Question: Consider the following IMP program: i : = 0 ; j : = len ( arr ) - 1 ; while i < = j
Consider the following IMP program:
i :;
j : lenarr;
while i j do
if arri arr then
i : i
else
tmp : arri;
arri : arrj;
arrj : tmp;
j : j
Givenanonemptyarrayofintegersarrwithindexesthroughlenarrtheprogramattempts to partition arr such that all elements lesser than or equal to its first element appear before all elements greater than its first element.
Come up with assertions P the loop invariant and Q the loop postcondition in terms of i j and arr, that can be used to demonstrate partial correctness of the program. Briefly explain how P can be used to imply Q
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
