Reductions and Decomposition
Topological Sort
Topological Sort is an ordering of a graph's vertices such that for every directed edge u→v, u comes beforev in the ordering.
Topological sorts only apply to directed, acyclic (no cycles) graphs (DAG).
Topological sort is called a linearization of the graph, since all the vertices in the graph could be redrawn in one line.
Topological Sort Algorithm
Perform a DFS traversal from every vertex in the graph, not clearing markings in between traversals.
Record DFS postorder along the way.
Topological ordering is the reverse of the postorder.
The total runtime of DFS is O(V + E)
.
Shortest Path Algorithm for DAGs
Visit vertices in topological order.
On each visit, relax all outgoing edges.
Last updated