recursion - How to determine how long a recursive fibonacci algorithm will take for larger values if I have the time for the smaller values? -


i have used time library , timed how long recursive algorithm takes calculate fib numbers 50. give number, there formula can use determine how long have potentially taken calculate fib(100)?

times smaller values:

fib(40): 0.316 sec fib(80): 2.3 years fib(100): ???  

this depends on algorithm in use. direct computation takes constant time. recursive computation without memoization exponential, base of phi. add memoization this, , drops logarithmic time.

the 1 fit data exponential time. doing basic math ...

(2.3 years / 0.316 sec) ** (1.0/40) gives base = 1.6181589... 

gee, @ that! less 1 part in 10^4 more phi!

let t(n) time compute fib(n). can support hypothesis that

t(n) = phi * t(n-1) therefore, t(100) = phi^(100-80) * t(80) 

i trust can finish here.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -