Interview concept

What are recursion and backtracking?

Recursion solves a problem by calling itself on smaller inputs until a base case. Backtracking is recursion that tries a choice, explores further, and undoes the choice when it leads to a dead end.

Interview concept

How it works

Base case and recurrence

Define a clear base case and how each call reduces the problem toward it.

Backtracking template

Choose, explore, and un-choose, pruning branches that cannot lead to a valid solution.

When to use it

Reach for it on permutations, combinations, subsets, and constraint problems like N-Queens.

Interview concept

Responsible use

Use any live AI assistant only where interview, workplace, school, and platform rules allow it. Do not use generated answers to misrepresent your skills, experience, or authorship.

FAQ

Common questions.

What is the difference between recursion and backtracking?

Backtracking is a form of recursion that explores choices and undoes them, systematically searching a solution space with pruning.

How do I avoid stack overflow?

Ensure a reachable base case, bound recursion depth, and consider an iterative or memoized approach for deep recursion.