ReviseAlgo Logo
MediumVery High Frequency25 min

Recursion

Master the recursive thinking model — base cases, recurrence, and the call stack.

Recursion solves a problem by breaking it into smaller instances of itself. Every recursive solution needs a base case and a recursive case.

Recursion

Patterns

Power: x^n (Divide & Conquer)

O(log n)Naive loop is O(n). Recursion halves the problem → O(log n).
Step-by-step1 / 3

Input stream

2
0
10
1

Invariant

Push work onto the stack; pop when the current token or base case resolves it.

Stacktop
myPow(2, 10)
half(2,5)

myPow(2, 10). Even: half(2,5)²

10 is even. Compute 2^5 once, square it.