Presentation is loading. Please wait.

Presentation is loading. Please wait.

B.Ramamurthy1 Graphs Chapter 12 B.Ramamurthy. 2 Introduction A structure that represents connectivity information. A tree is kind of graph. Applications.

Similar presentations


Presentation on theme: "B.Ramamurthy1 Graphs Chapter 12 B.Ramamurthy. 2 Introduction A structure that represents connectivity information. A tree is kind of graph. Applications."— Presentation transcript:

1 B.Ramamurthy1 Graphs Chapter 12 B.Ramamurthy

2 2 Introduction A structure that represents connectivity information. A tree is kind of graph. Applications include maps in geographic information system, transportation, electrical circuits, and computer network and our project3’s Scotland Yard map.

3 B.Ramamurthy3 Graph ADT A graph G is a pair {V, E} where V is a set of vertices, and E is a collection of pairs of vertices from V, called the edges. Vertices == nodes, edges == arcs Edges can be directed or undirected. Directed graph: all edges are directed (digraph) Undirected graph: all edges are undirected Mixed graph: There are also mixed graphs: City map with one-way routes is an example for mixed graph.

4 B.Ramamurthy4 Edges Directed:Flight from BUF to NYC (assume one way) BUF JFK Undirected: Graph of coauthor relationship: Symmetric Goodrich Vitter Garg Tamassia

5 B.Ramamurthy5 Graph XU V W Z Y a c b e d f g h i j Vertices = {U, V, X, W, Y, Z} Edges = {a,b,c,d,e,f,g,h,i,j} Undirected graph j is a self-loop

6 B.Ramamurthy6 Path Path is a sequence of alternating vertices and edges that starts at a vertex and ends at a vertex. Example: {W,c,U,a,V} A simple path is a path where all its vertices and edges are distinct Cycle is a path where the start and end vertices are the same.

7 B.Ramamurthy7 Graph Properties Adjacency: Two vertices are said to be adjacent if they are end points of the same edge. Incoming edge: of a vertex is an edge whose destination is that vertex. Outgoing edge: of a vertex is an edge whose origin is that vertex. The in-degree and out-degree of a vertex v are the number of incoming and outgoing edges respectively. Degree of a vertex is in-degree + out-degree

8 B.Ramamurthy8 Directed Flight Network: Example ORD LAX MIA BOS SFO DFW JFK TW45 NW35 DL47 AA903 AA523 AA411 AA49 AA1387 UA877 DL335 UA120

9 B.Ramamurthy9 Graph ADT (Tomassia and Goodrich’s text) Vertices and edges are positions store elements Accessor methods aVertex() incidentEdges(v) endVertices(e) isDirected(e) origin(e) destination(e) opposite(v, e) areAdjacent(v, w) Update methods insertVertex(o) insertEdge(v, w, o) insertDirectedEdge(v, w, o) removeVertex(v) removeEdge(e) Generic methods numVertices() numEdges() vertices() edges()

10 B.Ramamurthy10 Implementation of Graph ADT Matrix (a two dimensional array): adjacency matrix Vertices are used for row and column index Entry in a cell indicates an edge between the vertex at row index and vertex at column index.

11 B.Ramamurthy11 Airline Graph Matrix (p.555)

12 12 Adjacency List When a matrix is sparsely filled it is called a sparse matrix. Sparse matrix can be simplified into lists, row-lists, column-list, or cell type lists Location (from) Location(to) Transportation(bus,taxi,train) Scotland Yard Board


Download ppt "B.Ramamurthy1 Graphs Chapter 12 B.Ramamurthy. 2 Introduction A structure that represents connectivity information. A tree is kind of graph. Applications."

Similar presentations


Ads by Google