Algorithms and Data Structures (INF1, Autumn'05)

Exercise Set 6


Exercise 1:

Assume that you are given a function sum(l:LIST):int which for an input list l=< a1,a2, ..., an> returns the sum of all its values, i.e., sum(l)=a1.value + a2.value + ... + an.value. Formally, we know that the function sum is totally correct w.r.t. the following pre- and post-conditions.

--pre: l=< a1,a2, ..., an> s.t. VALUE_TYPE=int
x:=sum(l)
--post: x=Σi = 1..n ai.value



Exercise 2:



Exercise 3 (hand-in):

Write appropriate pre- and post-conditions for the list operations first and next.

--pre: ???
x:=l.first
--post: ???


--pre: ???
y:=l.next(x)
--post: ???