ClassS04CS141/Notes 04 21

ClassS04CS141 | ClassS04CS141 | recent changes | Preferences

Showing revision 1

We discussed directed graphs, paths and cycles in directed graphs, BFS in directed graphs, and DFS in directed graphs.

We discussed the concepts of "tree", "back", "forward", and "cross" edges resulting from a DFS.

We considered the following claim:

A directed graph has a cycle if and only if the DFS yields at least one back edge.

We considered whether the claim was true.

If there is a back edge, it seems clear there is a cycle (using the back edge (U,W) and the tree edges from W to U.

In the other direction, suppose the DFS yields no back edge. Then, considering the DFS tree of the graph, all edges go "left" or "down". Intuitively, this means there is no cycle. We tried to give a more precise argument as follows:

Suppose there is a cycle C. Let W be the first vertex in C encountered by the DFS. Let (U,W) be the edge into W on the cycle C.

Claim: (U,W) must be a back edge.

Why? Considering each case carefully, we can rule out that (U,W) is a tree edge, a cross edge, or a forward edge. Thus, it must be a back edge.

In this way we've convinced ourselves that if the graph has a cycle, the DFS must have a back edge.


Later we gave the following somewhat different argument.

Order the vertices v1,v2,...,vn in the order in which the DFS finishes with them.

Every cross edge, tree edge, or forward edge must go backward in this ordering. (This is because for each such edge (U,W), one can reason out that W must be finished before U.)

Thus, there can be no cycle using just the cross edges, tree edges, and forward edges. (Because along any path using these edges, the ranks (in the ordering) of the respective vertices along the path is always decreasing.)



ClassS04CS141 | ClassS04CS141 | recent changes | Preferences
This page is read-only | View other revisions | View current revision
Edited April 26, 2004 7:36 pm by Neal (diff)
Search: