LESSON 07 / 75·2 min readIntermediate

Recursion and backtracking

Must knowConcept lesson
01 Understand02 Recall03 Prepare

Recursion

A function calls itself to solve smaller subproblems.

Problems to practice

  • Fibonacci
  • Factorial
  • Tower of Hanoi
  • Binary tree traversal
  • permutations
  • subsets
  • combinations
  • N-Queens
  • Sudoku solver

Backtracking

Try a choice, recurse, then undo if it fails.

Example

Generate all subsets or permutations by exploring choices and removing the last choice when it does not work.

Important considerations

Always have a base case and avoid infinite recursion.


PAUSE & RECALL

Can you explain it without the notes?

Recursion and backtracking

Use your own words. Explain an example and one limitation before checking the explanation.

Check your explanation

Recursion

CONNECT IT TO YOUR INTERVIEW

Turn this concept into a clear answer.

Practice this concept
YOUR NEXT STEP

Keep connecting the ideas.

Next lesson: Trees and binary search trees

Adapted from 14_DSA_MASTER.md · “7. Recursion and backtracking”. Examples are study fragments; framework behavior can depend on your version.