Question: Please come up with original solution, without copy-pasting it from already give answers int partition (int arr[), int first, int last) int mid first int

Please come up with original solution, without copy-pasting it from already give answers
int partition (int arr[), int first, int last) int mid first int pivot-arrfirst]a for lint sweep-first+1 sweeplast: sweep++) // Assertion: .. if larrsweep pivot) int tmparr[sweep] arr Isweeparr [mid+1] arr [mid+11-tmpi mid++ // Post:..' arrlfirstarr[mid] azrlmid]pivot return mid; The focus for this problem will be the main loop of partition. You will make arguments about what it attempts to accomplish. a) 3 marks] The diagram depicts what we hope is the state of arrfirst..last] just after the main loop terminates [but before the pivot is swapped into place]. Write down a post-condition that effectively summarizes the values and locations of the array elements, as they relate to indices first, last and mid. first mid last ivot 2 piv b) 3 marks] Write an assertion that is true at the beginning of each loop. Just like you did for part (a), it should summae the values and locations of the array elements, as they relate to al indices, i.e., first, last, mid, but also sweep Hint: Your answer is probably correct if, when you substitute sweeplast 1, it matches your answer to part (a) c) 5 marks] Prove that the partition algorithm is correct using the initialization-maintenance- termination technique shown in class
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
