logo

Crowdly

Consider the following algorithm. Assume the input array contains numbers. ...

✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.

Consider the following algorithm. Assume the input array contains numbers.

1

2

3

4

5

6

function SUMMATION(array[1..n])

sum = array[1]

for k = 2 to n do

# The invariant is here.

sum = sum + array[k]

return sum

Prove that the following invariant holds at line 4:

For any value of kk between 2 and nnsum is equal to the sum of elements of array[1..k-1].

You will need to show:

  • The initialisation step
  • The maintenance step

You do not need the termination step.

More questions like this

Want instant access to all verified answers on learning.monash.edu?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!