2.
1 Hour | 2 Hours | |
log n | 236*108 | 272*108 |
sqrt(n) | 1296*1019 | 5184*1019 |
n | 36*108 | 72*108 |
n log n | 1.33*108 | 2.58*108 |
n2 | 60000 | 8.49*104 |
n3 | 1532.62 | 1930.98 |
2n | 31 | 32 |
n! | 12 | 13 |
3.
We want the following inequality to hold for a constant c when n ≥ n0:
4.
Algorithm (Input: X = (a1, a2, a3,.. an), Output: A = (A1, A2, ..., An)
1. A[1] = X[1]
2. print A[1]
3. for i=2 to n
4. ___ A[i] = A[i-1] + X[i]
5. ___ print A[i]
6. end for
Complexity: The algorithm clearly runs in O(n) time.
Correctness: Clearly, A[i] = a[1] + a[2] + ... + a[i]. (prove by induction on i if you want to be formal).