This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: Return F[n] B. How fast is Fib2? O(n) operations, linear. We’ve gone from exponential O(F n ) -> polynomial O(n). C. We’ve been careless in our runtime accounting. Adding numbers is not O(1) time if the numbers are arbitrarily large. F n ~ 1.6 n , ie O(n) bits long. Adding n-bit numbers takes O(n) time. D. Updated running times Fib: O(nF n ) exponential Fib2: O(n 2 ) polynomial Can we do better? A third algorithm a. Matrix vector form F = 0 F 1 1 F 1 = 0 1 F F 2 = 1 1 F 1 2 F 2 = 0 1 F F 3 = 1 1 F 1 So algorithm = n F n = 0 1 F F n+1 = 1 1 F 1 Time to compute F n is then the time to compute M n . We could compute M, M 2 , M 3 , M 4 , M 5 , … M n But there’s a much faster way repeated squaring M -> M 2 -> M 4-> M 8-> … -> M n Just O(log n) marix multiplications Multiplying n-bit numbers like O(n 2 ) time. Time to compute M n time to compute M n/2 one matrix multiplication T(n) = T(n/2) + O(n 2 )...
View Full Document
This note was uploaded on 01/09/2012 for the course CSE 101 taught by Professor Staff during the Spring '08 term at UCSD.
- Spring '08