Question & Answer: Could you please show me the step by step of the quicksort algorithm Using Quick Sort, with the median pivot rule (pick the median of: data[lo], data[hi – 1]…..

Could you please show me the step by step of the quicksort algorithm

Using Quick Sort, with the median pivot rule (pick the median of: data[lo], data[hi – 1], and data[(hi + lo) / 2]), sort the following list of numbers. Show your work by drawing the tree of partitions and pivots (as seen on the slides) with the partition rules discussed in class (swapping the pivot to index lo and doing swaps to complete the partitions). Apply a cutoff of 3 elements and sort with any sorting method.

Expert Answer

 Alogrithm step by step:
  •     Pick the middle element as Pivot
  •     Initialize left pointer with ‘0’and right pointers with size of array.
  •    Star at the left pointer and move to the right, find the first element which is greater than pivot value and starting at right pointer moving to left, find the first element which is less than pivot.
  • Swap elements those at left pointer and right pointer.
  •     Repeat the above 3,4,5 until left pointer is greater or equal to right pointer.
  •     Recursively sort the sub-list of lesser elements and the sub-list of greater elements.

Example:

Still stressed from student homework?
Get quality assistance from academic writers!