[ library(graph_algorithms) | Reference Manual | Alphabetic Index ]
Finds a topological ordering of the graph if one exists
- a graph structure
- a list of integer node numbers
Finds a topological ordering of the graph, i.e. an ordering of the
nodes such that all edges go from earlier to later nodes.
Such an ordering exists if and only if the graph is acyclic.
If the graph is cyclic, the predicate fails.
In general, the ordering is not unique, an arbitrary one is computed.
The complexity is O(Nnodes + Nedges).
Modes and Determinism
- top_sort(+, -) is semidet
No topological ordering exists, i.e. the graph is cyclic
graph_is_acyclic / 1, graph_cycles / 2