1 identify an invariant predicate of the while loop


(1) Identify an invariant predicate of the while loop suitable for proving that the algorithm returns the expected value. Then, give a loop variant expression suitable for proving that the algorithm will always terminate.

ALGORITHM SumPos(A[0..- 1])

// Returns the sum of the positive numbers in an array of length n. We

// assume that the sum of the numbers in an array of length zero is zero.

← 0

← 0

while ≠ do

if A[i] > 0

A[i]

← + 1

return t

 

Solution Preview :

Prepared by a verified Expert
Basic Computer Science: 1 identify an invariant predicate of the while loop
Reference No:- TGS02730009

Now Priced at $10 (50% Discount)

Recommended (97%)

Rated (4.9/5)