~/ learn/ comp-372/ cards/ Topological sort & strongly connected components
1 of 7

Type the topological-sort emit step (append on finish, reverse at the end)

Type the topological-sort emit step (append on finish, reverse at the end)

Answer

color[u] = BLACK result.append(u) # finished # ... after all DFS: result.reverse() # decreasing finish time

Appending on finish then reversing is equivalent to pushing onto the front of a list. The result is vertices in decreasing finish time = a valid topological order.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/50b0ebf0-80e0-444e-9070-6a0a1607ea20/flashcard utf-8 LF