<aside>

This section is part of the 5-hour LeetCode DSA Foundations course by Mukul Raina

SLIDE 150: Section Intro, Graphs

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

  1. Graph representations: adjacency list and adjacency matrix
  2. Directed vs undirected, weighted vs unweighted
  3. BFS: level-by-level exploration with shortest path guarantee
  4. DFS: depth-first exploration, recursive and iterative
  5. Grids as implicit graphs
  6. Connected components and cycle detection
  7. Worked example: Number of Islands

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>


SLIDE 151: Graph Representations: Adjacency List and Adjacency Matrix