logo

Crowdly

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

✅ Перевірена відповідь на це питання доступна нижче. Наші рішення, перевірені спільнотою, допомагають краще зрозуміти матеріал.

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.

Більше питань подібних до цього

Хочете миттєвий доступ до всіх перевірених відповідей на learning.monash.edu?

Отримайте необмежений доступ до відповідей на екзаменаційні питання - встановіть розширення Crowdly зараз!