A topic in the Open Knowledge Graph — a free, open map of 15,495 topics and the order to learn them in.

Directed Acyclic Graphs (DAGs)

College Depth 87 in the knowledge graph ☐ I know this ☆ Set as goal
1topic build on this
419prerequisites beneath it
See this on the map →
Directed Graphs and DigraphsCycle Detection in Directed Graphs→→Topological Sorting and Ordering
directed-graphs acyclic dags

Core Idea

A directed acyclic graph (DAG) is a digraph with no directed cycles. DAGs are fundamental in computer science for modeling dependencies, partial orders, and data flow. The absence of cycles guarantees that topological orderings exist.

Explainer

You already know that a directed graph (digraph) has edges with a direction — an arrow from A to B means something different from an arrow from B to A. Now add one constraint: no directed cycles. A directed acyclic graph, or DAG, is simply a digraph where you can never follow edges in their direction and return to where you started. That one restriction turns out to have profound consequences.

The easiest way to build intuition for DAGs is to think about prerequisites. In this knowledge graph, topics point to the topics that require them. You can't learn Gaussian elimination before you learn systems of equations. This dependency structure is a DAG — if topic A is a prerequisite for B, and B for C, then C cannot also be a prerequisite for A without creating circular reasoning. Real dependency systems (software packages, build steps, course sequences, task pipelines) are almost always DAGs for exactly this reason: cycles represent impossible orderings.

The absence of cycles has a direct structural payoff: every DAG has at least one source (a vertex with no incoming edges) and at least one sink (a vertex with no outgoing edges). This is easy to see — if every vertex had at least one incoming edge, you could always walk backwards along edges indefinitely, eventually revisiting a vertex and forming a cycle. Since that can't happen, sources must exist. The symmetric argument gives sinks.

This is why topological sorting is possible in DAGs but not in general digraphs. A topological ordering is a linear sequence of all vertices such that every directed edge goes from earlier to later in the sequence. It's the formal version of "do all prerequisites before the topic they unlock." Your prerequisite on cycle detection in directed graphs connects here: a digraph has a topological ordering if and only if it contains no directed cycle — i.e., if and only if it is a DAG. Any DFS-based cycle check on a directed graph is simultaneously a test for DAG-ness. If no back-edge is found, you have a DAG and can read off a topological order from the DFS finish times in reverse.

Practice Questions 5 questions

Prerequisite Chain

Understanding Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Combining Small Groups Within 5 → Number Bonds Within 5 → Number Bonds to 10 → Tens and Ones Place Value → Reading and Writing Three-Digit Numbers → Comparing Three-Digit Numbers → Comparing and Ordering Three-Digit Quantities → Comparing and Ordering Whole Numbers → Comparing Numbers 1 to 20 → Ordering Numbers to 20 → Number Line 0 to 20 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Opposites and Additive Inverses → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Dividing Integers → Unit Rates → Proportions → Percent Concept → Converting Between Fractions, Decimals, and Percents → Operations with Rational Numbers → Two-Step Equations → Solving Multi-Step Equations → Equations with Variables on Both Sides → Literal Equations → Slope-Intercept Form → Point-Slope Form → Writing Linear Equations → Parallel and Perpendicular Line Slopes → Graphing Linear Equations → Piecewise Functions → Step Functions → Composition of Functions → Inverse Functions → Radical Functions and Graphs → Rational Exponents → Exponential Functions and Graphs → Logarithms Introduction → Big-O Notation and Asymptotic Analysis → Depth-First Search (DFS) → Cycle Detection in Directed Graphs → Directed Acyclic Graphs (DAGs)

Longest path: 88 steps · 419 total prerequisite topics

Prerequisites (2)

Leads To (1)