Professional Documents
Culture Documents
Unity ID :
Problem
1 10 points
2 8 points
3 11 points
4 10 points
5 11 +1 points
50+1 points
Score
Name:
Problem 1. (12 points) Prove rigorously (ie give values for c and n0 that will make your
argument work, and justify the values) each of the following statements using the formal
definitions of O, , and . Warning: testing individual values for n is NOT a proof.
a) (5 points)
1. nlg(n) + sqrt(n) + n-1 O( nlg(n) ) : 0 < nlg(n) + sqrt(n) + n-1 < 3 nlg(n) for n > 2 since
n < nlg(n) for n > 2, sqrt(n) ( < n ) < nlg(n) for n >2, and n-1 (< 1 <n) < nlg(n) for n >2
=> choose c=3, n0=2 to show the bigOh claim
2. nlg(n) + sqrt(n) + n-1 ( nlg(n) ) : 0 < nlg(n) < nlg(n) + sqrt(n) + n-1 for n > 1 since
n + sqrt(n) + n-1 > 0 for n > 1.
=> choose c=1, n0=1 to show the bigOmega claim
Since all terms are positive, the first inequality is fulfilled in both cases.
1 & 2 together results in nlg(n) + sqrt(n) + n-1 ( nlg(n) )
Name:
Problem 2. (8 +1 points) If it is not stated differently, give the asymptotic big-theta bound for
T(n) of each of the following recurrences. If not explicitly stated, please assume that small
instances need constant time c. If possible, use the Master Theorem. To receive full marks justify
your answers.
a) (4 points) T(n) = T(2n/3) + 1
Use Master Theorem: a=1, b=3/2, f(n)= 1, nlogba= n0 = 1. Since f(n) ( nlogba(=1)) Master
Theorem case 2 applies, and we get: T(n)= ( lg(n) ).
b) (4 points) Solve the recurrence T(n) = 2T( n-1 ) + 1 for n>1 ; T(1) = 1 exactly, i.e. compute
T(n) as a function of n. Show your work! Tip: use forward iteration.
T(1) = 1
T(2) = 2+1
T(3) = 4+2+1
T(4) = 8+4+2+1
T(n) = 2n-1+2n-2++1 = 2n - 1
Name:
Problem 3. (11 points)
Consider the following algorithm.
(1) s 1
(2) for i 1 to n do
(3)
if i is even then
(4)
for j 1 to 2 do
(5)
ss*2
(6)
else
(7)
ss*3
(8) return s
a) (5 points) For n = 1,2,3,4,5 what function values are returned in line 8? How many
multiplications (*) does the algorithm perform for these n values?
N
Return value
(s)
# multiplications
(*)
3*4
9*4
9*16
5
27*16
#Multiplica tions n n
s 3
( n 1) / 2
n / 2
Name:
Problem 4. (10 points)
a) (3 points) Consider the following recursive procedure:
F(n):
if n = 1 then
return 1
else
return F(n-1) + 2*F(n-1)
What value does F(n) return? Tip: start with computing some small instances.
F(n) = 3n-1
b) (4 points) Write down the recurrence for the running time T(n) of F.
T(n)
c) (3 points) How do the answers to (c) and (e) change if we replace the last line of F(n) by
return 3*F(n-1)
c) does not change, e) changes to T(n)
Name:
Problem 5 (11+1 points). Mark the correct answer (T: true, F: false). Beware of guessing:
correct answer +1.5pt. incorrect answer -.5pt. no answer 0pts.
a) [ T F ]
b) [ T F ]
c) [ T F ]
2n+400000 (2n)
d) [ T F ]
2n+400000 (2n)
e) [ T F ]
2n+400000 (2n)
g) [ T F ]
for __________________________ .
See lecture 2 page 11.
Name: