ClassS04CS141 | ClassS04CS141 | recent changes | Preferences

1. Simulate DFS on the directed graph with the following edge and vertex set:

vertex set = {A, B, C, D, E, F, G, H, J}

directed edges = { (A,B), (A,C), (B,D), (B,E), (D,H), (D,J), (C,F), (C,G), (H,B), (D,A), (F,E), (A,G) }

Start the DFS at vertex A, and, given a choice, visit neighbors of each vertex in alphabetical order.

Recall that the dfs-numbering of the vertices gives the order in which the vertices are first encountered during the DFS.

Define the dfs post-order numbering of the vertices so that it gives the order in which the vertices are first finished with during the DFS.

For example, a vertex v has post-order number 1 if it is the first one such that the call DFS(v) returns. (Such a vertex will always be a leaf in the dfs tree.) The vertex with post-order number N (the number of vertices) will always be the root of the DFS tree, provided all vertices are reachable from the root.

1A. What are the dfs-numbers of the vertices?

1B. What are the dfs-post-order numbers of the vertices?

1C. If you run BFS (breadth-first search, starting at A) what are the distance labels of the vertices?

2. Classification of edges

Recall that DFS on a directed graph classifies edges into tree, back, cross, and forward edges.

2A. List the edges of each type in the example you did above.

2B. In general, if an edge (u,v) is of the type in the first column below, which conditions are possible?

type pre[u] < pre[v] pre[u] > pre[v] post[u] < post[v] post[u] > post[v]
tree: ? ? ? ?
back: ? ? ? ?
forward: ? ? ? ?
cross: ? ? ? ?

Above pre[u] denotes the dfs-number of u, post[u] denotes the dfs post-order number, defined in problem 1.

2C. In terms of the post-order numbers, what is unique about back edges? Use this to give another argument that, if the DFS yields no back edges, then the graph has no cycles.

3. Algorithm for topologically sorting a directed acyclic graph

Describe an algorithm that, given a directed graph G with no cycles, outputs the vertices of the graph in some order v1, v2, ..., vn so that any directed edge in the graph goes backward in the ordering. That is, if there is an edge from vi to vj, then i ≥ j.

Your algorithm should run in time O(N+M) where N is the number of vertices and M is the number of edges. Argue that your algorithm does this.

4. Prove that the root vertex of the DFS tree is a cut vertex iff it has more than one child in the DFS tree

In class we claimed but did not prove that in a DFS of an undirected graph, the root vertex v is a cut vertex if and only if it has more than one child in the DFS tree. (Recall that a cut vertex is a vertex whose removal disconnects the graph.)

Prove this claim. Argue carefully that

ClassS04CS141 | ClassS04CS141 | recent changes | Preferences
This page is read-only | View other revisions
Last edited April 26, 2004 3:50 pm by Neal (diff)