Question: 2 . ( 6 points ) The version of PARTITION discussed in lecture is not the original partitioning algorithm. Here is the original partition algorithm,
points The version of PARTITION discussed in lecture is not the original partitioning algorithm. Here is the original
partition algorithm, which is due to T Hoare:
HOAREPARTITIONA p r
x Ap
i p
j r
while TRUE
do repeat j j
until Aj x
repeat i i
until Ai x
if i j
then exchange Ai Aj
else return j
a Demonstrate the operation of HOAREPARTITION on the array A showing
the values of the array and auxiliary values after each iteration of the loop in lines
The next three questions ask you to give a careful argument that the procedure HOAREPARTITION is correct. Prove the
following:
b The indices i and j are such that we never access an element of A outside the subarray Ap r
c When HOAREPARTITION terminates, it returns a value j such that p j r
d Every element of Ap j is less than or equal to every element of Aj r when HOAREPARTITION
terminates.
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
