What is Topological Sorting
Topological Sorting(拓扑排序) is designed for Directed Acyclic Graph(DAG, 有向无环图). Topological Sorting is a linear ordering of vertices such that for every directed edge u v, vertex u comes before v in the ordering.
Example
Topological sorting can be more than one result. For this graph, “5 4 2 3 1 0” is one of the result. The first vertex in topological sorting is always a vertex with an in-degree of 0.
Algorithm to do Topological Sorting
DFS
深度优先搜索以任意顺序循环遍历图中的每个节点,若搜索进行中碰到之前已经遇到的节点,或碰到叶节点,则中止算法。
Kahn’s Algorithm
First, find a list of “start nodes” which have no incoming edges and insert them into a set S; at least one such node must exist in a non-empty acyclic graph
Topological Sorting Application
- Task Priorities
Reference
- “Topological Sorting.” GeeksforGeeks, 12 May 2013, https://www.geeksforgeeks.org/topological-sorting/.
- “拓撲排序.” 维基百科,自由的百科全书, 22 May 2022. Wikipedia, https://zh.wikipedia.org/w/index.php?title=%E6%8B%93%E6%92%B2%E6%8E%92%E5%BA%8F&oldid=71758255.
- “算法 - 拓扑排序.” Earth Guardian, 22 Aug. 2018, http://redspider110.github.io/2018/08/22/0092-algorithms-topological-sorting/index.html.