Lecture 20. Graphs and network models 1. Recap Binary search tree is a special binary tree which is designed to make the search of elements or keys in.

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

CS 253: Algorithms Chapter 22 Graphs Credit: Dr. George Bebis.
Analysis of Algorithms CS 477/677
Cpt S 223 – Advanced Data Structures Graph Algorithms: Introduction
Review Binary Search Trees Operations on Binary Search Tree
Chen, Lu Mentor: Zhou, Jian Shanghai University, School of Management Chen213.shu.edu.cn.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
PSU CS Algorithms Analysis and Design Graphs.
Introduction to Algorithms Second Edition by Cormen, Leiserson, Rivest & Stein Chapter 22.
ALGORITHMS THIRD YEAR BANHA UNIVERSITY FACULTY OF COMPUTERS AND INFORMATIC Lecture eight Dr. Hamdy M. Mousa.
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
 Graph Graph  Types of Graphs Types of Graphs  Data Structures to Store Graphs Data Structures to Store Graphs  Graph Definitions Graph Definitions.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
Graph & BFS.
Graphs Intro G.Kamberova, Algorithms Graphs Introduction Gerda Kamberova Department of Computer Science Hofstra University.
Chapter 9 Graph algorithms. Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
Network Optimization Problems: Models and Algorithms This handout: Minimum Spanning Tree Problem.
Graphs.
Graph COMP171 Fall Graph / Slide 2 Graphs * Extremely useful tool in modeling problems * Consist of: n Vertices n Edges D E A C F B Vertex Edge.
Introduction to Graphs
Graphs and Trees This handout: Trees Minimum Spanning Tree Problem.
Graph & BFS Lecture 22 COMP171 Fall Graph & BFS / Slide 2 Graphs * Extremely useful tool in modeling problems * Consist of: n Vertices n Edges D.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Spring 2010CS 2251 Graphs Chapter 10. Spring 2010CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs.
Chapter 9 Graph algorithms Lec 21 Dec 1, Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
Graphs G = (V,E) V is the vertex set. Vertices are also called nodes and points. E is the edge set. Each edge connects two different vertices. Edges are.
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
© 2008 Prentice-Hall, Inc. Chapter 12 To accompany Quantitative Analysis for Management, Tenth Edition, by Render, Stair, and Hanna Power Point slides.
Review of Graphs A graph is composed of edges E and vertices V that link the nodes together. A graph G is often denoted G=(V,E) where V is the set of vertices.
To accompany Quantitative Analysis for Management, 9e by Render/Stair/Hanna 12-1 © 2006 by Prentice Hall, Inc. Upper Saddle River, NJ Chapter 12.
C o n f i d e n t i a l HOME NEXT Subject Name: Data Structure Using C Unit Title: Graphs.
ALG0183 Algorithms & Data Structures Lecture 18 The basics of graphs. 8/25/20091 ALG0183 Algorithms & Data Structures by Dr Andy Brooks.
GRAPH Learning Outcomes Students should be able to:
Graph. Data Structures Linear data structures: –Array, linked list, stack, queue Non linear data structures: –Tree, binary tree, graph and digraph.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
1 Chapter 9 Graph Algorithms Real-life graph problems Algorithms for some graph problems Choice of data structures for graph problems.
Lecture 13 Graphs. Introduction to Graphs Examples of Graphs – Airline Route Map What is the fastest way to get from Pittsburgh to St Louis? What is the.
GRAPHS CSE, POSTECH. Chapter 16 covers the following topics Graph terminology: vertex, edge, adjacent, incident, degree, cycle, path, connected component,
Graphs. What is a graph? A data structure that consists of a set of nodes (vertices) and a set of edges that relate the nodes to each other The set of.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Data Structures & Algorithms Graphs
COSC 2007 Data Structures II Chapter 14 Graphs I.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 20.
Graphs A graphs is an abstract representation of a set of objects, called vertices or nodes, where some pairs of the objects are connected by links, called.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 13: Graphs Data Abstraction & Problem Solving with C++
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Data Structures & Algorithms Graphs Richard Newman based on book by R. Sedgewick and slides by S. Sahni.
Graphs 황승원 Fall 2010 CSE, POSTECH. 2 2 Graphs G = (V,E) V is the vertex set. Vertices are also called nodes and points. E is the edge set. Each edge connects.
GRAPHS. Graph Graph terminology: vertex, edge, adjacent, incident, degree, cycle, path, connected component, spanning tree Types of graphs: undirected,
Discrete Structures CISC 2315 FALL 2010 Graphs & Trees.
Graphs Upon completion you will be able to:
Chapter 9: Graphs.
Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
Graphs Definition: a graph is an abstract representation of a set of objects where some pairs of the objects are connected by links. The interconnected.
Chapter 05 Introduction to Graph And Search Algorithms.
Graph Theory Graph Theory - History Leonhard Euler's paper on “Seven Bridges of Königsberg”, published in 1736.
Data Structures and Algorithm Analysis Graph Algorithms Lecturer: Jing Liu Homepage:
1 GRAPHS – Definitions A graph G = (V, E) consists of –a set of vertices, V, and –a set of edges, E, where each edge is a pair (v,w) s.t. v,w  V Vertices.
1 Data Structures and Algorithms Graphs. 2 Graphs Basic Definitions Paths and Cycles Connectivity Other Properties Representation Examples of Graph Algorithms:
CS 3343: Analysis of Algorithms
Network Models Chapter 12
Graph Algorithm.
Graph Representation Adjacency list representation of G = (V, E)
Graphs All tree structures are hierarchical. This means that each node can only have one parent node. Trees can be used to store data which has a definite.
Graph Operations And Representation
Network Models 7-1.
Prepared by Lee Revere and John Large
More Graphs Lecture 19 CS2110 – Fall 2009.
Presentation transcript:

