• Keine Ergebnisse gefunden

Discrete Mathematics 2. Exercise Sheet

N/A
N/A
Protected

Academic year: 2022

Aktie "Discrete Mathematics 2. Exercise Sheet"

Copied!
3
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Algorithmic

Discrete Mathematics 2. Exercise Sheet

Department of Mathematics SS 2012

PD Dr. Ulf Lorenz 2. and 3. May 2012

Dipl.-Math. David Meffert Version of April 26, 2012

Groupwork

Exercise G1 (Master-Theorem)

Determine, if possible, fixed bounds for the complexities of the recurrences (a) T(n) =4T(n2) +n3,

(b) T(n) =4T(n2) +n, (c) T(n) =4T(n2) +n2logn, (d) T(n) =4T(n2) +n2. Hint:

Exercise G2 (Complexity)

(a) Let f,t:N→Rbe functions with fO(t). ProveO(f) +O(t)⊆O(t)andO(f) +O(f)⊆O(t). (b) Does33+nO(3n)hold?

(c) Does33nO(3n)hold?

(d) Show thatO(fO(g) =O(f ·g)holds for f,g:N→R+.

Remark: For real valued functions f,g:N →R one just substitutes f(n), g(n)with|f(n)|,|g(n)|in the definition of O(g).

Exercise G3 (Algorithms)

(a) Given two algorithmsAandB:

• AlgorithmAhas complexityO(f).

• AlgorithmBhas complexityO(g).

We want to look at two new algorithms usingAandB.

1

(2)

Algorithm 1 INPUT :n∈N fori=1, ..., 100do

run algorithm A end for

fori=1, ...,n

2 do run algorithm B end for

Algorithm 2 if n≥30then

run algorithm A else

run algorithmus B end if

We already knowf ∈Ω(g). Determine the best possible estimates for the runtime of both algorithms.

(b) Take a look at algorithm3and determine the best possible estimate for its runtime. Justify you answer.

Algorithm 3 INPUT : n∈N m = n

whilem > 1do forj = 1,...,n

2do a=3·b c = a +b end for m =12·m end while

Exercise G4 (Sets) Order the functions

n2,p

n,n!,nn,n

by their complexity. Start with lowest complexity and use theo-notation. Determinen0dependend onc>0in every of those cases, too.

Remark:

fo(g):⇐⇒ ∀c>0∃n0∈N∀nn0: 0≤f(n)<c g(n)

Homework

Exercise H4 (Asymptotics) (14 points)

(a) Prove that forr1,r2∈R+we havenr1O(nr2)andr1nO(r2n)iffr1r2. (b) Prove the following statements for functions f,t:N→R:

i. O(f) +O(f)⊆O(f).

ii. O(fO(t)⊆O(f ·t).

iii. max{f,t} ∈Θ(f +t)for f,t≥0.

Exercise H5 (A sorting algorithm) (10 points)

The algorithmSortListsorts a sequence of numbers in ascending order.

2

(3)

Algorithm 4SortList(list)

INPUT: sequence of numbers,list=a1, ...,an,ai∈N ifn <=1then

returnlist else

leftlist=a1, ...,adn

2e

rightlist=adn

2e+1, ...,an

return Sort(SortList(lelftlist),SortList(rightlist)) end if

Algorithm 5Sort(rightlist,leftlist) INPUT: two sequences of numbers:

rightlist=a1, ...,al,leftlist=b1, ...,bk,ai,bi∈N newlist

whilerightlistandleftlistnot emptydo

iffirst element ofleftlist<= first element ofrightlistthen

append first element ofleftlisttonewlistand delete it fromleftlist else

append first element ofrightlisttonewlistand delete it fromrightlist end if

end while

whileleftlistnot emptydo

append first element ofleftlisttonewlistand delete it fromleftlist end while

whilerightlistnot emptydo

append first element ofrightlisttonewlistand delete it fromleftlist end while

returnnewlist

(a) Sort the sequence9, 10, 7, 3, 1, 2, 12, 9, 23in ascending order by using the algorithmSortList. Make sure to include detailed steps for the algorithm in your solution to indicate that you understand how it works.

(b) What is the runtime of the algorithmSortList?

Exercise H6 (6 points)

Given algorithm 6. What does the algorithm? Determine its runtime.

Algorithm 6 INPUT :n∈N K1 = 2;

K2 = n;

whileK2 > K1do K2 = n/K1

ifdK2e==K2then return K1 else

K1=K1+1 end if end while return 0

3

Referenzen

ÄHNLICHE DOKUMENTE

They describe the number of possibilities to choose k objects from a given set containing n objects (without putting objects back and without respecting the order of the

The capacities on the edges should be natural numbers and the maximal flow x from s to t is given... Let s be the source in this graph and t

They describe the number of possibilities to choose k objects from a given set containing n objects (without putting objects back and without respecting the order of the

Make sure to include detailed steps for the algorithm in your solution to indicate that you understand how it works. (b) What is the runtime of the

Now keep on following the cycle C till the first node v 1 ∈ V 0 \{ V 1 } .We repeat this procedure till we went through the whole cycle C and get to the starting vertex v

Now reduce the flow on the whole path P 1 ( u, v ) P 2 by 1, so the general flow for the graph is valid again, with a maximal flow reduced by 1.. It could be the case now that this

As solving this problem exactly is time-consuming, a greedy evaluation procedure is used for approximating the quality of intermediate leader solution candidates, which is described

Users of the PACE TR-48 Analog Computer will find the High Speed Repetitive Operation Group a· valuable aid in the solution of a variety of computing