Question: PRE - condition: a ! = null, a . length > 0 , and a [ a . length - 1 ] = = x
PREcondition: a null,
alength and
aalength x
int optsearchint a int x
int i;
for i ; ai x; i
Empty body
if i alength
return i;
return;
POSTcondition: If there exists i such that i i alength
and ai x then return i otherwise return
Assume a has length N such that a a aalength is a set of
N distinct elements, which may or may not contain the target element x but
aalength x Give the best loop invariant to prove that opt search returns with the
POSTcondition satisfied. Verify the initialization condition of the loop invariant from part aVerify the maintenance condition of the loop invariant from part a
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
