CS 112
Lecture 22
More on the Final Project
- User interface. See for example the executable file testGraph
in the directory ~112b/Graph/. To go there, log on your 112b-xx
account, then do cd ~112b/Graph. To run testGraph, type
testGraph at the Unix prompt. This is the minimal interface I expect.
- Discussion of the data structure.
Today's topic:
Graph Traversal, Depth First Search and Connectivity
- Directed graphs versus undirected graphs. Examples.
- Paths in graphs (directed and undirected). Examples.
- Connected versus not connected graphs. Examples.
- Connected digraphs for which there exists no path from a node
A to a node B. Examples.
- Graph traversal algorithm: starts at a node v and "visits"
all the nodes that can be reached by directed paths from v.
- Depth-first search (DFS) from node v: from each node, follow a path
as far as you can, while visiting only vertices that you have not
previously seen. When you reach a previously visited vertex,
back up to where you came from and visit the next child of the
current node, if any exists. Otherwise back up and repeat this
procedure. Stop when you are
at v and have backed up from its last child.
- Example of how DFS works.
- Implementation of
DFS
in pseudo code. Recursion. The C++ implementation is part of the
final project assignment.
- Simulation of how the code is executed for a graph
given by its adjacency list representation (not C++ code, but
rather box-and-arrow notation).
- Application to Connectivity problems:
- Decide if an undirected graph is
connected.
- Decide if there exists a path from a given node v to
another node u in a directed graph.
- Decide if there exists a node
that cannot be reached from a node v, in a directed graph.
- List all the nodes reachable from a given node v.
Interpretation for computer networks, road networks, etc.
Ileana Streinu