Recursion

Problem shape

Beginner
4
8
15
16
23
42
Core idea

Solve a problem by reducing it to smaller versions of itself.

Step 1 / 5
Problem shape
Current lesson

Recursion Lab

Recursion Beginner

Recursion

Welcome to the Recursion algorithm lab. Solve a problem by reducing it to smaller versions of itself. Use it when: Use for trees, divide and conquer, backtracking, and naturally nested structures. The time complexity is Depends on branches, and the space complexity is Call stack depth. The pseudocode is: solve(problem) if base case return answer return combine(solve(smaller problem)) As you practice, track the state that changes and the condition that makes the algorithm stop.

Time

Depends on branches

Space

Call stack depth

Pseudocode

solve(problem)
  if base case
    return answer
  return combine(solve(smaller problem))
Open deeper structure lesson
1.0x