As an example of tree recursion, the Fibonacci series points out the disadvantages: although it is a classic example of tree recursion, It is very bad to use recursion to find the Fibonacci number. This is because excessive redundant computing is generated. (See page 25th of the translated book)
Li Yang of the toplanguage group said: in the coding horror section handed down in the code book, the author stressed that it is not necessary to use recursion to calculate the factorial or Fibonacci series, because this usage is slow, the memory usage is unpredictable and the readability is poor.
In the toplanguage group, I only dive. In actual situations, I tested ironscheme interpreter, JavaScript console, and C #2005 compiler. The test process is to test the Fibonacci number, and the test value is getting bigger and bigger.
Result: The javascript console was the first to exit. The ironscheme interpreter is slower than the C #2005 compiler. This is no way-the compilation is faster than the explanation, rather than the "optimize compilation" of tail recursion.
The following is the Fibonacci series program written in javascript:
VaR fib = function (n) {If (n = 0) return 0; If (n = 1) return 1; else {return arguments. callee (n-1) + arguments. callee (n-2) ;}}var fibobj = fib (7); console. log (fibobj );