Lecture 20. Graphs and network models 1

Recap Binary search tree is a special binary tree which is designed to make the search of elements or keys in linear times. For each current parent node key, the values of all nodes of left sub tree are less and of right sub tree are greater than from current parent. You can use different operations in constant times such as search, max, min, successor, insert and delete. 2

Graphs Definition = a set of nodes (vertices) with edges (links) between them. G = (V, E) - graph V = set of vertices  V  = n E = set of edges  E  = m – Binary relation on V – Subset of V x V ={(u,v): u  V, v  V}

Applications Applications that involve not only a set of items, but also the connections between them Computer networks Circuits Schedules Hypertext Maps 4

Terminology Directed vs Undirected graphs 5

Terminology (Cont !!!) Complete graph – A graph with an edge between each pair of vertices Subgraph – A graph (V ’, E ’ ) such that V ’  V and E ’  E Path from v to w – A sequence of vertices such that v 0 =v and v k =w Length of a path – Number of edges in the path path from v 1 to v 4 6

Terminology (Cont !!!) w is reachable from v – If there is a path from v to w Simple path – All the vertices in the path are distinct Cycles – A path forms a cycle if v 0 =v k and k≥2 Acyclic graph – A graph without any cycles cycle from v 1 to v 1 7

Terminology (Cont !!!) Connected and Strongly Connected 8

Terminology (Cont !!!) A tree is a connected, acyclic undirected graph 9

Graph Representation Adjacency list representation of G = (V, E) – An array of  V  lists, one for each vertex in V – Each list Adj[u] contains all the vertices v that are adjacent to u (i.e., there is an edge from u to v) – Can be used for both directed and undirected graphs / / / Undirected graph 10

Properties of Adjacency-List Representation Sum of “lengths” of all adjacency lists – Directed graph: edge (u, v) appears only once (i.e., in the list of u) – Undirected graph: edge (u, v) appears twice (i.e., in the lists of both u and v) Undirected graph Directed graph  E  2  E  11

