CHAPTER 13 GRAPH ALGORITHMS ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA.

Slides:



Advertisements
Similar presentations
© 2004 Goodrich, Tamassia Depth-First Search1 DB A C E.
Advertisements

© 2010 Goodrich, Tamassia Graphs1 Graph Data Structures ORD DFW SFO LAX
CS16: Introduction to Data Structures & Algorithms
Depth-First Search1 Part-H2 Depth-First Search DB A C E.
© 2004 Goodrich, Tamassia Breadth-First Search1 CB A E D L0L0 L1L1 F L2L2.
Depth-First Search1 DB A C E. 2 Outline and Reading Definitions (§6.1) Subgraph Connectivity Spanning trees and forests Depth-first search (§6.3.1) Algorithm.
CSC 213 – Large Scale Programming Lecture 27: Graph ADT.
CSC 213 ORD DFW SFO LAX Lecture 20: Graphs.
© 2004 Goodrich, Tamassia Graphs1 ORD DFW SFO LAX
Breadth-First Search1 Part-H3 Breadth-First Search CB A E D L0L0 L1L1 F L2L2.
1 Graphs ORD DFW SFO LAX Many slides taken from Goodrich, Tamassia 2004.
© 2004 Goodrich, Tamassia Depth-First Search1 DB A C E.
TTIT33 Alorithms and Optimization – DALG Lecture 4 Graphs HT TTIT33 Algorithms and optimization Algorithms Lecture 4 Graphs.
1 Graphs: Concepts, Representation, and Traversal CSC401 – Analysis of Algorithms Lecture Notes 13 Graphs: Concepts, Representation, and Traversal Objectives:
Graphs1 Part-H1 Graphs ORD DFW SFO LAX
Graphs1 ORD DFW SFO LAX Graphs2 Outline and Reading Graphs (§6.1) Definition Applications Terminology Properties ADT Data structures.
Graphs1 ORD DFW SFO LAX Graphs2 Outline and Reading Graphs (§6.1) Definition Applications Terminology Properties ADT Data structures.
CSC311: Data Structures 1 Chapter 13: Graphs I Objectives: Graph ADT: Operations Graph Implementation: Data structures Graph Traversals: DFS and BFS Directed.
ECE669 L10: Graph Applications March 2, 2004 ECE 669 Parallel Computer Architecture Lecture 10 Graph Applications.
TDDB56 DALGOPT-D TDDB57 DALG-C – Lecture 11 – Graphs Graphs HT TDDB56 – DALGOPT-D Algorithms and optimization Lecture 11 Graphs.
1 Graph Algorithms Lecture 09 Asst. Prof. Dr. Bunyarit Uyyanonvara IT Program, Image and Vision Computing Lab. School of Information and Computer Technology.
CSC 213 – Large Scale Programming. Today’s Goals  Make Britney sad through my color choices  Revisit issue of graph terminology and usage  Subgraphs,
Lecture17: Graph I Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
Graphs – ADTs and Implementations ORD DFW SFO LAX
Graphs Chapter 12.
Graphs Part 1. Outline and Reading Graphs (§13.1) – Definition – Applications – Terminology – Properties – ADT Data structures for graphs (§13.2) – Edge.
Graphs. Data Structure for Graphs. Graph Traversals. Directed Graphs. Shortest Paths. 2 CPSC 3200 University of Tennessee at Chattanooga – Summer 2013.
Chapter 6 Graphs ORD DFW SFO LAX
Elementary Graph Algorithms CLRS Chapter 22. Graph A graph is a structure that consists of a set of vertices and a set of edges between pairs of vertices.
Graphs CSE 2011 Winter June Graphs A graph is a pair (V, E), where  V is a set of nodes, called vertices  E is a collection of pairs.
Spring 2007Graphs1 ORD DFW SFO LAX
GRAPHS 1. Outline 2  Undirected Graphs and Directed Graphs  Depth-First Search  Breadth-First Search.
1 prepared from lecture material © 2004 Goodrich & Tamassia COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material.
October 21, Graphs1 Graphs CS 221 (slides from textbook author)
Depth-First Search1 DB A C E. 2 Depth-first search (DFS) is a general technique for traversing a graph A DFS traversal of a graph G – Visits all the vertices.
1 Subgraphs A subgraph S of a graph G is a graph such that The vertices of S are a subset of the vertices of G The edges of S are a subset of the edges.
CSE 373: Data Structures and Algorithms
Graphs. Graphs Similar to the graphs you’ve known since the 5 th grade: line graphs, bar graphs, etc., but more general. Those mathematical graphs are.
Depth-First Search Lecture 21: Graph Traversals
CSC401: Analysis of Algorithms 6-1 CSC401 – Analysis of Algorithms Chapter 6 Graphs Objectives: Introduce graphs and data structures Discuss the graph.
Graphs Quebec Toronto Montreal Ottawa 449 km 255 km 200 km 545 km Winnipeg 2075 km 2048 km New York 596 km 790 km 709 km.
Graphs and Paths : Chapter 15 Saurav Karmakar
CHAPTER 13 GRAPH ALGORITHMS ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA.
CSC 213 – Large Scale Programming Lecture 31: Graph Traversals.
1 COMP9024: Data Structures and Algorithms Week Eleven: Graphs (I) Hui Wu Session 1, 2016
Graphs ORD SFO LAX DFW Graphs 1 Graphs Graphs
Graphs 10/24/2017 6:47 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and.
Graphs.
Graphs 5/14/ :46 PM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and.
Graphs 7/18/2018 7:39 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and.
Searching Graphs ORD SFO LAX DFW Spring 2007
Graphs ORD SFO LAX DFW Graphs Graphs
COMP9024: Data Structures and Algorithms
Graphs ORD SFO LAX DFW Graphs Graphs
COMP9024: Data Structures and Algorithms
Chapter 14 Graph Algorithms
Graphs Part 1.
CMSC 341 Lecture 21 Graphs (Introduction)
Graphs ORD SFO LAX DFW Graphs Graphs
Graphs.
Graphs.
Graphs ORD SFO LAX DFW Graphs Graphs
Graphs CSE 2011 Winter November 2018.
What is a Graph? a b c d e V= {a,b,c,d,e} E= {(a,b),(a,c),(a,d),
Graphs ORD SFO LAX DFW Graphs Graphs
Graphs ORD SFO LAX DFW Graphs Graphs
Graphs 4/29/15 01:28:20 PM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Searching Graphs ORD SFO LAX DFW Spring 2007
Graphs Part 1 ORD SFO LAX DFW
Graphs ORD SFO LAX DFW /15/ :57 AM
Presentation transcript:

CHAPTER 13 GRAPH ALGORITHMS ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA AND MOUNT (WILEY 2004) AND SLIDES FROM NANCY M. AMATO ORD DFW SFO LAX

GRAPH ORD PVD MIA DFW SFO LAX LGA HNL

EDGE & GRAPH TYPES ORDDFW flight AA 1206 ORDDFW flight route 802 miles

APPLICATIONS Electronic circuits Printed circuit board Integrated circuit Transportation networks Highway network Flight network Computer networks Local area network Internet Web Databases Entity-relationship diagram

TERMINOLOGY XU V W Z Y a c b e d f g h i j

X V W Z Y b e d f g h i j

P1P1 XU V W Z Y a c b e d f g hP2P2

C1C1 XU V W Z Y a c b e d f g hC2C2

EXERCISE ON TERMINOLOGY 1. Number of vertices? 2. Number of edges? 3. What type of the graph is it? 4. Show the end vertices of the edge with largest weight 5. Show the vertices of smallest degree and largest degree 6. Show the edges incident to the vertices in the above question 7. Identify the shortest simple path from HNL to PVD 8. Identify the simple cycle with the most edges ORD PVD MIA DFW SFO LAX LGA HNL

EXERCISE PROPERTIES OF UNDIRECTED GRAPHS A graph with given number of vertices (4) and maximum number of edges

EXERCISE PROPERTIES OF UNDIRECTED GRAPHS A graph with given number of vertices (4) and maximum number of edges

EXERCISE PROPERTIES OF DIRECTED GRAPHS A graph with given number of vertices (4) and maximum number of edges

EXERCISE PROPERTIES OF DIRECTED GRAPHS A graph with given number of vertices (4) and maximum number of edges

SUBGRAPHS Subgraph Spanning subgraph

CONNECTIVITY Connected graph Non connected graph with two connected components

TREES AND FORESTS Tree Forest

SPANNING TREES AND FORESTS A spanning tree of a connected graph is a spanning subgraph that is a tree A spanning tree is not unique unless the graph is a tree Spanning trees have applications to the design of communication networks A spanning forest of a graph is a spanning subgraph that is a forest Graph Spanning tree

GRAPH ADT

EXERCISE ON ADT ORD PVD MIA DFW SFO LAX LGA HNL

EDGE LIST STRUCTURE An edge list can be stored in a sequence, a vector, a list or a dictionary such as a hash table ORD PVD MIA DFW LGA (ORD, PVD) (ORD, DFW) (LGA, PVD) (LGA, MIA) (DFW, LGA) (DFW, MIA) 1120 Edge List ORD LGA PVD DFW MIA Vertex Sequence

EXERCISE EDGE LIST STRUCTURE Construct the edge list for the following graph u x y v z a

ASYMPTOTIC PERFORMANCE EDGE LIST STRUCTURE Edge List Space ? ? ? ? ? (ORD, PVD) (ORD, DFW) (LGA, PVD) (LGA, MIA) (DFW, LGA) (DFW, MIA) 1120 Edge List ORD LGA PVD DFW MIA Vertex Sequence False WeightDirectedDegree

ASYMPTOTIC PERFORMANCE EDGE LIST STRUCTURE Edge List Space (ORD, PVD) (ORD, DFW) (LGA, PVD) (LGA, MIA) (DFW, LGA) (DFW, MIA) 1120 Edge List ORD LGA PVD DFW MIA Vertex Sequence False WeightDirectedDegree

EDGE LIST STRUCTURE Vertex object element reference to position in vertex sequence Edge object element origin vertex object destination vertex object reference to position in edge sequence Vertex sequence sequence of vertex objects Edge sequence sequence of edge objects v u w ac b a z d uv w z bcd

ADJACENCY LIST STRUCTURE Adjacency Lists associate edges with their end vertices Each vertex stores a list of incident edges ORD PVD MIA DFW LGA ORD LGA PVD DFW MIA (ORD, PVD) Adjacency List (ORD, DFW) (LGA, PVD) (LGA, MIA) (PVD, ORD) (PVD, LGA) (LGA, DFW) (DFW, ORD) (DFW, LGA)(DFW, MIA) (MIA, LGA) (MIA, DFW)

EXERCISE ADJACENCY LIST STRUCTURE Construct the adjacency list for the following graph u x y v z a

ASYMPTOTIC PERFORMANCE ADJACENCY LIST STRUCTURE Adjacency List Space ? ? ? ? ? ORD LGA PVD DFW MIA (ORD, PVD) Adjacency List (ORD, DFW) (LGA, PVD) (LGA, MIA) (PVD, ORD) (PVD, LGA) (LGA, DFW) (DFW, ORD) (DFW, LGA)(DFW, MIA) (MIA, LGA) (MIA, DFW)

ASYMPTOTIC PERFORMANCE ADJACENCY LIST STRUCTURE Adjacency List Space ORD LGA PVD DFW MIA (ORD, PVD) Adjacency List (ORD, DFW) (LGA, PVD) (LGA, MIA) (PVD, ORD) (PVD, LGA) (LGA, DFW) (DFW, ORD) (DFW, LGA)(DFW, MIA) (MIA, LGA) (MIA, DFW)

ADJACENCY LIST STRUCTURE Store vertex sequence and edge sequence Each vertex stores a sequence of incident edges Sequence of references to edge objects of incident edges Augmented edge objects References to associated positions in incidence sequences of end vertices u v w ab a uv w b

ADJACENCY MATRIX STRUCTURE Adjacency matrices store edges in a table, indexed by the vertex

EXERCISE ADJACENCY MATRIX STRUCTURE Construct the adjacency matrix for the following graph u x y v z a

ADJACENCY MATRIX STRUCTURE IN A WEIGHTED GRAPH 0 ORD 1 LGA 2 PVD 3 DFW 4 MIA 0 ORD LGA PVD DFW MIA Store edge object/property in table, or include a pointer to it inside of the table 0:ORD 2:PVD 4:MIA 3:DFW 1:LGA

EXERCISE ADJACENCY MATRIX STRUCTURE: WEIGHTED DIGRAPH 0 ORD 1 LGA 2 PVD 3 DFW 4 MIA 0 ORD 1 LGA 2 PVD 3 DFW 4 MIA 0:ORD 2:PVD 4:MIA 3:DFW 1:LGA

EXERCISE ADJACENCY MATRIX STRUCTURE: WEIGHTED DIGRAPH 0 ORD 1 LGA 2 PVD 3 DFW 4 MIA 0 ORD LGA PVD DFW MIA :ORD 2:PVD 4:MIA 3:DFW 1:LGA

ASYMPTOTIC PERFORMANCE OF ADJACENCY MATRIX STRUCTURE Adjacency Matrix Space ? ? ? ? ?

ASYMPTOTIC PERFORMANCE OF ADJACENCY MATRIX STRUCTURE Adjacency Matrix Space

ADJACENCY MATRIX STRUCTURE Augmented vertex objects Integer key (index) associated with vertex 2D-array adjacency array Reference to edge object for adjacent vertices Null for non nonadjacent vertices The “old fashioned” version just has 0 for no edge and 1 for edge u v w ab  1  2  a uv w 01 2 b

ASYMPTOTIC PERFORMANCE Edge List Adjacency List Adjacency Matrix Space

DEPTH-FIRST SEARCH DB A C E

EXAMPLE DB A C E D B A C E D B A C E discovery edge back edge A visited vertex A unexplored vertex unexplored edge F F F G G G

EXAMPLE DB A C E DB A C E DB A C E D B A C E F F F F G G G G

DB A C E F G DB A C E F G DB A C E F G

DFS AND MAZE TRAVERSAL The DFS algorithm is similar to a classic strategy for exploring a maze We mark each intersection, corner and dead end (vertex) visited We mark each corridor (edge) traversed We keep track of the path back to the entrance (start vertex) by means of a rope (recursion stack)

DFS ALGORITHM

EXERCISE DFS ALGORITHM Perform DFS of the following graph, start from vertex A Assume adjacent edges are processed in alphabetical order Number vertices in the order they are visited Label edges as discovery or back edges CB A E D F

PROPERTIES OF DFS DB A C E F G v1v1 v2v2

ANALYSIS OF DFS DB A C E F G

APPLICATION PATH FINDING

APPLICATION CYCLE FINDING

BREADTH-FIRST SEARCH CB A E D L0L0 L1L1 F L2L2

EXAMPLE C B A E D discovery edge cross edge A visited vertex A unexplored vertex unexplored edge L0L0 L1L1 F CB A E D L0L0 L1L1 F CB A E D L0L0 L1L1 F

EXAMPLE CB A E D L0L0 L1L1 F CB A E D L0L0 L1L1 F L2L2 CB A E D L0L0 L1L1 F L2L2 CB A E D L0L0 L1L1 F L2L2 discovery edge cross edge visited vertex A A unexplored vertex unexplored edge

EXAMPLE CB A E D L0L0 L1L1 F L2L2 CB A E D L0L0 L1L1 F L2L2 CB A E D L0L0 L1L1 F L2L2 discovery edge cross edge visited vertex A A unexplored vertex unexplored edge

BFS ALGORITHM

EXERCISE BFS ALGORITHM Perform BFS of the following graph, start from vertex A Assume adjacent edges are processed in alphabetical order Number vertices in the order they are visited and note the level they are in Label edges as discovery or cross edges CB A E D F

PROPERTIES CB A E D L0L0 L1L1 F L2L2 CB A E D F

ANALYSIS

ANALYSIS OF BFS

APPLICATIONS

DFS VS. BFS CB A E D L0L0 L1L1 F L2L2 CB A E D F DFSBFS ApplicationsDFSBFS Spanning forest, connected components, paths, cycles  Shortest paths  Biconnected components 

DFS VS. BFS CB A E D L0L0 L1L1 F L2L2 CB A E D F DFSBFS