Anda di halaman 1dari 3

Technische Universitat M

unchen
Fakultat f
ur Informatik
Lehrstuhl f
ur Effiziente Algorithmen
Prof. Dr. Harald Racke
Chintan Shah

Wintersemester 2012
Losungsblatt 1
9 November 2012

Effiziente Algorithmen und Datenstrukturen I


Aufgabe 1 (10 Punkte)
Prove the following statements:
1. f (n) + g(n) (f (n))
2. f (n) O(g(n)) f (n) + g(n) O(g(n))
3. f (n) o(g(n)) and g(n) O(h(n)) h(n) (f (n))
4. f (n) O(g(n)) and g(n) O(f (n)) f (n) (g(n))
State whether the following statement is true:
1.

1
(n)

O( n1 )

L
osungsvorschlag
1. f (n) + g(n) (f (n))
Taking c = 1 and n0 = 1, we get
n n0 , c f (n) = f (n) f (n) + g(n)
2. f (n) O(g(n)) f (n) + g(n) O(g(n))
f (n) O(g(n)) c > 0 and n0 > 0 such that n n0 , f (n) c g(n)
n n0 , f (n) + g(n) (c + 1) g(n)
Taking c0 = c + 1 > 0 and n00 = n0 , we get n n00 , f (n) + g(n) c0 g(n).
3. f (n) o(g(n)) and g(n) O(h(n)) h(n) (f (n))
f (n) o(g(n)) c1 > 0, n1 > 0 such that f (n) < c1 g(n)n n1
g(n) O(h(n)) c2 > 0, n2 > 0 such that g(n) c2 h(n)n n2

We wish to prove that c0 > 0, n0 > 0, such that c0 f (n) < h(n).
Given c0 , choose c1 = c01c2 . Then, for n n0 = max{n1 , n2 },
c0 f (n) =

f (n)
c1 g(n)
g(n)
c2 h(n)
<
=

= h(n)
c1 c2
c1 c2
c2
c2

4. f (n) O(g(n)) and g(n) O(f (n)) f (n) (g(n))


(a) f (n) O(g(n)) and g(n) O(f (n)) f (n) (g(n))
f (n) O(g(n)) c1 > 0 and n1 > 0 such that n n1 , f (n) c1 g(n)
g(n) O(f (n)) c2 > 0 and n2 > 0 such that n n2 , g(n) c2 f (n)

Then, taking c3 =

1
, c4
c2

= c1 and n0 = max{n1 , n2 }, we get n n0 ,


c3 g(n) f (n) c4 g(n).

(b) f (n) (g(n)) f (n) O(g(n)) and g(n) O(f (n))


f (n) (g(n)) n0 , c3 , c4 , such that n n0 , c3 g(n) f (n) c4 g(n).
Taking c2 = c13 and c1 = c4 , we get
n n0 , f (n) c1 g(n) f (n) O(g(n))
n n0 , g(n) c2 f (n) g(n) O(f (n))

5.

1
(n)

O( n1 )

True.
Let f (n) (n). We will show that

1
f (n)

1
n

f (n)

n n
n
<
0 lim
n f (n)
1/f (n)
0 lim
<
n 1/n
 
1
1

O
f (n)
n

f (n) (n) 0 < lim

Aufgabe 2 (10 Punkte)


For constants c,  > 0 and k > 1, arrange the following functions of n in non-decreasing
asymptotic order so that fi (n) = O(fi+1 (n)) for two consecutive functions in your
sequence. Also indicate whether fi (n) = (fi+1 (n)) holds or not.

nk , n, 2n , n1+sin(n) , log(n!), nk+ , nn , n, nk (log n)c , n!, n log n, 3n , n log log n, n log(n2 )
Lo
sungsvorschlag

n o(n) o(n log log n) o(n log n) (n log(n2 )) (log(n!)) o(nk )


o(nk (log n)c ) o(nk+ ) o(2n ) o(3n ) o(n!) o(nn )
n0 O(n1+sin(n) ) O(n2 )

Aufgabe 3 (10 Punkte)


Let f (n) and g(n) be asymptotically non-negative functions. Using the basic definition of
-notation, prove that max{f (n), g(n)} = (f (n) + g(n)).
Lo
sungsvorschlag
Let h(n) = max {f (n), g(n)}. Then,
(
f (n), if f (n) g(n),
h(n) =
g(n), if f (n) < g(n).
We show that c1 , c2 , n0 > 0 such that
c1 (f (n) + g(n)) max {f (n), g(n)} c2 (f (n) + g(n)), n n0 .

(1)

Since f (n) and g(n) are asymptotically non-negative, n0 > 0 such that f (n) 0 and
g(n) 0 n n0 . Thus, for n n0 , f (n) + g(n) f (n) 0 and f (n) + g(n) g(n) 0.
Since for any particular n, h(n) is either f (n) or g(n), we have f (n) + g(n) h(n) 0,
which shows that h(n) = max {f (n), g(n)} c2 (f (n) + g(n)) n n0 for c2 = 1.
Similarly, since for any particular n, h(n) is the larger of f (n) and g(n), we have
n n0 , 0 f (n) h(n) and 0 g(n) h(n). Adding these two inequalities
h(n), which shows that
gives us 0 f (n) + g(n) 2h(n), or 0 (f (n)+g(n))
2
h(n) = max {f (n), g(n)} c1 (f (n) + g(n)) n n0 for c1 = 12 .

Aufgabe 4 (10 Punkte)


Show that for any real constants a and b, where b > 0,
(n + a)b = (nb )
Lo
sungsvorschlag
Observe that
n + a n + |a| 2n when |a| n.
Also, n + a n |a| 21 n when |a| n2 .
So, when 2|a| n, we have
0

So taking c1 =

 n b
n
n + a 2n 0
(n + a)b (2n)b , since b > 0
2
2
 b
1
0
nb (n + a)b 2b nb
2

1 b
,
2

c2 = 2b and n0 = 2|a| satisfies the definition.

Anda mungkin juga menyukai