Properties of Adjacency-List Representation Memory required –  (V + E) Preferred when – The graph is sparse:  E  <<  V  2 – We need to quickly determine the nodes adjacent to a given node. Disadvantage – No quick way to determine whether there is an edge between node u and v Time to determine if (u, v)  E: – O(degree(u)) Time to list all vertices adjacent to u: –  (degree(u)) Undirected graph Directed graph 12

Graph Representation Adjacency matrix representation of G = (V, E) – Assume vertices are numbered 1, 2, …  V  – The representation consists of a matrix A  V  x  V  : – a ij = 1 if (i, j)  E 0 otherwise Undirected graph For undirected graphs, matrix A is symmetric: a ij = a ji A = A T 13

Properties of Adjacency Matrix Representation Memory required –  (V 2 ), independent on the number of edges in G Preferred when – The graph is dense:  E  is close to  V  2 – We need to quickly determine if there is an edge between two vertices Time to determine if (u, v)  E: –  (1) Disadvantage – No quick way to determine the vertices adjacent to another vertex Time to list all vertices adjacent to u: –  (V) Undirected graph Directed graph 14

Weighted Graphs Graphs for which each edge has an associated weight w(u, v) w: E  R, weight function Storing the weights of a graph – Adjacency list: Store w(u,v) along with vertex v in u’s adjacency list – Adjacency matrix: Store w(u, v) at location (u, v) in the matrix 15

Weighted Graphs 16

Problem 1 Given an adjacency-list representation, how long does it take to compute the out-degree of every vertex? – For each vertex u, search Adj[u]  Θ(E) 2 5/ / /

Problem 2 How long does it take to compute the in-degree of every vertex? – For each vertex u, search entire list of edges  Θ(VE) 2 5/ / /

Network Models Network models are used to solve a variety of problems: 1. the minimal-spanning tree technique, 2. the maximal-flow technique, and 3. the shortest-route technique. 19

Minimal-Spanning Tree Technique Definition: The minimal-spanning tree technique determines the path through the network that connects all the points while minimizing total distance. For example: If the points represent houses in a subdivision, the minimal spanning tree technique can be used to determine the best way to connect all of the houses to electrical power, water systems, etc. in a way that minimizes the total distance or length of power lines or water pipes. 20

Minimal-Spanning Tree Steps 1. Selecting any node in the network. 2. Connecting this node to the nearest node minimizing the total distance. 3. Finding and connecting the nearest unconnected node.  If there is a tie for the nearest node, one can be selected arbitrarily.  A tie suggests that there may be more than one optimal solution. 4. Repeating the third step until all nodes are connected. 21

Minimal-Spanning Tree Technique Solving the network for Melvin Lauderdale construction Start by arbitrarily selecting node 1. Since the nearest node is the third node at a distance of 2 (200 feet), connect node 1 to node 3. Considering nodes 1 and 3, look for the next- nearest node. – This is node 4, which is the closest to node 3 with a distance of 2 (200 feet). Once again, connect these nodes 22

Network for Lauderdale Construction 23

First Iteration 24

Second Iteration 25

Third Iteration 26

Summarize: Minimal-Spanning Tree Technique Step 1:Select node 1 Step 2:Connect node 1 to node 3 Step 3:Connect the next nearest node Step 4:Repeat the process The total number of iterations to solve this example is 7. This final solution is on next slide 27

Third Iteration 28

Final Solution to the Minimal-Spanning Tree Example Nodes 1, 2, 4, and 6 are all connected to node 3. Node 2 is connected to node 5. Node 6 is connected to node 8, and node 8 is connected to node 7. All of the nodes are now connected. The total distance is found by adding the distances for the arcs used in the spanning tree. In this example, the distance is: = 16 (or 1,600 feet). 29

Summary Graphs and network models are used to solved certain real life problems. Graph is a cyclic and non linear data structure. Vertices V and Edges E are main components of graph Main types of graphs are directed, un directed and weighted graphs. Minimum spanning tree is an application of network model to solve the problems where you have to find shortest path over a network. 30

In Next Lecturer In next lecture, we will discuss other network and graph models. 31