Runtime blow-up of recursive Fibonacci
Question
A plain recursive routine for the Fibonacci numbers, , needs seconds to compute for some large . Roughly how long will it take for , and how could you compute Fibonacci numbers faster?
Short answer
About seconds. The run time grows like , i.e. by the golden ratio per step, so s. Iterating from the bottom up (keeping the last two values) takes , and matrix powering or fast doubling takes operations.
Adapted from Zhou, A Practical Guide to Quantitative Finance Interviews, sec. 7.1 Algorithms, 'Fibonacci numbers', p.178; question and answer rewritten by SelfMadeQuant.com.
See the hint and the full worked solution in the question bank (free account).
Open the worked solution