Kanh’s Algorithm
An algorithm for topological-sort, useful when we don’t have access to attributes of vertices.
- Put vertices with in-degree of in
- Set counter to
- While
- Remove a vertex
- Set label of to counter
- Increment the counter
- For any edge , decrement the in-degree of
- If , put into
- If counter is less than , there must be a cycle! Since some vertices didn’t get labeled, they must be in the cycle.