Graph-Based Algorithms: CSE373: Design and Analysis of Algorithms
Graph-Based Algorithms: CSE373: Design and Analysis of Algorithms
Graph-Based Algorithms
CSE373: Design and Analysis of Algorithms
Properties of DFS
Parentheses structure: If we represent the
discovery of vertex with a left parenthesis
and represent its finishing by a right
parenthesis , then the history of discoveries
and finishings makes a well-formed expression
in the sense that the parentheses are properly
nested.
Properties of DFS
This
yields the parentheses theorem: For any
Properties of DFS
Classifying Edges
Consider edge in directed graph
w.r.t. DFS forest
1. tree edge: is a child of
2. back edge: is an ancestor of
3. forward edge: is a descendant of (but not
a child)
4. cross edge: all other edges. They can go
between vertices in the same depth-first
tree, as long as one vertex is not an ancestor
of the other, or they can go between vertices
in different depth-first trees.
Classifying Edges
The
DFS algorithm can be used to classify graph
edges by assigning colors to them. Each edge
can be classified by the color of the vertex that
is reached when the edge is explored:
Classifying Edges
Given
a directed acyclic graph (DAG), find a
linear ordering of the vertices such that if is an
edge, then precedes in the ordering.
DAG indicates precedence among events:
events are graph vertices, edge from to means
event has precedence over event
DAG:
TOPOLOGICAL-SORT(G)
1 call DFS(G) to compute finishing times for each vertex
2 as each vertex is finished, insert it onto the front of a linked list
3 return the linked list of vertices