Algorithms and Data Structures (INF1, Autumn'05)

Exercise Set 5


Exercise 1:

In this exercise you are asked to implement the operation merge from the D&C sorting algorithm explained at the lecture.

Let A[1..n], B[1..m] and C[1..(n+m)] be arrays such that n,m>0.


Exercise 2 (hand in):

Recall the ADT called SET from the lecture. For a set s:SET we have the following basic operations and we also defined a non-destructive version of member(x:int,s:SET):boolean.

Define a new set operation sum(s:SET):int satisfying

--pre: s is a SET
x:=sum(s)
--post: x=Σa ∈ S a     and   s'=s

Assume now that somebody gave you a better implementation of SET than what we did at the lecture. However, the only info you know about the new implementation is that Is this piece of information enough to analyze the worst-case time complexity of your sum operation?

Exercise 3:

Assume the same "better" implementation of SET as in Example 2.

Define a new operation intersection(s1:SET, s2:SET):SET satisfying

--pre: s1 and s2 are SETs

s:=intersection(s1, s2)

--post: s = s1 ∩ s2   and   s'1 = s1   and   s'2 = s2

Provide the worst-case time complexity analysis of intersection(s1, s2) (use |s1| for the number of elements in the set s1 and |s2| for the number of elements in s2).