This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: – n 7 = n 6 + n 5 + 1 = 25 + 15 + 1 = 41 – n 8 = n 7 + n 6 + 1 = 41 + 25 + 1 = 67 . • Note that n k more than doubles for every other value of n k . That is, n k > 2 k/2 . It increases exponentially! Last Updated 120124 10:12 AM CSE 2011 Prof. J. Elder  34  A Better Fibonacci Algorithm • Use linear recursion instead: Algorithm LinearFibonacci( k ): Input: A positive integer k Output: Pair of Fibonacci numbers ( F k , F k1 ) if k = 1 then return ( k, 0) else ( i, j ) = LinearFibonacci( k  1) return ( i + j, i ) • Runs in O ( k ) time. Last Updated 120124 10:12 AM CSE 2011 Prof. J. Elder  35  Binary Recursion • Second Example: The Tower of Hanoi...
View
Full Document
 Fall '11
 Elder
 Data Structures, Recursion, Fibonacci number, National secondary road, Golden ratio, Prof. J., Prof. J. Elder, Recursion Fibonacci Algorithm

Click to edit the document details