Chapter 12: Graphs

12.1 The Graph Abstract Data Type

Graphs.pdf 1-10

12.1.1 Graph Functions

General Functions:
numVertices()
Return the number of vertices in G.
numEdges()
Return the number of edges in G.
vertices()
Return an iterator of the vertices of G.
edges()
Return an iterator of the edges of G.
aVertex()
Return a vertex of G.
degree(v)
 Return the degree of v.
adjacentVertices(v)
Return an iterator of the vertices adjacent to v.
incidentEdges(v)
Return an iterator of the edges incident upon v.
endVertices(e)
Return an array of size 2 storing the end vertices of e.
opposite(v,e)
Return the endpoint of edge e distinct from v.
areAdjacent(v,w)
Return true whenever vertices v and w are adjacent.

Functions Dealing with Directed Edges:
directedEdges()
Return an iterator of all directed edges.
undirectedEdges()
Return an iterator of all undirected edges.
destination(e)
Return the destination of the directed edge e.
origin(e)
Return the origin of the directed edge e.
isDirected(e)
Return true if and only if the edge is directed.
inDegree(v)
Return the in-degree of v.
outDegree(v)
Return the out-degree of v.
inIncidentEdges(v)
Return an iterator of all the incoming edges to v.
outIncidentEdges(v)
Return an iterator of all the outgoing edges from v.
inAdjacentVertices(v)
Return an iterator of all vertices adjacent to v along incoming edges to v.
outAdjacentVertices(v)
Return an iterator of all vertices adjacent to v along outgoing edges from v.

Functions for Updating Graphs:
insertEdge(v,w,o)
Insert and return an undirected edge between vertices v and w, storing the object o at this position.
insertDirectedEdge(v,w,o) Insert and return an directed edge from vertex v to vertex w, storing the object o at this position.
insertVertex(o)
Insert and return a new (isolated) vertex storing the object o at this position.
removeVertex(v)
Remove the vertex v and all its incident edges.
removeEdge(e)
Remove edge e.
makeUndirected(e)
Make edge e undirected.
reverseDirection(e)
Reverse the direction of directed edge e.
setDirectionFrom(e,v)
Make e directed away from vertex v.
setDirectionTo(e,v) Make e directed into vertex v.


12.2 Data Structures for Graphs

Graphs.pdf 11-14

12.2.1 The Edge List Structure

Vertex Objects

Edge Objects

The Edge List

Performance

12.2.2 The Adjacency List Structure

The Adjacency List
Performance

12.2.3 The Adjacency Matrix Structure

Performance

12.3 Graph Traversal

12.3.1 Depth-First Search

The Decorator Pattern

Polymorphic Objects
html-12.2 (Object1)
html-12.3 (Object2)

A Generic DFS Implementation in C++

Using the Template Method Pattern for DFS
html-12.4 (DFS1)
html-12.5 (DFS2)
html-12.6 (ConnectTestDFS)
html-12.7 (FindPathDFS)
html-12.8 (FindCycleDFS)

12.3.2 Breadth-First Search

BFS.pdf 1-12

12.4 Directed Graphs

Digraphs.pdf 1-
Comparing BFS and DFS for Directed and Undirected

Graphs

Reachability

12.4.1 Traversing a Digraph

Testing for Strong Connectivity

Directed Breadth-First Search

12.4.2 Transitive Closure

12.4.3 Directed Acyclic Graphs

Testing if a Directed Graph is Acyclic


12.5 Weighted Graphs

ShrotestPaths.pdf 3


12.6 Shortest Paths

ShrotestPaths.pdf 4-5

12.6.1 Dijkstra's Algorithm

ShrotestPaths.pdf 6

A Greedy Method for Finding Shortest Paths

Edge Relaxation

Why It Works

The Running Time of Dijkstra's Algorithm

An Alternative Implementation for Dijkstra's Algorithm

Comparing the Two Implementations

Programming Dijkstra's Algorithm in C++
html-12.14 (LocatorX)
html-12.15 (Dijkstra1)
html-12.16 (Dijkstra2)

12.7 Minimum Spanning Trees

MST.pdf 1-
Problem Definition
A Crucial Fact about Minimum Spanning Trees

12.7.1 Kruskal's Algorithm

The Running Time of Kruskal's Algorithm

12.7.2 The Prim-Jarnik Algorithm

A Comparison of the Above MST Algorithms