Class TopologicalOrderAlgoImpl

java.lang.Object
com.jgalgo.alg.dag.TopologicalOrderAlgoAbstract
com.jgalgo.alg.dag.TopologicalOrderAlgoImpl
All Implemented Interfaces:
TopologicalOrderAlgo

public class TopologicalOrderAlgoImpl extends TopologicalOrderAlgoAbstract
A simple algorithm that compute a topological order in a DAG graph.

The algorithm perform iterations while maintaining the in-degree of each vertex. At each iteration, a vertex \(u\) with in-degree zero is added as the next vertex in the result topological order, and the vertex is 'removed' from the graph conceptually, practically the algorithm decrease the in-degree of each vertex reachable by one of \(u\)'s out going edges. If there is no vertex with zero in-degree before all vertices were added to the topological sort, there is a cycle and no topological order exists.

The algorithm is linear in both space and running time.

Author:
Barak Ugav