Skip to main content
General

Recursion vs Iteration - when to use which in interviews?

Madhav MukherjeeMadhav Mukherjee
7/15/2025
175

I always default to recursion because it's easier to think about. But I've been told iterative solutions are preferred. Why?

  1. Stack overflow risk with deep recursion
  2. Space complexity - recursion uses O(n) stack space
  3. Performance - function call overhead

But recursion is:

  • Easier to code for trees/graphs
  • More readable for backtracking
  • Natural for divide and conquer

My approach: write recursion first, convert to iterative if the interviewer asks. Is this a good strategy?


recursioniterationinterview-tipsstrategy

Comments (8)

Sign in to join the discussion.
Katie Weber
Katie Weber11 months ago

I usually start with recursion during whiteboard interviews to get the logic down quickly. Then if time allows, I try converting to an iterative solution. It shows flexibility, I think.

Lavanya Bhatt
Lavanya Bhatt11 months ago

When you're under tight time constraints in an interview, recursion can be a lifesaver for quickly getting a working solution down. Just make sure to mention the limitations!

Aditi Malhotra
Aditi Malhotra8/29/2025

I totally feel you! Recursion often seems so straightforward. But in an interview setting, the concern about stack overflow is real, especially for deep problems. I guess it's all about showing you understand both methods.

Ritesh Pillai
Ritesh Pillai8/11/2025

I've noticed interviewers generally prefer iteration because it shows you can optimize for both space and time. But yeah, recursion is so elegant for complex tree structures!

Lakshay Desai
Lakshay Desai8/9/2025

Iterative solutions are generally more efficient, so I stick to them unless the problem is inherently recursive. I think interviewers appreciate seeing you handle potential memory issues upfront.

Vera Chen
Vera Chen8/7/2025

In my experience, some interviewers use recursion as a trap to see if you can recognize the limitations and suggest improvements. It’s like a test within a test!

Akshay Pillai
Akshay Pillai8/5/2025

Recursion feels more intuitive for me especially in DFS or backtracking problems. But yeah, knowing when and how to convert to iteration is a key skill for interviews.

Raghav Ahuja
Raghav Ahuja7/20/2025

I think starting with recursion is fine as long as you can quickly pivot to iteration if asked. It shows you’re adaptable and can handle the situation.