Topological Sort & SCC
Summarized notes on Introduction to Algorithms, Chapter 22
Topological Sort
- DFS can be used to perform topological sort on directed acyclic graph, or DAG
- topological sort is a linear ordering of all vertices such that is contains
edge then appears before in ordering
→ sort by highest to smallest finish time
- the result of topological sort is a linked list of vertices
- result can be visualized as ordering of vertices along a horizontal line so that all directed edges go from left to right
- linear sort is possible only if there are no cycles
- → DFS cannot yield any back edges; otherwise there is a cycle
Complexity
Strongly Connected Components
- finding strongly connected components is an application of DFS
- strongly connected component is maximal set of vertices such that
for every vertex and in , both and
- given algorithm:
- run DFS on to compute finish time for each vertex
- computes transpose where edge directions are reversed
- run DFS on in order of decreasing finish times
- output vertices of each tree in depth-first forest; these are the strongly connected components
- the component graph is a DAG
Complexity