Module 8 · Graphs and Trees · Topological Sorting

Course schedule II

A course can be taken once all its prerequisites are done. Kahn's BFS keeps taking courses with no prerequisites left; the DFS adds a course once everything it needs is finished. A cycle of prerequisites means no order works.

Approach