This preview shows pages 1–9. Sign up to view the full content.

bEgInSlIdE Copyright 1995 - 2007 C. Gotsman & Y.M. Kimchi, Computer Science Dept. Technion 1 Chapter 3 Nested ADTs

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
bEgInSlIdE Copyright 1995 - 2007 C. Gotsman & Y.M. Kimchi, Computer Science Dept. Technion 3 Example: GRAPH GRAPH = SET of vertices + SET of edges edge = pair of vertices. A B C D E F G V = { A, B, C, D, E, F,G } E = { {A,B}, {A,G}, {C,G}, {A,C}, {E,D}, {D,F} } neighbors(G) = {A,C} connected-component(G) = {G,C,A,B}

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
bEgInSlIdE Copyright 1995 - 2007 C. Gotsman & Y.M. Kimchi, Computer Science Dept. Technion 4 Other Possible GRAPH Implementations SET of “extended” vertices. An “extended” vertex contains a list of neighboring vertices. SET of vertices + adjacency matrix. How is this similar to the bit array implementation of SET ? A B A C C D D E E F F 1 1 1 1 1 1 1 1 1 1 G G 1 1 B
bEgInSlIdE Copyright 1995 - 2007 C. Gotsman & Y.M. Kimchi, Computer Science Dept. Technion 5 GRAPH interface Create graph. Destroy graph. Add vertex to graph. Add edge to graph. Remove vertex from graph. Remove edge from graph. Find neighbors of a vertex in a graph. Find connected component of a vertex in a graph. Are two vertices in a graph connected ? Print graph. Other possible interface functions: Copy graph. Vertex iterator . Edge iterator .

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
bEgInSlIdE Copyright 1995 - 2007 C. Gotsman & Y.M. Kimchi, Computer Science Dept. Technion 6 #ifndef GRAPH_HDR_ /* ‘{‘ */ #define GRAPH_HDR_ #include "set.h" #define VERTEX_LABEL_SIZE 30 typedef struct graph_rec* Graph; typedef char * Label; Graph GraphCreate ( void ); void GraphDestroy (Graph); Result GraphAddVertex (Graph,Label); Result GraphAddEdge (Graph,Label,Label); Result GraphRemoveVertex (Graph,Label); Result GraphRemoveEdge (Graph,Label,Label); Set GraphNeighbors (Graph,Label); Set GraphConnectedComponent (Graph,Label); bool GraphTwoConnected (Graph,Label,Label); void GraphPrint (Graph); #endif /* GRAPH_HDR_ ‘}’ */ graph.h - ADT interface Note that the contents of the graph_rec structure are still unknown.
bEgInSlIdE Copyright 1995 - 2007 C. Gotsman & Y.M. Kimchi, Computer Science Dept. Technion 7 A graph as a model for a road network Cities are vertices. Roads are edges. Tiberias Zfat Akko Haifa Netanya Tel_Aviv Jerusalem Beer_Sheva Eilat

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document