Bfs-dfs

28 articles

dsa7 min read

Clone Graph — Deep Copy with BFS, DFS and HashMap Bookkeeping

Master Clone Graph (LeetCode 133): a FAANG favorite that tests BFS, DFS, graph traversal, hash map state, and cycle handling. We trace it step by step, derive the optimal pattern, and fortify you against the classic mistakes interviewers love to spot.

Read →
dsa7 min read

Course Schedule — Cycle Detection via Topological Sort

A directed graph cycle-detection problem solved by Kahn topological sort (BFS) or three-color DFS. The bedrock template behind dependency resolution at Maven, npm, Bazel, Make, and every modern build system.

Read →
dsa7 min read

Graph Valid Tree — Cycle and Connectivity Check

A graph is a valid tree iff it is connected and has no cycles, equivalently exactly n - 1 edges and one connected component. Solve with BFS, DFS, or Union Find — Union Find is shortest.

Read →