Cs141 Home/Hwk1Soln

Cs141 Home | Cs141 Home | recent changes | Preferences

Showing revision 2
Difference (from revision 2 to revision 2) (minor diff)
(The revisions are identical or unavailable.)
1. Ordered from slowest growing to fastest growing:

1/n < 2100 < log log n < log2 n < n0.01 < ⌈ sqrt(n) ⌉ < 2log n < 6n log n < 4n3/2 < 22n

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:

n5 + 5n4 + 10n3 + 10n2 + 5n + 1 ≤ cn5.
Dividing both sides by n5, this is the same as
(n5 + 5n4 + 10n3 + 10n2 + 5n + 1)/n5 ≤ (cn5)/n5.
Simplifying, this is the same as
1 + 5/n + 10/(n2) + 10/(n3) + 5/(n4) + 1/(n5) ≤ c.

The inequality holds when n=1 and c=32 (check).
All terms except 1 on the left side are decreasing functions of n.
Therefore when n ≥ n0 = 1, c = 32, the inequality holds. This completes the proof.

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).


Cs141 Home | Cs141 Home | recent changes | Preferences
This page is read-only | View other revisions | View current revision
Edited January 31, 2005 2:38 pm by Neal (diff)
Search: