Topological Sort

Kahn's algorithm (BFS-based), DFS-based topological sort, and cycle detection in directed graphs.

41 lessons
134 min

Lessons

1. Intro

Getting Dressed

2m

2. Directed Acyclic Graphs (DAGs)

No Circles Allowed

2m

3. Kahn's Algorithm - The Intuition

Peeling the Onion

3m

4. Kahn's Algorithm - Implementation

The Template

8m

5. Detecting Cycles with Kahn's

The Leftovers

3m

6. Quiz: Cycle Detection with Kahn's

Knowledge check

2m1 problems

7. Problem - Course Schedule II

LeetCode 210

2m1 problems

8. Course Schedule II - The Constraint

Building dependencies

3m

9. Course Schedule II - Core Idea

In-degree tracks readiness

3m

10. Course Schedule II - Algorithm

Kahn's step by step

4m

11. Course Schedule II - Implementation

The code

5m1 problems

12. Lessons from Course Schedule II

What you learned

3m

13. DFS-Based Topological Sort

Alternative to Kahn

5m

14. Comparing Kahn and DFS

When to use each

5m

15. Quiz: Kahn's vs DFS Topological Sort

Knowledge check

2m1 problems

16. Common Topological Sort Mistakes

Pitfalls to avoid

5m

17. Pattern - Lexicographical Order

Controlling the Choice

3m

18. Pattern - Uniqueness

Is there only one way?

3m

19. Pattern - Implicit Graphs

Deriving Edges

4m

20. Dynamic Programming on DAGs

The Real Power

4m

21. Quiz: DAG Properties

Knowledge check

2m1 problems

22. Problem - Longest Flight Route

The code

5m1 problems

23. Longest Flight Route - Core Idea

DP on topological order

3m

24. Longest Flight Route - Algorithm

Kahn's + DP

4m

25. Longest Flight Route - Implementation

CSES 1680

2m1 problems

26. Pattern - Reverse Logic

Flip the edges

3m

27. Lessons from Longest Flight Route

DAG DP pattern

3m

28. Quiz: DP on DAGs

Knowledge check

2m1 problems

29. Problem - Game Routes

CSES 1681

2m1 problems

30. Game Routes - Core Idea

Summing paths instead of max

3m

31. Game Routes - Algorithm

Topological order guarantees

3m

32. Game Routes - Implementation

The code

5m1 problems

33. Lessons from Game Routes

Counting on DAGs

3m

34. Quiz: Counting Paths in a DAG

Knowledge check

2m1 problems

35. Problem - Parallel Courses III

LeetCode 2050

2m1 problems

36. Parallel Courses III - Core Idea

Finish time propagates

3m

37. Parallel Courses III - Algorithm

DP on topological order

4m

38. Parallel Courses III - Implementation

The code

5m1 problems

39. Lessons from Parallel Courses III

Critical Path Method

3m

40. Quiz: Parallel Scheduling

Knowledge check

2m1 problems

41. Section Recap

Order from Chaos

2m

Practice Problems

1.
Course Schedule IILeetCodemedium
2.
Alien DictionaryLeetCodehard
4.
Fox And NamesCodeforcesmedium
5.
Directing EdgesCodeforcesmedium
6.
Karen and SupermarketCodeforceshard

Ready to start learning?

Access all 41 lessons with interactive content and progress tracking.