in reply to a better fibonacci subroutine
Call Number of calls Calls fib(1) 0 Internal fib(2) 0 Internal fib(3) 2 fib(2), fib(1) fib(4) 4 fib(3), [fib(2), fib(1)], fib(2) fib(5) 6 fib(4)[4]... fib(3)[2]... fib(6) 10 fib(5)[6]... fib(4)[4]... fib(7) 16 fib(6)[10]... fib(5)[6]... fib(8) 26 fib(7)[16]... fib(6)[10]...While this DOES demonstrate recursion, it can consume resources. Being a bit of an 'old school' type programmer who grew up with machines with limited resources using an iterative solution is perfered (to me!).
|
---|