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?
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]|
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.
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.
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