• Keine Ergebnisse gefunden

Algorithms & Data Structures Homework 5 HS 18 Exercise Class

N/A
N/A
Protected

Academic year: 2022

Aktie "Algorithms & Data Structures Homework 5 HS 18 Exercise Class"

Copied!
3
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Eidgen¨ossische

Technische Hochschule Z¨urich

Ecole polytechnique f´ed´erale de Zurich Politecnico federale di Zurigo

Federal Institute of Technology at Zurich

Departement of Computer Science 22. October 2018

Markus P¨uschel, David Steurer

Algorithms & Data Structures Homework 5 HS 18 Exercise Class

(Room & TA)

:

Submitted by:

Peer Feedback by:

Points:

Exercise 5.1 Big-ΘNotation(No bonus points).

1. For the following code fragment, count the number of times the functionfis invoked and express this inΘ-notation as concisely as possible. The functionfdoes not invoke itself.

for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) {

for(int k = j; k < n; k++) { f();

} } }

2. For the following code fragment, determine inΘ-notation the number of times the functionf is invoked. The functionfdoes not invoke itself.

for(int i = 1; i <= 2*n; i+=5) { for(int j = 1; j*j <= n; j++) {

f();

}

for(int k = 1; k*k < 1000; k = k+1) { f();

} }

Exercise 5.2 Relations between big-O,ΩandΘ(No bonus points).

1. Prove or disprove:Ω(n2)∩ O(n3) = Θ(n2)∪Θ(n3)

2. Is there a functionf :N→ R+that is neither inO(n2)nor inΩ(n2)? If no, prove, if yes, give an example.

3. Prove or disprove: Letf, g∈Θ(h), then|f−g| ∈ O(1).

4. Is there a non-constant functionf :N→R+withf ∈Θ(1)? If no, prove, if yes, give an example.

5. Prove or disprove: Letf ≤ O(g),g≤ O(h), andh≤ O(f). ThenΘ(f) = Θ(g) = Θ(h).

(2)

Exercise 5.3 Recurrence Relations(1 Point for Part 2).

For this exercise, assume thatnis a power of two, and that a and c are positive constants.

1. Letf : N → R+ be defined asf(1) = c, andf(n) = 2f(n2) +a·n, forn ≥ 2. Assume that n= 2kis a power of2,k∈N∪ {0}. Show that:

f(n) =c·n+a·n·log2n.

2. Letf :N → R+be defined asf(1) = a, andf(n) = 2f n2

+an2. Assume thatn= 2k is a power of2,k ∈N∪ {0}. Use telescoping to guess a closed form solution forf (and show how you did it), and then prove it by mathematical induction.

Exercise 5.4 Binary Relations(No bonus points).

In discrete mathematics, you learned that arelationρfrom a setAto a setBis a subset of the Cartesian productA×B. If(a, b)∈ρ, thenais related tob. IfA=B, thenρis said to be a relation onA. LetA={f :N→R+}. Recall that0∈/ R+. Then we can define relations onA, associated withO,Ω, andΘin the following way:

ρO ={(f, g) :f ≤ O(g)}

ρ={(f, g) :f ≥Ω(g)}

ρΘ={(f, g) :f = Θ(g)}

1. For each of the relationsρOΘ, determine (a) If it is an equivalence relation. Prove or disprove.

(b) If it is a partial order. Prove or disprove.

2. We can define a binary relation from a graph: LetG= (V, E)be any directed graph, allowing also loops, i.e. edges(u, u), whereu∈V. ThenρG =Eis a relation onV. (Recall thatE ⊂V ×V).

Similarly, we can define a graph from a binary relation: LetρG be a relation on V. ThenG = (V, ρG)is a directed graph, possibly with loops.

For each of the following graphsG, what are the properties (reflexivity, symmetricity, antisym- metricity, transitivity) of its corresponding relation, ρG? Arrows represent directed edges. If a line has two arrows, it represents two directed edges.

• Graph A

A B

C D

E

G F

2

(3)

• Graph B

A B

C D

E

G F

• Graph C

A B

C D

F E

3. Draw a directed graphG= (V, E), possibly with loops, with7vertices and17edges that corre- sponds to an equivalence relation. There can be no duplicate edges inE. If both(u, v)and(v, u) are inE, it counts as two edges.

Exercise 5.5 Max Submatrix Sum(2 Points).

Provide anO(n3)time algorithm which given ann×n-matrixMoutputs its maximal submatrix sum S. That is, ifM has some nonnegative entries,

S = max

0≤a≤b<n 0≤c≤d<n

b

X

i=a d

X

j=c

M[i][j],

and if all entries ofM are negative,S= 0.

Justify your answer, i.e. prove that the asymptotic runtime of your algorithm isO(n3).

Submission:On Monday, 29.10.2018, hand in your solution to your TAbeforethe exercise class starts.

3

Referenzen

ÄHNLICHE DOKUMENTE

For a given plan with N cells including the start and the end cell, how many steps do we need to reach the end cell, starting from the start cell, in the worst case scenario..

Hint: Suppose you start with a map with two vertical lines, dividing the map into three regions, colored red, blue, and red from right to left.. What happens if you draw a vertical

There must be such a vertex to remove because the tree is acyclic and connected and non-trivial (See Exercise 1.2.4).. Add the leaf node back to

In this exercise, we ask you to prove that a connected graph contains an Eulerian tour if and only if it does not contain a vertex of odd degree.. Prove that every connected

For the following code fragment, count the number of times the function f is invoked and express this in Θ -notation as concisely as possible.. For the following code

Determine the best search strategy for the floor where the phone breaks and give the number of drops in big-Θ notation.. Starting from the first block we drop the first phone from

The maximum possible difference of the depths of two leaves in the tree (with height h ) is therefore 1 greater than the maximum difference of the depths of two leaves in the

When i ≥ 1 , DP [i, j] contains the probability that the first person who draws a stone will win the game if the bag initially contains i black stones and j white ones. There