Lectures 23 and 24
Graphs. 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
in pseudo code. Recursion.
- 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:
Interpretation for computer networks, road networks, etc.
- Decide if an undirected graph is
- 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.