Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3 1 Graphs.

Slides:



Advertisements
Similar presentations
Review Binary Search Trees Operations on Binary Search Tree
Advertisements

IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
Introduction to Algorithms Second Edition by Cormen, Leiserson, Rivest & Stein Chapter 22.
Graphs and Digraphs Chapter 14.
CS 206 Introduction to Computer Science II 03 / 27 / 2009 Instructor: Michael Eckmann.
Graphs Chapter Chapter Contents Some Examples and Terminology Road Maps Airline Routes Mazes Course Prerequisites Trees Traversals Breadth-First.
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
Graphs Chapter 20 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 27 Graph Applications.
Graphs Chapter 30 Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X.
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 excerpts Graphs (breadth-first-search)
Graphs Graphs are the most general data structures we will study in this course. A graph is a more general version of connected nodes than the tree. Both.
Data Structure and Algorithms (BCS 1223) GRAPH. Introduction of Graph A graph G consists of two things: 1.A set V of elements called nodes(or points or.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
Graph & BFS.
Graphs Chapter 30 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Graphs CS-240/341. Uses for Graphs computer networks and routing airline flights geographic maps course prerequisite structures tasks for completing a.
Graphs.
Graph COMP171 Fall Graph / Slide 2 Graphs * Extremely useful tool in modeling problems * Consist of: n Vertices n Edges D E A C F B Vertex Edge.
Graphs. Graph definitions There are two kinds of graphs: directed graphs (sometimes called digraphs) and undirected graphs Birmingham Rugby London Cambridge.
Introduction to Graphs
Graph & BFS Lecture 22 COMP171 Fall Graph & BFS / Slide 2 Graphs * Extremely useful tool in modeling problems * Consist of: n Vertices n Edges D.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Spring 2010CS 2251 Graphs Chapter 10. Spring 2010CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs.
Graphs & Graph Algorithms 2 Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
CS 206 Introduction to Computer Science II 11 / 05 / 2008 Instructor: Michael Eckmann.
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
CS 206 Introduction to Computer Science II 03 / 30 / 2009 Instructor: Michael Eckmann.
Graphs Chapter 20 Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012.
Graphs & Graph Algorithms 2 Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Review of Graphs A graph is composed of edges E and vertices V that link the nodes together. A graph G is often denoted G=(V,E) where V is the set of vertices.
C o n f i d e n t i a l HOME NEXT Subject Name: Data Structure Using C Unit Title: Graphs.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Graph Dr. Bernard Chen Ph.D. University of Central Arkansas.
Chapter 2 Graph Algorithms.
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 Graphs.
Chapter 14 Graphs. © 2004 Pearson Addison-Wesley. All rights reserved Terminology G = {V, E} A graph G consists of two sets –A set V of vertices,
Representing and Using Graphs
Graphs. What is a graph? A data structure that consists of a set of nodes (vertices) and a set of edges that relate the nodes to each other The set of.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Graphs. 2 Graph definitions There are two kinds of graphs: directed graphs (sometimes called digraphs) and undirected graphs Birmingham Rugby London Cambridge.
Graphs. Definitions A graph is two sets. A graph is two sets. –A set of nodes or vertices V –A set of edges E Edges connect nodes. Edges connect nodes.
Data Structures CSCI 132, Spring 2014 Lecture 38 Graphs
Graph Introduction, Searching Graph Theory Basics - Anil Kishore.
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.
Graphs A graphs is an abstract representation of a set of objects, called vertices or nodes, where some pairs of the objects are connected by links, called.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 13: Graphs Data Abstraction & Problem Solving with C++
1 Directed Graphs Chapter 8. 2 Objectives You will be able to: Say what a directed graph is. Describe two ways to represent a directed graph: Adjacency.
COSC 2007 Data Structures II
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Graphs Slide credits:  K. Wayne, Princeton U.  C. E. Leiserson and E. Demaine, MIT  K. Birman, Cornell U.
© 2006 Pearson Addison-Wesley. All rights reserved 14 A-1 Chapter 14 Graphs.
Graphs Upon completion you will be able to:
Graphs and Paths : Chapter 15 Saurav Karmakar
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
Chapter 05 Introduction to Graph And Search Algorithms.
Data Structures and Algorithm Analysis Graph Algorithms Lecturer: Jing Liu Homepage:
Lecture #13. Topics 1.The Graph Abstract Data Type. 2.Graph Representations. 3.Elementary Graph Operations.
Csc 2720 Instructor: Zhuojun Duan
I206: Lecture 15: Graphs Marti Hearst Spring 2012.
Graphs Representation, BFS, DFS
Graphs Chapter 13.
Graphs Chapter 11 Objectives Upon completion you will be able to:
Graphs.
Chapter 11 Graphs.
Chapter 14 Graphs © 2006 Pearson Addison-Wesley. All rights reserved.
Chapter 14 Graphs © 2011 Pearson Addison-Wesley. All rights reserved.
INTRODUCTION A graph G=(V,E) consists of a finite non empty set of vertices V , and a finite set of edges E which connect pairs of vertices .
Presentation transcript:

Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs and Digraphs Chapter 16 7/7/15

Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Chapter Contents 16.1 Directed Graphs 16.2 Searching and Traversing Digraphs 16.3 Graphs

Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Chapter Objectives Introduce directed graphs (digraphs) and look at some of the common implementations of them Study some of the algorithms for searching and traversing digraphs See how searching is basic to traversals and shortest path problems in digraphs Introduce undirected graphs and some of their implementations

Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs Similar to a tree –Without a specific ordering Consists of a finite set of elements –Vertices or nodes Together with finite set of directed –Arcs or edges –Connect pairs of vertices

Graphs Undirected –Edges are bidirectional Directed –Edges unidirectional Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved

Graphs Formal definition –A graph G is and ordered triplet (V, E, g) where V – non-empty set of vertices (nodes) E – set of edges g – a function associating with each edge e and unordered pair x – y of vertices, called endpoints Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved

7 Directed Graphs Also known as Digraphs Applications of directed graphs –Analyze electrical circuits –Find shortest routes (Maps) –Develop project schedules

Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Directed Graphs Trees are special kinds of directed graphs –One of their nodes (the root) has no incoming arc –Every other node can be reached from the node by a unique path Graphs differ from trees as ADTs –Insertion of a node does not require a link (arc) to other nodes … or may have multiple arcs

Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Directed Graphs A directed graph is defined as a collection of data elements: –Called nodes or vertices –And a finite set of direct arcs or edges –The edges connect pairs of nodes Operations include –Constructors –Inserts of nodes, of edges –Deletions of nodes, edges –Search for a value in a node, starting from a given node

Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graph Representation Adjacency matrix representation –for directed graph with vertices numbered 1, 2, … n Defined as n by n matrix named adj The [i,j] entry set to 1 (true) if vertex j is adjacent to vertex i (there is a directed arc from i to j ) 0 (false) otherwise

Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graph Representation rows i columns j Entry [ 1, 5 ] set to true Edge from vertex 1 to vertex 5 Entry [ 1, 5 ] set to true Edge from vertex 1 to vertex 5

Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graph Representation Weighted digraph –There exists a "cost" or "weight" associated with each arc –Then that cost is entered in the adjacency matrix A complete graph –has an edge between each pair of vertices –N nodes will mean N * (N – 1) edges

What is an Adjacency Matrix? Also referred to as a connection matrix or vertex matrix Matrix whose rows and columns represent the graph vertices –Values 1 or 0 depending if the two vertices are adjacent or not No self cycles = all 0s on the diagonal Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved

Basic Adjacency Matrix Representations Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Reference:

Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Adjacency Matrix Out-degree of i th vertex (node) –# of edges emanating out from a vertex –Sum of 1's (true's) in row i In-degree of j th vertex (node) –# of edges emanating into a vertex –Sum of the 1's (true's) in column j What is the out-degree of node 4? What is the in-degree of node 3?

Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graph Representation rows i columns j What is the out-degree of node 4? What is the in-degree of node 3? Out degree: i In degree: j

Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Adjacency Matrix Consider the sum of the products of the pairs of elements from row i and column j In general, the i, j entry of the mth power of adj, adj m, indicates the # of paths of length m from vertex i to vertex j adj adj 2 Fill in the rest of adj 2 This is the number of paths of length 2 from node 1 to node 3

Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Adjacency Matrix Basically we are doing matrix multiplication –What is adj 3 ? The value in each entry would represent –The number of paths of length 3 –From node i to node j Consider the meaning of the generalization of adj n

Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Adjacency Matrix Deficiencies in adjacency matrix representation –Data must be stored in separate matrix –When there are few edges the matrix is sparse (wasted space) data =

Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Adjacency-List Representation Solving problem of wasted space –Better to use an array of pointers to linked row-lists This is called an Adjacency-list representation

Exercise #1a: Find the adjacency matrix adj and the data matrix data for the given digraph Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved

Exercise #1a Solution Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved

Exercise #1b: Find the adjacency list adj for the given digraph Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved

Exercise #2: Draw the directed graph represented by the given adjacency matrix adj and the data matrix data Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved

Exercise #2: Solution Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved

Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Searching a Graph Recall that with a tree we search from the root But with a digraph … –may not be a vertex from which every other vertex can be reached –may not be possible to traverse entire digraph (regardless of starting vertex)

Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Searching a Graph We must determine which nodes are reachable from a given node Two standard methods of searching: –Depth first search –Breadth first search

Depth First Search Search “deeper in the graph whenever possible Overall idea is to take the most recently discovered vertex that has unexplored edges and explores deeper until all have been explored, then backtracks If undiscovered vertices remain, they get selected as a new source and process is repeated Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved

Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Depth-First Search Start from a given vertex v Visit first neighbor w, of v Then visit first neighbor of w which has not already been visited etc. … Continues until –all nodes of graph have been examined If dead-end reached –backup to last visited node –examine remaining neighbors

Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Depth-First Search Start from node 1 What is a sequence of nodes which would be visited in DFS? Click for answer A, B, E, F, H, C, D, G

Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Depth-First Search DFS uses backtracking when necessary to return to some values that were –already processed or –skipped over on an earlier pass When tracking this with a stack –pop returned item from the stack Recursion is also a natural technique for this task Note: DFS of a tree would be equivalent to a preorder traversal

Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Depth-First Search Algorithm to perform DFS search of digraph 1. Visit the start vertex, v 2. For each vertex w adjacent to v do: If w has not been visited, apply the depth-first search algorithm with w as the start vertex. Note the recursion

Breadth First Search Overall idea is that the “frontier” between discovered and undiscovered vertices expands uniformly across the breadth of the tree Other algorithms use similar ideas including Prim’s minimum spanning tree algorithm and Dijkstra’s single source shortest path algorithm Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved

Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Breadth-First Search Start from a given vertex v Visit all neighbors of v Then visit all neighbors of first neighbor w of v Then visit all neighbors of second neighbor x of v … etc. BFS visits nodes by level

Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Breadth-First Search Start from node containing A What is a sequence of nodes which would be visited in BFS? Click for answer A, B, D, E, F, C, H, G, I

Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Breadth-First Search While visiting each node on a given level –store it so that –we can return to it after completing this level –so that nodes adjacent to it can be visited First node visited on given level should be First node to which we return What data structure does this imply? A queue

Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Breadth-First Search Algorithm for BFS search of a diagraph 1.Visit the start vertex 2.Initialize queue to contain only the start vertex 3.While queue not empty do a.Remove a vertex v from the queue b.For all vertices w adjacent to v do: If w has not been visited then: i.Visit w ii.Add w to queue End while

Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graph Traversal Algorithm to traverse digraph must: –visit each vertex exactly once –BFS or DFS forms basis of traversal –Mark vertices when they have been visited 1.Initialize an array (vector) unvisited unvisited[i] false for each vertex i 2.While some element of unvisited is false a.Select an unvisited vertex v b.Use BFS or DFS to visit all vertices reachable from v End while

Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Paths Routing problems – find an optimal path in a network –a shortest path in a graph/digraph –a cheapest path in a weighted graph/digraph Example – a directed graph that models an airline network –vertices represent cities –direct arcs represent flights connecting cities Task: find most direct route (least flights)

Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Paths Most direct route equivalent to –finding length of shortest path –finding minimum number of arcs from start vertex to destination vertex Search algorithm for this shortest path –an easy modification of the breadth-first search algorithm

Minimum Spanning Tree (MST) Spans the graph G Connects all the vertices –Forms a tree (spanning tree) Often want to find the connections with the least weight/distance = minimum spanning tree Two popular algorithms: Kruskal’s and Prim’s –(we will only be looking at Prim’s) Cormen, Leiserson, Rivest, Stein, Introduction to Algorithms, Third Edition, © 2012 MIT Press 41

MST’s and Circuit Design Want to make pins of several components electrically equivalent by wiring together Connect n pins with n-1 wires (1 wire to 2 pins) Best arrangement uses least amount of wire 42 Cormen, Leiserson, Rivest, Stein, Introduction to Algorithms, Third Edition, © 2012 MIT Press

MST’s and Circuit Design (ctd) 43 Cormen, Leiserson, Rivest, Stein, Introduction to Algorithms, Third Edition, © 2012 MIT Press

Example of MST -Weights on the edges are shown -Edges included in the MST are shaded -Total weight = 37 -Not unique 44 Cormen, Leiserson, Rivest, Stein, Introduction to Algorithms, Third Edition, © 2012 MIT Press

Prim’s MST algorithm Tree starts with arbitrary root vertex r Grows until the tree spans all vertices in V Each step adds to the tree A, a light edge that supports the MST 45 Cormen, Leiserson, Rivest, Stein, Introduction to Algorithms, Third Edition, © 2012 MIT Press

46 Cormen, Leiserson, Rivest, Stein, Introduction to Algorithms, Third Edition, © 2012 MIT Press

Prim’s Algorithm Example 47 Cormen, Leiserson, Rivest, Stein, Introduction to Algorithms, Third Edition, © 2012 MIT Press

Prim’s Algorithm Example 48

49

Dijkstra’s Algorithm Solves for the shortest path on a weighted digraph (all edges must be > 0) Overall, two sets are maintained one containing the vertices included in the shortest path tree, and vertices not yet included Each step looks for a vertex in the “not yet included” set that has a minimum distance to add to the shortest path tree set Note: shortest path from source to all vertices in the given graph 50 Cormen, Leiserson, Rivest, Stein, Introduction to Algorithms, Third Edition, © 2012 MIT Press

Algorithm: DIJKSTRA(V, E, w, s) INIT-SINGLE-SOURCE(V, s) S ← ∅ //Initialized to empty set Q ← V //insert all vertices in Q, min-priority queue while Q ≠ ∅ do u ← EXTRACT-MIN(Q) S ← S ∪ {u} for each vertex v ∈ Adj[u] do RELAX(u, v, w) Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved

View of Dijkstra’s Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved

Exercise: Dijkstra’s Algorithm Create the MST using Dijkstra’s Algorithm from the following example 53 Reference: algorithm/

Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs Like a digraph –Except no direction is associated with the edges –No edges joining a vertex to itself allowed

Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Undirected Graph Representation Can be represented by –Adjacency matrices Adjacency matrix will always be symmetric –For an edge from i to j, there must be –An edge from j to i –Hence the entries on one side of the matrix diagonal are redundant Since no loops, –the diagonal will be all 0's

Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Undirected Graph Representation Given Adjacency-List representation

Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Edge Lists Adjacency lists suffer from the same redundancy –undirected edge is repeated twice More efficient solution –use edge lists Consists of a linkage of edge nodes –one for each edge –to the two vertices that serve as the endpoints

Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Edge Nodes Each edge node represents one edge –vertex[1] and vertex[2] are vertices connected by this edge –link[1] points to another edge node having vertex[1] as one end point –link[2] points to another edge node having vertex[2] as an endpoint

Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Edge List Vertices have pointers to one edge

Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graph Operations DFS, BFS, traversal, etc. are similar as those for digraphs Note class template Graph, Fig. 16.4Fig –Uses edge-list representation of graphs as just described

Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Connectedness Connected defined –A path exists from each vertex to every other vertex Note the isConnected() function in Graph class template –Uses a DFS, marks all vertices reachable from vertex 1 View program in Fig. 16-5Fig –Exercises this function