0% found this document useful (0 votes)
131 views4 pages

Partial Solutions To Exercises 2.2

The document contains solutions to exercises on analyzing the asymptotic complexity of algorithms. It analyzes functions and determines their Big O, Ω, and Θ notation. Key points analyzed include: - Common functions like n(n+1)/2 and their asymptotic bounds - The effects of constants and logarithmic factors on asymptotic complexity - Properties that must hold for functions to be part of a specific complexity class - How the complexity of multiple functions combined is determined by the dominant term - Proofs that certain assertions about complexity classes hold true based on their definitions

Uploaded by

Luhan Zhao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
131 views4 pages

Partial Solutions To Exercises 2.2

The document contains solutions to exercises on analyzing the asymptotic complexity of algorithms. It analyzes functions and determines their Big O, Ω, and Θ notation. Key points analyzed include: - Common functions like n(n+1)/2 and their asymptotic bounds - The effects of constants and logarithmic factors on asymptotic complexity - Properties that must hold for functions to be part of a specific complexity class - How the complexity of multiple functions combined is determined by the dominant term - Proofs that certain assertions about complexity classes hold true based on their definitions

Uploaded by

Luhan Zhao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Solutions to Exercises 2.

2
1. a. Since Cworst (n) = n, Cworst (n) ∈ Θ(n).

b. Since Cbest (n) = 1, Cbest (1) ∈ Θ(1).


p(n+1)
c. Since Cavg (n) = 2 + n(1 − p) = (1 − p2 )n + p
2 where 0 ≤ p ≤ 1,
Cavg (n) ∈ Θ(n).

2. n(n + 1)/2 ≈ n2 /2 is quadratic. Therefore

a. n(n + 1)/2 ∈ O(n3 ) is true. b. n(n + 1)/2 ∈ O(n2 ) is true.

c. n(n + 1)/2 ∈ Θ(n3 ) is false. d. n(n + 1)/2 ∈ Ω(n) is true.

3. a. Informally, (n2 + 1)10 ≈ (n2 )10 = n20 ∈ Θ(n20 ) Formally,


 2 10
(n2 +1)10 (n2 +1)10 n +1
 10
lim n20 = lim 2 10 = lim 2 == lim 1 + n12 = 1.
n→∞ n→∞ (n ) n→∞ n n→∞

Hence (n2 + 1)10 ∈ Θ(n20 ).

Note: An alternative proof can be based on the binomial formula and


the assertion of Exercise 6a.
√ √ √
b. Informally, 10n2 + 7n + 3 ≈ 10n2 = 10n ∈ Θ(n). Formally,



2 2
lim 10n n+7n+3 = lim 10n n+7n+3
2 = lim 10 + n7 + n32 = 10.
n→∞ n→∞ n→∞

Hence 10n2 + 7n + 3 ∈ Θ(n).

c. 2n lg(n + 2)2 + (n + 2)2 lg n2 = 2n2 lg(n + 2) + (n + 2)2 (lg n − 1) ∈


Θ(n lg n) + Θ(n2 lg n) = Θ(n2 lg n).

d. 2n+1 + 3n−1 = 2n 2 + 3n 31 ∈ Θ(2n ) + Θ(3n ) = Θ(3n ).

e. Informally, log2 n ≈ log2 n ∈ Θ(log n). Formally, by using the in-


equalities x − 1 < x ≤ x (see Appendix A), we obtain an upper bound
log2 n ≤ log2 n
and a lower bound
1 1
log2 n > log2 n − 1 ≥ log2 n − log2 n (for every n ≥ 4) = log2 n.
2 2
Hence log2 n ∈ Θ(log2 n) = Θ(log n).

11
4. a. The order of growth and the related notations O, Ω, and Θ deal with
the asymptotic behavior of functions as n goes to infinity. Therefore no
specific values of functions within a finite range of n’s values, suggestive
as they might be, can establish their orders of growth with mathematical
certainty.

b. lim log2 n
= lim(log2 n)
= lim n1 log2 e = log2 e lim 1
= 0.
n→∞ (n) 1

