Docsity

Solutions to Exercise Set 2 for Computer Algorithms I | MCS 401, Study notes of Algorithms and Programming

Toggle sidebar
bg1
Solutions to CS / MCS 401 Exercise Set #2 (Spring 2008)
Exercise 3.1-4 (page 50)
limn→∞ 2n+1 / 2n = limn→∞ 2 = 2, so 2n+1 = O(2n).
limn→∞ 22n / 2n = limn→∞ 2n = ∞, so 22n ≠ O(2n).
Exercise 3.2-6 (page 57)
We prove by induction on i that Fi = (ϕi + ϕ
∧)i/√⎯5.
If i = 0, (ϕi − ϕ
∧i)/√⎯5 = (1 − 1)/√⎯5 = 0 = F0.
If i = 1, (ϕi − ϕ
∧i)/√⎯5 = ( (1 + √⎯5 )/2 − (1 − √⎯5 )/2) /√⎯5 = 1 = F1.
Now assume i ≥ 2, and that the result holds for all k with k < i. Recall ϕ and ϕ
∧ are the roots of
x2 − x − 1 = 0. Thus ϕ2 = ϕ + 1 and ϕ
∧2 = ϕ
∧ + 1. Multiplying by ϕi−2 gives ϕi = ϕi−1 + ϕi−2 and
ϕ
∧i = ϕ
∧i−1 + ϕi−2 for all i ≥ 2.
Fi = Fi−1 + Fi−2 = (ϕi−1 − ϕ
∧i−1)/√⎯5 + (ϕi−2 − ϕ
∧i−2)/√⎯5 (inductive hypothesis)
= (ϕi−1 + ϕi−2)/√⎯5 − ( ϕ
∧i−1 + ϕ
∧i−2)/√⎯5
= ϕi/√⎯5 − ϕ
∧i/√⎯5
= (ϕi − ϕ
∧i)/√⎯5
So the result holds for i.
Exercise 3-2 (pages 57-58)
A B O o Ω ω Θ Notes
lgk(n) nε yes yes no no no
Polynomials dominate logarithms.
nk cn yes yes no no no
Exponentials dominate polynomials.
sqrt(n) nsin(n) no no no no no
nsin(n) oscillates in (1/n,n). There are
arbitrarily large values for n for
which nsin(n) < 1, and arbitrarily large
n for which nsin(n) > n0.75. For any
positive constants c1 and c2, there
exist arbitrarily large values of n with
sqrt(n) / nsin(n) < c1, and arbitrarily
large n with sqrt(n) / nsin(n) > c2
.
2n 2n/2 no no yes yes no
limn→∞ 2n / 2n/2
= lim n→∞ 2n/2 = ∞.
nlg(c) clg(n) yes no yes no yes
We showed in class that nlg(c) = clg(n).
lg(n!) lg(nn) yes no yes no yes
lg(nn) = nlg(n), and lg(n!) ≈
nlg(n) – 1.44n by Stirling’s formula.
pf3

Partial preview of the text

Download Solutions to Exercise Set 2 for Computer Algorithms I | MCS 401 and more Study notes Algorithms and Programming in PDF only on Docsity!

Solutions to CS / MCS 401 Exercise Set #2 (Spring 2008)

Exercise 3.1-4 (page 50)

lim n →∞ 2 n +1^ / 2 n^ = lim n →∞ 2 = 2, so 2 n +1^ = O(2 n ).

lim n →∞ 2 2 n^ / 2 n^ = lim n →∞ 2 n^ = ∞, so 2 2 n^ ≠ O(2 n ).

Exercise 3.2-6 (page 57)

We prove by induction on i that Fi = (ϕ i^ + ϕ∧^ ) i^ /√⎯5.

If i = 0, (ϕ i^ − ϕ∧^ i^ ) /√⎯5 = (1 − 1) /√⎯5 = 0 = F 0.

If i = 1, (ϕ i^ − ϕ∧^ i^ ) /√⎯5 = ( ( 1 + √⎯ 5 )/ 2 − ( 1 − √⎯ 5 )/ 2 ) /√⎯5 = 1 = F 1.

Now assume i ≥ 2, and that the result holds for all k with k < i. Recall ϕ and ϕ∧^ are the roots of x^2 − x − 1 = 0. Thus ϕ^2 = ϕ + 1 and ϕ∧^2 = ϕ∧^ + 1. Multiplying by ϕ i −^2 gives ϕ i^ = ϕ i −^1 + ϕ i −^2 and ϕ∧^ i^ = ϕ∧^ i −^1 + ϕ i −^2 for all i ≥ 2.

