Sort the following array a using quicksort,
[6, 11, 4, 9, 8, 2, 5, 8, 13, 7]
The code should be selected as the arithmetic mean of the first and last elements, i.e. (a[0] + a[size - 1]) / 2 (rounded down)
.
Show all the important steps, such as partitioning and recursive algorithm calls.
I understand how to sort an array using quicksort, however I'm not sure how to calculate the anchor point.
Is the arch calculated by 6 + 7 = 13
, then 13 / 2 = 6.5
(rounded down 6
), so is the axis of rotation 2
(i.e. the 6th element)?
I know that elements smaller than the pivot are displayed on the left, and elements larger than the pivot are displayed on the right, and the section repeats this step of sorting the submatrix.
Any help would be greatly appreciated.
Paradox
source share