n→∞ n n→∞ n→∞ n
n 1
lim = lim = 0.
n→∞ n log2 n n→∞ log2 n
n log2 n log2 n
lim
n→∞ n2 = lim
n→∞ n = (see the first limit of this exercise) = 0.
2
lim nn3 = lim n1 = 0.
n→∞ n→∞
n3
3 ) 3n2 2 (n2 )
lim 2n = lim (n
(2n ) = lim n = ln32 n→∞
2 ln 2 lim 2nn = 3
lim (2
ln 2 n→∞ n
)
n→∞ n→∞ n→∞

(n)
= ln32 lim 2n2n 6
lim 2nn = ln62 2 lim (2
ln 2 = ln2 2 n→∞ n) 
n→∞ n→∞
= ln2 2 lim 2n ln 2 = ln3 2 lim 2n = 0.
6 1 6 1
n→∞ n→∞
2n
lim = (see Example 3 in the section) 0.
n→∞ n!

5. (n − 2)! ∈ Θ((n − 2)!), 5 lg(n + 100)10 = 50 lg(n + 100) ∈ Θ(log n), 2√2n =
(22 )n ∈ Θ(4n ), 0.001n4 + 3n3 + 1 ∈ Θ(n4 ), ln2 n ∈ Θ(log2 n), 3 n ∈
1
Θ(n 3 ), 3n ∈ Θ(3n ). The list of these functions ordered in increasing
order of growth looks as follows:

5 lg(n + 100)10 , ln2 n, 3 n, 0.001n4 + 3n3 + 1, 3n , 22n , (n − 2)!

k= lim a n +a k k k 1 nkk 1 +...+a0



k 1 + ... + a0 )
nk
p(n) − a −
6. a. lim = lim (ak + n
n→∞ n n→∞ n n→∞
= ak > 0.

Hence p(n) ∈ Θ(nk ).

b.

n  0 if a1 < a2 ⇔ an1 ∈ o(an2 )
an a1
lim 1n = lim = 1 if a1 = a2 ⇔ an1 ∈ Θ(an2 )
n→∞ a2 n→∞ a2 
∞ if a1 > a2 ⇔ an2 ∈ o(an1 )

7. a. The assertion should be correct because it states that if the order of


growth of t(n) is smaller than or equal to the order of growth of g(n), then

12
the order of growth of g(n) is larger than or equal to the order of growth
of t(n). The formal proof is immediate, too:

t(n) ≤ cg(n) for all n ≥ n0 , where c > 0,

implies
1
( )t(n) ≤ g(n) for all n ≥ n0 .
c

b. The assertion that Θ(αg(n)) = Θ(g(n)) should be true because αg(n)


and g(n) differ just by a positive constant multiple and, hence, by the
definition of Θ, must have the same order of growth. The formal proof
has to show that Θ(αg(n)) ⊆ Θ(g(n)) and Θ(g(n)) ⊆ Θ(αg(n)). Let
f (n) ∈ Θ(αg(n)); we’ll show that f (n) ∈ Θ(g(n)). Indeed,

f (n) ≤ cαg(n) for all n ≥ n0 (where c > 0)

can be rewritten as

f (n) ≤ c1 g(n) for all n ≥ n0 (where c1 = cα > 0),

i.e., f (n) ∈ Θ(g(n)).

Let now f (n) ∈ Θ(g(n)); we’ll show that f (n) ∈ Θ(αg(n)) for α > 0.
Indeed, if f (n) ∈ Θ(g(n)),

f (n) ≤ cg(n) for all n ≥ n0 (where c > 0)

and therefore
c c
f (n) ≤ ag(n) = c1 αg(n) for all n ≥ n0 (where c1 = > 0),
α α
i.e., f (n) ∈ Θ(αg(n)).

c. The assertion is obviously correct (similar to the assertion that a = b


if and only if a ≤ b and a ≥ b). The formal proof should show that
Θ(g(n)) ⊆ O(g(n)) ∩ Ω(g(n)) and that O(g(n)) ∩ Ω(g(n)) ⊆ Θ(g(n)),
which immediately follow from the definitions of O, Ω, and Θ.

d. The assertion is false. The following pair of functions can serve as


a counterexample
  2
 n if n is even  n if n is even
t(n) = and g(n) =
 2 
n if n is odd n if n is odd

13
8. a. We need to prove that if t1 (n) ∈ Ω(g1 (n)) and t2 (n) ∈ Ω(g2 (n)), then
t1 (n) + t2 (n) ∈ Ω(max{g1 (n), g2 (n)}).

Proof Since t1 (n) ∈ Ω(g1 (n)), there exist some positive constant c1
and some nonnegative integer n1 such that

t1 (n) ≥ c1 g1 (n) for all n ≥ n1 .

Since t2 (n) ∈ Ω(g2 (n)), there exist some positive constant c2 and some
nonnegative integer n2 such that

t2 (n) ≥ c2 g2 (n) for all n ≥ n2 .

Let us denote c = min{c1 , c2 } and consider n ≥ max{n1 , n2 } so that we


can use both inequalities. Adding the two inequalities above yields the
following:

t1 (n) + t2 (n) ≥ c1 g1 (n) + c2 g2 (n)


≥ cg1 (n) + cg2 (n) = c[g1 (n) + g2 (n)]
≥ c max{g1 (n), g2 (n)}.

Hence t1 (n) + t2 (n) ∈ Ω(max{g1 (n), g2 (n)}), with the constants c and
n0 required by the O definition being min{c1 , c2 } and max{n1 , n2 }, re-
spectively.

b. The proof follows immediately from the theorem proved in the text
(the O part), the assertion proved in part (a) of this exercise (the Ω part),
and the definition of Θ (see Exercise 7c).

9. a. Since the running time of the sorting part of the algorithm will still
dominate the running time of the second, it’s the former that will deter-
mine the time efficiency of the entire algorithm. Formally, it follows from
equality
Θ(n log n) + O(n) = Θ(n log n),
whose validity is easy to prove in the same manner as that of the section’s
theorem.

b. Since the second part of the algorithm will use no extra space, the
space efficiency class will be determined by that of the first (sorting) part.
Therefore, it will be in Θ(n).

10. The key idea here is to walk intermittently right and left going each time
exponentially farther from the initial position. A simple implementation
of this idea is to do the following until the door is reached: For i = 0, 1, ...,
make 2i steps to the right, return to the initial position, make 2i steps to

14

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy