<aside>

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

C11: DSA Foundations for Interviews

Section 12: Recursion and Backtracking


SLIDE 110: Section Intro, Recursion and Backtracking

Section 12: Recursion and Backtracking

Recursion is a function calling itself on a smaller version of the same problem. Backtracking is recursion with an undo step: build a solution piece by piece, and when a choice leads to a dead end, undo it and try the next option. Together, these two techniques are the foundation for tree traversal, graph search, and dynamic programming, all of which are covered in C6.

This section receives the largest time allocation in the course for a deliberate reason: teaching recursion too quickly produces students who can recite the definition but cannot apply it to a new problem. The gap between “I understand recursion conceptually” and “I can write a recursive solution to a problem I have never seen” is where most freshers fail in interviews. This section closes that gap.

What We’ll Cover:

  1. The recursive mental model: how to think about recursion without tracing every call
  2. Anatomy of a recursive function: base case, recursive case, combining results
  3. Recursion complexity: why some recursive solutions are O(n) and others are O(2^n)
  4. The backtracking template: choose, explore, unchoose
  5. Generation problems: permutations, subsets, and combinations
  6. Pruning: cutting branches from the search tree to avoid wasted work

Where Recursion and Backtracking Connect to Other Sections:

Connection Section How It Applies
Merge Sort is recursive divide-and-conquer Section 9: Sorting Split, sort halves recursively, merge
Linked list operations can be recursive Section 11: Linked Lists Reverse, merge, and traverse recursively
Tree traversals are recursive by nature C6: Trees Inorder, preorder, postorder are all recursion
Graph DFS is recursion on adjacency lists C6: Graphs Explore neighbors recursively, mark visited
Dynamic programming optimizes overlapping recursion C6: DP Memoize recursive subproblems, or convert to iterative DP

<aside>

Mukul Raina | youtube.com/@mukulraina | linkedin.com/in/mukulraina

</aside>