LeetCode Course Schedule: Topological Sort with DFS
Detect cycles and produce a valid course order in LeetCode 207 Course Schedule using DFS-based topological sort. Includes BFS Kahn alternative and interview script.
10 posts.
Detect cycles and produce a valid course order in LeetCode 207 Course Schedule using DFS-based topological sort. Includes BFS Kahn alternative and interview script.
Understand Bellman-Ford's relaxation loop, how it handles negative edges, detects negative cycles, and why it costs more than Dijkstra.
Learn Dijkstra's shortest path algorithm with a clean Python implementation, complexity analysis, and the priority queue intuition behind it.
Build minimum spanning trees with Kruskal's union-find approach and Prim's priority queue approach, with side-by-side Python implementations.
LeetCode 133 walked through — why a hash map from original to copy is the entire idea, plus the BFS variant for stack-limited environments.
LeetCode 417 explained — why you should flood from the oceans inward, not from each cell outward, and how the intersection gives the answer.
LeetCode 127 walked through — the wildcard-pattern adjacency trick, why BFS is mandatory, and the bidirectional speedup.
Compare Kahn's BFS-based topological sort with DFS-based postorder, with Python implementations, complexity, and cycle detection.
A practical guide to BFS and DFS on graphs — recursive and iterative DFS, BFS with a deque, shortest paths on unweighted graphs, connected components, cycle detection, and five classic practice problems.
A practical introduction to graphs — directed vs undirected, weighted vs unweighted, cyclic vs acyclic, and the three main representations (adjacency list, adjacency matrix, edge list) with Python code.