1 min readMay 10, 2022
There are a few issues with recursion.
- It appears more intuitive, but sometimes isn’t. IMO, more complicated than necessary for a binary search.
- Basic recursive approach is easy when the number exists, but when the number doesn’t exist, how does a recursive approach find the next smallest number? A lot of interviewers get tripped up on that. You end up with a less beautiful recursive function call.
- A lot of developers forget to write the helper function.
- They also end up writing preconditions twice. Once in the helper function and one more time in the recursive functions.
- Suppose the array has a trillion numbers, recursion uses a lot of stack space which is not necessary with an iterative solution.
- The recursive solution is more lines of code for the purpose of a one hour long interview.
I find the iterative solution gives me fairly good hire/no-hire signals, without the candidate getting tripped up by recursion.