600 likes | 860 Views
Graphs. Ed. 2. and 3.: Chapter 12 Ed. 4.: Chapter 13. Graphs Graph ADT - What is a graph? - Graph methods Data structure for graphs - Edge list structure, adjacency list structure, adjacency matrix Graph Traversal - Depth-first search - Breadth-first search Directed graphs.
E N D
Graphs • Ed. 2. and 3.: Chapter 12 • Ed. 4.: Chapter 13
Graphs • Graph ADT • - What is a graph? • - Graph methods • Data structure for graphs • - Edge list structure, adjacency list • structure, adjacency matrix • Graph Traversal • - Depth-first search • - Breadth-first search • Directed graphs
(u, v) u v (Toronto) (Winnipeg) (v, u)
u v (New York) (Winnipeg) (v, u)
element c1 c2 rank c3
Edge Objects The edge object for an edge e storing element o has data fields for A reference to o · A Boolean indicator of whether e is directed or not · · References to the vertex objects in V associated with the endpoint vertices of e (if the edge e is undir ected) or to the origin and destination vertices of e (if the edge e is directed) · A reference to the position of the edge - object in container E Note: The last data field is the rank of the edge object in the container E if E is a vector.
element With an edge list, some methods (edge - based) are fast while others need some efforts. For example, methods endVertices(), origin(), and destination() are fast because we can access edges directly. end vertex 1 or 0 end vertex