F i = F i − 1 + F i − 2 = (ϕ i −^1 − ϕ∧^ i −^1 ) /√⎯5 + (ϕ i −^2 − ϕ∧^ i −^2 ) /√⎯ 5 (inductive hypothesis)

= (ϕ i −^1 + ϕ i −^2 ) /√⎯ 5 − ( ϕ∧^ i −^1 + ϕ∧^ i −^2 ) /√⎯ 5

= ϕ i^ /√⎯ 5 − ϕ∧^ i^ /√⎯ 5

= (ϕ i^ − ϕ∧^ i^ ) /√⎯ 5

So the result holds for i.

Exercise 3-2 (pages 57-58)

A B O o Ω ω Θ Notes lg k ( n ) nε^ yes yes no no no Polynomials dominate logarithms. n k^ c n^ yes yes no no no Exponentials dominate polynomials.

sqrt( n ) n sin( n )^ no no no no no

n sin( n )^ oscillates in (1/ n , n ). There are arbitrarily large values for n for which n sin( n )^ < 1, and arbitrarily large n for which n sin( n )^ > n 0.75^. For any positive constants c 1 and c 2 , there exist arbitrarily large values of n with sqrt( n ) / n sin( n )^ < c 1 , and arbitrarily large n with sqrt( n ) / n sin( n )^ > c 2. 2 n^ 2 n /2^ no no yes yes no lim^ n →∞ 2 n^ / 2 n /2^ = lim^ n →∞ 2 n /2^ =^ ∞. n lg( c )^ c lg( n )^ yes^ no^ yes^ no^ yes^ We showed in class that^ n lg( c )^ =^ c lg( n )^. lg( n !) lg( n n ) yes no yes no yes lg( n^ n ) = n lg( n ), and lg( n !) ≈ n lg( n ) – 1.44 n by Stirling’s formula.

Exercise 3-3 (pages 57-58), part (a) 2 2 n + 2 2 n ( n +1)! n! Note n! ≈ ( n / e ) n^ sqrt(2π n ) grows more rapidly than α n , α fixed. en n ⋅ 2 n 2 n (3/2) n n lg lg( n ), (lg( n ))lg( n )^ Note (lg( n )) lg( n )^ = 2 lg lg( n ) lg( n )^ = 2 lg( n ) lg lg( n )^ = n lg lg( n )^. (lg( n ))! Note (lg( n ))! ≈ (lg( n )/ e ) lg( n )^ sqrt(2πlg( n )) = n lg lg( n )^ / n lg( e )^ Θ(sqrt(lg( n )) = n lg lg( n )−1.44Θ(sqrt(lg( n )). n^3 n^2 , 4 lg( n )^ Note 4 lg( n )^ = n lg(4)^ = n^2 by the general rule a log b ( c )= c log b ( a ). n lg( n ), lg( n !) Note lg(n!) ≈ n lg( n ) − 1.44 n n , 2 lg( n ) (sqrt(2))lg( n )^ Note (sqrt(2))lg( n )^ = n lg(sqrt(2))^ = n 0. 2 sqrt(2 lg(n)) (lg( n ))^2 ln( n ) sqrt(lg( n )) ln ln n

1, n 1/lg( n )^ Note n 1/lg( n )^ = ( 2 lg( n )) 1/lg( n )^ = 2 1 = 2.

Exercise C

a) Recall that lim (^) n →∞ f ( n ) = lim (^) n →∞ g ( n ) = ∞. Note lim (^) n →∞ g ( n ) = ∞ implies ln( g ( n )) ≥ 1 for all n sufficently large. Note also f ( n ) = O( g ( n )) means that there exists a constant c such that f ( n ) ≤ c g ( n )) for all n sufficiently large. Increasing c if necessary, we may assume c ≥ 1 and hence ln( c ) > 0. Thus for all n sufficiently large, f ( n ) ≤ c g ( n )) ⇒ ln( f ( n )) ≤ ln( cg ( n )) Since ln ( x ) in an increasing function. ⇒ ln( f ( n )) ≤ ln( c ) + ln( g ( n )) ⇒ ln( f ( n )) ≤ ln( c )ln( g ( n )) + ln( g ( n )) Since ln (c) > 0 and ln ( g ( n ) ) ≥ 1. ⇒ ln( f ( n )) ≤ ( ln( c ) + 1) ln ( g ( n )) Since ln( c )+1 is constant, ln( f ( n )) = O( ln( g ( n ))).