Expedia Interview Question
Software Engineer / Developerstradeoff:
recursive functions have a large overhead for function calls. This could lead to slower performance in some cases (eg. factorial). In such a case you'd be spending more time with function call overhead than actually doing the calculations. Iterative is normally faster and efficient, but could be complex to implement as you'd need to implement your own stack & store stuff on it etc.
Recursive is also tricky because it could lead to infinite recursion if you're not careful in making sure there's a base case that gets executed eventually.
This is interesting problem we used to solve in college time, Iterative approach is more efficient and faster than recursive approach which consumes a lot of memory and method calls.
- Dilip June 23, 2010