<aside>
This section is part of the 5-hour LeetCode DSA Foundations course by Mukul Raina
Section 16: Graphs Foundations
Graphs generalize trees. Where a tree has a single root, no cycles, and exactly one path between any two nodes, a graph allows cycles, multiple paths, disconnected components, and directed or undirected edges. Many real-world problems that do not look like graph problems turn out to be graph problems: navigating a grid, detecting dependencies, finding connected groups, checking reachability.
Graph problems appear in roughly 15-20% of DSA interviews. Nearly every graph problem reduces to one of two fundamental traversals: BFS (breadth-first search) or DFS (depth-first search). If you know when to apply each and how to implement them cleanly, you can solve the majority of graph interview questions.
What We'll Cover
Where This Section Connects
| Section | Connection |
|---|---|
| Stacks and Queues (Section 10) | BFS uses a queue, iterative DFS uses a stack. The data structure drives the traversal order. |
| Linked Lists (Section 11) | Floyd's cycle detection on linked lists is a specialized form of cycle detection. Graph cycle detection generalizes it. |
| Recursion (Section 12) | Recursive DFS is a direct application of the recursive mental model from Section 12. |
| Trees (Section 15) | Trees are a special case of graphs (connected, acyclic). Tree BFS and DFS are graph BFS and DFS without a visited set. |
<aside>
Mukul Raina | youtube.com/@mukulraina | linkedin.com/in/mukulraina
</aside>