m03_ADT - bEgInSlIdE 1 Chapter 3 Nested ADTs Copyright 1995...

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

View Full Document Right Arrow Icon
bEgInSlIdE Copyright 1995 - 2007 C. Gotsman & Y.M. Kimchi, Computer Science Dept. Technion 1 Chapter 3 Nested ADTs
Background image of page 1

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

View Full DocumentRight Arrow Icon
bEgInSlIdE Copyright 1995 - 2007 C. Gotsman & Y.M. Kimchi, Computer Science Dept. Technion 2 Nested ADT’s A high-level ADT may be built on top of (many) lower-level ADT’s. ADT 2 ADT 1 ADT 3
Background image of page 2
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}
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 4
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 .
Background image of page 5

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

View Full DocumentRight Arrow Icon
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.
Background image of page 6
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
Background image of page 7

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

View Full DocumentRight Arrow Icon
bEgInSlIdE Copyright 1995 - 2007 C. Gotsman & Y.M. Kimchi, Computer Science Dept. Technion 8 #include <stdio.h> #include "graph.h" Graph BuildVertices(Graph road) { GraphAddVertex(road, "Jerusalem"); GraphAddVertex(road, "Tel_Aviv"); GraphAddVertex(road, "Haifa"); GraphAddVertex(road, "Tiberias"); GraphAddVertex(road, "Akko"); GraphAddVertex(road, "Zfat"); GraphAddVertex(road, "Netanya"); GraphAddVertex(road, "Beer_Sheva"); GraphAddVertex(road, "Eilat"); return road; } graph_app.c We do not test returned values :-(
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/14/2011 for the course CS 234122 taught by Professor Gillbarequet during the Spring '11 term at Technion.

Page1 / 26

m03_ADT - bEgInSlIdE 1 Chapter 3 Nested ADTs Copyright 1995...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online