CMPT 125 Lecture 7: L7 P3

34 views3 pages

Document Summary

If the array is dynamic, this can be expensive. For example, if we need to insert new values into the array. Homework: write a recursive version of binary search. On the other hand, the running time of fib using an array is o(n). Exponential time. because t(n) is equal to t(n-1) + t(n-2) + o(1). T(n) > 2*t(n-2) + o(1) multiply by 2, subtract 2, add 1. > 8t(n-6) multiply by 2(t)*(n-(subtract by 2)) multiply by 2, subtract by 2. How many iterations are performed in the following for loop? for (int i = 1 ; i < n ; i = i*2) { T(n/2) running time cut in half. sum = sum+i; # of times we divide n by 2 ---> o(log(n)) = logv2(n) logv2(n) ---> # of times needed to multiply by 2 to get to n. Express the run time of the following program using big-o notation. foo(int n) { if (n > 1)

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents

Related Questions