Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Yarde
Problem I. Algorithm demands 23n^3 operations for input size n. a) How many operations per second would computer have to do to complete an input of size 100 in 10 minutes?
10 min = 600 sec 1 min = 60 secs f(n) = 23n^2 about 383.3333... f(100) = 23(100^2) = 230,000
b) Assume computer does 50,000 operations in a second. What is the largest input that can be done in an hour?
Problem II. Assume you run a program on a computer doing 100 operations in a second. The algorithm does 3^n+2000 operations for input n. a) How many hours will it take computer to do input of size n =10?
3^n +2000
61049/100 = 610.49 = 10+ min 5 hr = 300 min = 18,000 sec 18,000 sec = 3^n + 2000 16,000 = 3^n 18,000 2000 = 16,000 n = 8.8 approx
Problem III. Algorithm that works 50n^3 and input of size n = 2000. a) If implemented on computer that does 1,000,000 op/sec, how long would it take in days?
f(n) = 50n^3
b) How many operations per second would computer have to do if you wanted it to be done in 30 days? Lakeisha S. Yarde Algorithms Homework #2
864,000 sec/day = 25,920,000 50n^3 = 2592 * 10^4 calculator and estimated n. n^3 = 518,400 n = 80.3 Note: I did cubic division and got an approximation. I plugged that value into a
2.3-1: Using figure 2.4, illustrate merge sort on A= {3, 41, 52, 26, 38, 57, 9, 49} 3 3 41 3 26 41 52 3 9 26 38 41 49 52 57 41 52 26 52 26 38 38 57 9 38 49 57 57 9 9 49 49
2.3-4: Recurrence for the running time of recursive version of insertion sort for A[1...n]
T(1) = 1
2.3-5: Pseudo-code of binary search algorithm recursively. recursivebinarysearch(A, v, low, high) if low > high return NIL mid = (low + high)/2 if v == A[mid] return mid else if v > A[mid] return recursivebinarysearch(A, v, mid+1, high) return recursivebinarysearch(A, v, low, mid-1) 3-1.3: Explain why stating the running time of algorithm A is at least O(n^2) is meaningless.
If we let the running time be T(n). Then T(n) O(n^2) implies T(n) f(n) in O(n^2) for all n in O(n^2). It's constant at least but does not give us any insight to the time. Algorithms Homework #2
Lakeisha S. Yarde
Yes. Since 0 f(n) c * g(n) for all n n0 , if c = 2 and n0 = 1 we can say: 2^n+1 = 2* 2^n for all n. 0 2^n+1 c* 2^n for all n n0
And for 2^2n = O(2^n), 2^2n = 2^n * 2^n c* 2^n which becomes 2^n c. There isn't a constant c that can be greater than 2^n. So, no, it isn't true.
o(g(n)) = 0 f(n) < c*g(n) while (g(n)) = 0 c*g(n) < f(n) The intersection cannot be both less than and greater than the function f(n).
Problem 3-3: Ordering by asymptotic growth rates - 2^2n+1 > 2^2n > (n+1)! > n! > 2^n > n lg n > n^3 > ln n > 2^lg n > lg*n
Lakeisha S. Yarde
Algorithms Homework #2