Algorithms / Dags And Paths
Least You Need to Know: Topological Order, DAGs, and Path Intuition
A **topological order** lists the vertices of a directed acyclic graph so every edge points forward in the list. DAG thinking shows up in build systems, prerequisite planning, dependency graphs, and many workflow pipelines.
The least you need to know
- A topological ordering exists exactly when a directed graph has no directed cycle.
- In a topological order, every prerequisite appears before the task that depends on it.
- A shortest path minimizes total path cost under the cost model in the question.
- A spanning tree connects all vertices without cycles and uses exactly `n-1` edges on `n` vertices.
- DAGs are common models for dependencies because cycles break prerequisite ordering.
Key notation
DAG
directed acyclic graph
u → v
u must come before v in a topological order
n-1 edges
edge count of a tree on n vertices
Tiny worked example
- If course A is a prerequisite for course B, draw an edge `A → B`.
- A valid semester plan must place A before B.
- A topological order is exactly such a valid dependency-respecting arrangement when no cycle exists.
Common mistakes
- Students often think any directed graph has a topological order.
- Students often confuse shortest path by edge count with shortest path by total weight.
- Students often forget that a spanning tree cannot contain cycles.
How to recognize this kind of problem
- If the question mentions prerequisites or build dependencies, think DAG and topological order.
- If the graph contains a directed cycle, no valid topological order can exist.
- Ask whether path cost means edge count or weighted total.