Topological sort
The vertices of a directed graph with no cycles can be lined up so every edge points forward, by repeatedly taking out a vertex with no edges coming in, and when none is left to take while vertices remain, the graph has a cycle.
The vertices of a directed graph with no cycles can be lined up so every edge points forward, by repeatedly taking out a vertex with no edges coming in, and when none is left to take while vertices remain, the graph has a cycle.