PROGRAM VERIFICATION

Homework #2: Shared Find


Fill in a proof outline (repairing the program, if necessary) that shows that this program finds the location k of the first positive element (a[k]>0) in an array a[1:N] and returns N+1 if there is none such.
 
 

i1 := 1

i2 := 2

k := N+1


while i1 < k do
if a[i1] > 0
then k := i1

else i1 := i1+2


while i2 < k do
if a[i2] > 0
then k := i2

else i2 := i2+2