Graph Theory37 sections · 1633 units
Open in Course

Directed Acyclic Graphs (DAGs)

No Circles Allowed

A Directed Acyclic Graph (DAG) is a directed graph with no cycles. "Directed" means edges have a direction (ABA \to B is not the same as BAB \to A). "Acyclic" means you can never follow edges and return to where you started.

Topological sort only works on DAGs. If your graph has a cycle like ABCAA \to B \to C \to A, there is no valid ordering. AA must come before BB, BB before CC, and CC before AA, which is a contradiction. Detecting whether a graph is a DAG is part of the topological sort process. If the algorithm cannot order all nodes, you know a cycle exists.