Topological Sort
You can't take Data Structures before Intro to Programming. That one prerequisite is a directed edge, and a surprising number of problems are just that edge multiplied: order the nodes so every one of them lands after the things it depends on. Topological sort hands you that order, or tells you it's impossible because a cycle means something eventually depends on itself. Course Schedule, build order, task scheduling, they're the same problem with the nouns swapped out. When a prompt says "prerequisites" or "dependencies," it's showing you a directed graph and asking for an order.
Only works on DAGs (Directed Acyclic Graphs). If there's a cycle, no valid ordering exists.
- 1 problem, worked step by step
- about 30 min
Premium lessonData Structures & Algorithms
Keep going with Premium.
All 78 lessons and 103 worked problems in this course, plus what 100 companies ask, pulled from 20,000+ candidate reports.
100 companies. Checked every month.
Unlock the full course$49 a year · less than $1 a week · Cancel anytime