Class Questions for CLR&S, Section 22.4

Summaries

  1. Topological Sort of a graph is a depth-first search on a directed graph. A topological sort of a dag (directed graph) G = (V, E) is a linear ordering of all its vertices such that if G contains an edge (u, v) then u appears before v in the ordering. (If the graph contains a cycle, then no linear ordering is possible.)

    The algorithm for a topological sort is the following:

    TOPOLOGICAL-SORT (G)

    1. call DFS (G) to compute finishing times v.f for each vertex v
    2. as each vertex is finished, insert it onto the front of a linked list
    3. return the linked list of vertices

    Lemma 22.11
    A directed graph G is acyclic if and only if a depth-first search of G yields no back edges.

  2. Topological sort sorts directed acyclic graphs (basically posets), which have the property that if you can get from node A to node B, then there's no way to get from node B to node A. The sorting algorithm will place node A before node B if node B can be reached from node A.

  3. The algorithm is really really simple: run a depth-first search. Each time we hit a dead end, insert that node in the front of a linked list. The end. Since inserting into the front of a linked list has O(1) and we insert V nodes, this adds an additional O(V) work and the algorithm still runs in linear time.

  4. A topological sort is sort of a method of compressing the vertices of a directed graph with no cycles, meaning no loops, into a line. If there is a path from vertex u to vertex v, then u comes before v in the ordering. To do this, we first run a depth first search. As we discover each node, it is placed at the front of a linked list. Since the depth first search runs in Theta(vertices + edges), and inserting a node at the front of a linked list takes Theta(1), this sort will take Theta(vertices+edges).

  5. Topological sort is an application of depth-first search. G=(V,E) is a linear ordering of all its vertices, which means v is before e. Majority of this sorting use directed acyclic graphs. The example from the reading explains this method very well.

  6. Topological sort can be applied to a directed acyclic graph, or a DAG. It sorts the graph in a linear ordering so that all of its vertices, on an edge (u, v), u appears before v in the ordering. If there's a cycle in the graph, then this linear ordering is impossible. v would have to start before u, but we need u to finish before v, and we wouldn't even be able to visit u if that were the case, which leads us to the conclusion that topological sort will not be possible on a cyclic graph. A DAG and the topological sort are used to indicate what event takes precedence over another. A real world application of this would for example be job scheduling.

  7. A topological sort is a depth-first search that orders the vertices "such that if G contains an edge (u,v), then u appears before v in the ordering". The algorithm goes: call depth first search for each vertex, when each DFS is finishes, put it on the front of a linked list, return that list. The performance of this sort is Omega(V+E).

  8. In this section, we learn that we can use depth-first search to perform a topological sort of a directed acyclic graph. In topological search, you first call depth first search, and after each vertex is popped from the stack, you insert it in the front of a linked list and your return this sorted linked list of vertices. Topological takes O(V+E) time.

  9. In this chapter we discuss the topographical sort. Which is a linerar ordering of all vertices of a directed acyclic graph such that if an element contains an esge (u, v), then u appears before v. Topographical sort produces a topological sort of the directed acyclic graph.

  10. A topological sort of a dag(G=(V,E)) is a linear ordering of all its vertices such that if G contains an edge then u appears before v in the ordering.

    Here is how to do Topological sort:

    1. call DFS(G) to compute finishing times v.f for each vertex v.
    2. as each vertex is finished, insert it onto the front of a linked list.
    3. return the linked list of vertices.
  11. Here is the algorithm to find the strongly-connected components:

    1. call DFS(G) to compute finishing times u.f for each vertex u.
    2. compute G transpose
    3. call DFS(G transpose), but in main loop of DFS, consider the vertices in order of decreasing u.f from the first step
    4. output the vertices of each tree in the depth-first forest formed in step 3 as a separate strongly-connected component.

Questions

  1. In topological sort, is there more than one possible solution when ordering the verticies (depending on starting point)?

  2. If we have a cycle, do we just return a failure, or is there an accepted way of dealing with cycles in topological sorting?

  3. Would you mind going over exactly why topological sort only takes time theta(V+E)?

  4. Would you mind going over the proofs on page 614?

    [Overall, this makes a lot more sense after Prof. Walker's explanations on Wednesday.]

  5. I don't quite understand what "topological" means.

  6. Topological sorting seems pretty straightforward but I have a question about cyclic graphs. Can we topologically sort part of a graph if only some subset of its vertices are cyclical?

  7. What is a practical use for topological sort?

  8. Could you go over the proofs on page 614?

  9. Why are strongly connected components important?

  10. What is the transpose of a graph?

  11. What happens if a strongly connected component has a sub-graph containing a smaller strongly connected component?

  12. Could you go over the proofs?


This document is available on the World Wide Web as

http://www.walker.cs.grinnell.edu/courses/301.fa13/student-comments/student-comments-clrs-sec22.4.shtml

created November 23, 2013
last revised November 23, 2013
Valid HTML 4.01! Valid CSS!
For more information, please contact Henry M. Walker at walker@cs.grinnell.edu.