AlgoScope

DFS Topological Sort

Reverse postorder of a DFS is a topological order, and a back edge means there is none.

Connectivity and topological order, algorithm, intermediate
Enter vertex 0. Next is 1.012345u
Enter vertex 0. Next is 1.012345u

Topological Sort: DFS finish order

Decision, step 2 of 14

Enter 0. Its edges go to 1, 2. Unvisited: 1, 2. Go into 1 first.

How topological sort works

Cost

Best
O(V + E)
Average
O(V + E)
Worst
O(V + E)
Space
O(V)

Taught by the same lesson

Topological Sort covers these too, in the same run.