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?

4th Apr 2017, 7:25 PM
Dimas Fajar
Dimas Fajar - avatar
4 ответов
+ 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.
4th Apr 2017, 7:43 PM
Tamra
Tamra - avatar
+ 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.
4th Apr 2017, 10:59 PM
Hatsy Rei
Hatsy Rei - avatar
+ 1
i hate recursion anyway
4th Apr 2017, 8:30 PM
Edward
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.
22nd Jun 2018, 10:43 PM
Ahmed Saeed
Ahmed Saeed - avatar