The document introduces the Fibonacci sequence and algorithms for computing Fibonacci numbers. It shows that a naive recursive algorithm is very slow. A new algorithm called FibList is presented that pre-computes the Fibonacci numbers up to the desired index n in an array, running in linear time O(n) and polynomial time complexity. This improved algorithm demonstrates how the choice of algorithm can dramatically impact performance.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
24 views14 pages
1 Intro 2 Fibonaccinumbers3
The document introduces the Fibonacci sequence and algorithms for computing Fibonacci numbers. It shows that a naive recursive algorithm is very slow. A new algorithm called FibList is presented that pre-computes the Fibonacci numbers up to the desired index n in an array, running in linear time O(n) and polynomial time complexity. This improved algorithm demonstrates how the choice of algorithm can dramatically impact performance.
0, 1, 1, 2, 3, 5, 8 0+1=1 1+1=2 1+2=3 2+3=5 3+5=8 New Algorithm FibList(n) create an array F [0 . . . n] F [0] 0 F [1] 1 for i from 2 to n: F [i] F [i 1] + F [i 2] return F [n] New Algorithm FibList(n) create an array F [0 . . . n] F [0] 0 F [1] 1 for i from 2 to n: F [i] F [i 1] + F [i 2] return F [n]
T (n) = 2n + 2. So T (100) = 202.
Easy to compute. Summary Introduced Fibonacci numbers. Naive algorithm takes ridiculously long time on small examples. Improved algorithm incredibly fast. Summary Introduced Fibonacci numbers. Naive algorithm takes ridiculously long time on small examples. Improved algorithm incredibly fast.