Topological sort #
Topological sort of a directed graph given by adjacency lists: the vertices in reverse order of
finishing time under the depth-first search of CslibFrontier.Algorithms.Lean.DFS.Basic, following
Cormen et al., Section 22.4. Linear-time iterative execution on the standard-basis word
RAM is proved in CslibFrontier.Algorithms.WordRAM.DFS.
Main definitions #
Cslib.Algorithms.Lean.DFS.IsTopologicalOrder: a list of all the vertices, without repetition, in which the source of every edge comes before its target.Cslib.Algorithms.Lean.DFS.topologicalSort: topological sort via reverse DFS finishing order.
Main results #
Cslib.Algorithms.Lean.DFS.IsTopologicalOrder.acyclic: a graph with a topological order is acyclic.Cslib.Algorithms.Lean.DFS.isTopologicalOrder_topologicalSort_iff: from a list of all the vertices, topological sort returns a topological order exactly when the graph is acyclic Cormen et al., Theorem 22.12. In particular a graph is acyclic if and only if it has a topological order (Cslib.Algorithms.Lean.DFS.acyclic_iff_exists_isTopologicalOrder).
References #
A topological order of the graph: a list of distinct vertices containing every vertex, in which the source of each edge comes before its target.
A graph with a topological order is acyclic: positions in the order strictly increase along every edge.
Topological sort: the vertices in reverse order of finishing time under depth-first search
from the vertices vs in turn.
From a list of all the vertices, topological sort lists each vertex at most once.
From a list of all the vertices, topological sort lists every vertex.
Topological sort is correct exactly on acyclic graphs Cormen et al., Theorem
22.12: from a list vs of all the vertices, topologicalSort adj vs is a topological
order if and only if the graph is acyclic.
A finite graph is acyclic if and only if it has a topological order.
Topological sort of List.finRange N has length N.