AlgoFrames

Finishing order

Standard · Trace the algorithm · about 6 min

Pass 1 of Kosaraju runs DFS from A and records when each node finishes. After each finish, click the node that finishes next.

Example 1

Input:

{"edges":[["A","B"],["B","C"],["C","A"],["C","D"],["D","E"],["E","D"],["F","E"],["F","A"]]}

Output:

["E","D","C","B","A","F"]

F is unreached from A, so a second DFS starts there.

Constraints

  • Neighbors are tried in the order edges are listed.
  • Unvisited nodes start new searches in alphabetical order.

Learn the idea first: Strongly connected components: Kosaraju and Tarjan, a visual lesson.

More Strongly connected components: Kosaraju and Tarjan problems