Topological sort

Posted on April 12, 2015
  1. Call DFS(G) to compute the finishing time of \(v.f\) for each vertex \(v\)
  2. As each vertex if finished, insert it to the front of a linked list
  3. return the linked list

Correctness

Notes

  1. Find the sink vertex
  2. Remove the vertex and nodes associated with the above vertex from the graph to obtain a new graph \(G\).
  3. recurse on \(G\) till \(G\) is empty.
  1. Create a new attribute to the graph nodes and this attribute of all edges except \(t\) to be zero and \(t\)’s attribute shall have value \(0\).
  2. Do a DFS search, but when the DFS procedure discovers the node \(t\), immediately, make it’s color black.
  3. When a vertex \(v\) finished, let the value of our attribute to be the sum of values of the attribute to it’s immediate children.
  4. The value of the our attribute of \(p\) after completion of DFS will be the number of simple paths from \(p\) to \(t\).