0
Interview trivial: Computing factorial with Recursion ?
Why do recruiters think to rarely or maybe never hire a developer who computes the factorial using Recursion?
4 Respostas
+ 15
Recursion consumes a lot of memory and can easily overflow the method call stack. Using a for loop to sum it up is at least less memory-intensive, if not faster.
+ 11
You can test out a live example of what Tamra said. Iteration for 10000000 loops is fine, but recursing for the similar amount may even crash as a desktop compiled .exe.
+ 1
i hate recursion anyway
0
Depends on the project you're being interviewed for. A good understanding of recursion (writing Tail Call Optimizable Code) is imperative when using a functional language such as Clojure, F# or Haskell.
OO languages generally do not provide TCO which means a recursive solution, even one which could benefit from TCO, has the potential to blow up the stack.
As for interviewers\recruiters passing up on people using recursion. Either they themselves are unfamiliar with recursion thus unable to ask questions about pros and cons of the solution or the candidate is unable to explain what his solution is and isn't good for.