DSA Interview Question

What is recursion?

Updated 2026-07-10 · Beginner friendly
Quick answer

Recursion is when a function calls itself to solve a smaller version of the same problem. Every recursive solution needs a base case that stops the calls, and a recursive case that moves toward that base case. Without a base case the function would call itself forever and crash with a stack overflow.

The two parts every recursion needs

def factorial(n):
    if n <= 1:        # base case
        return 1
    return n * factorial(n - 1)   # recursive case

factorial(4)  # 24

Each call waits on the call below it. The computer keeps track of these paused calls on the call stack, which is why very deep recursion can run out of memory.

In the interview

Always mention the base case first, because a missing base case is the most common bug. If asked about the downside, say recursion uses stack memory for each call and can hit a stack overflow, and that many recursions can be rewritten as loops.

Want the full DSA guide?

Read every DSA concept with notes, diagrams, and code in one place. Track your progress as you go.

Open the DSA guide All DSA questions