Question
Follow pseudo to partition the array using 1rst element, 6 a) Show the array after each time swap (line 14 and line 18 above) is
Follow pseudo to partition the array using 1rst element, 6
a) Show the array after each time swap (line 14 and line 18 above) is executed.
b) Consider that the array might contain duplicates (including multiple elements equal to the pivot value), add a few lines of codes after line 19 in the above pseudocode so that all pivot values are moved to the middle, and the function returns the starting and ending index of the middle section that contains elements that are equal to the pivot.
c) Comment where the 2nd smallest element should be, i.e., the left partition or right partition of the above partition result?
// partition list A[startI...endI] using // A[startI] (first element in the sublist) Partition (A, startI, endI) 1. pivot A[startI] //set first element as pivot value 2. left- startI+1; //left index 3. right -end; //right index 4. do f // increment left until we find a value larger than pivot or 5.// until left--right 5.while (a[left]-pivot && leftStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started