Show me the steps in sorting this array using quick sortnot
Show me the steps in sorting this array using quick sort(not the code, show me how to do this specific array):
81, 8, 18, 288, 300,50, 15, 788, 10, 1, 4, 384, 898
Solution
1) The first item in the array is selected as the pivot value which is responsible for splitting the array.
Therefore in the array : 81, 8, 18, 288, 300,50, 15, 788, 10, 1, 4, 384, 898
81 is selected as the pivot element.
2) Locate two position markers, lets call them leftmark and rightmark.
Therefore, leftmark = 8
and rightmark = 898
Leftmark and Rightmark will converge on split point where the array will be partitioned into 2 sub arrays.
2.a) While value at leftmark is less than pivot move right.
2.b) While value at rightmark is greater than pivot move left.
3) Compare leftmark (ie. 8) and rightmark (ie. 898) with the pivot value 81.
leftmark value 8 < Pivot value 81. So we can move right. Therefore , leftmark 18
rightmark value 898 > Pivot value 81. So we can move left. Therefore , rightmark 384
4) Compare leftmark (ie. 18) and rightmark (ie. 384) with the pivot value 81.
leftmark value 18 < Pivot value 81. So we can move right. Therefore , leftmark 288
rightmark value 384 > Pivot value 81. So we can move left. Therefore , rightmark 4
5) Compare leftmark (ie. 288) and rightmark (ie. 4) with the pivot value 81.
leftmark value 288 > Pivot value 81. So we need to stop.
rightmark value 384 < Pivot value 81. So we need to stop.
Compare leftmark (288) with rightmark (4). Swap the 2 values since leftmark>rightmark.
Therefore, array now becomes : 81, 8, 18, 4, 300,50, 15, 788, 10, 1, 288, 384, 898
Now, leftmark=4 and rightmark=288.
6) Compare leftmark (ie. 4) and rightmark (ie. 288) with the pivot value 81.
leftmark value 4 < Pivot value 81. So we can move right. Therefore , leftmark 300.
rightmark value 288 > Pivot value 81. So we can move left. Therefore , rightmark 1.
7) Compare leftmark (ie. 300) and rightmark (ie. 1) with the pivot value 81.
leftmark value 300 > Pivot value 81. So we need to stop.
rightmark value 1 < Pivot value 81. So we need to stop.
Compare leftmark (300) with rightmark (1). Swap the 2 values since leftmark>rightmark.
Therefore, array now becomes : 81, 8, 18, 4, 1 ,50, 15, 788, 10, 300 , 288, 384, 898
Now, leftmark=1 and rightmark=300
8) Compare leftmark (ie. 1) and rightmark (ie. 300) with the pivot value 81.
leftmark value 1 < Pivot value 81. So we can move right. Therefore , leftmark 50.
rightmark value 300 > Pivot value 81. So we can move left. Therefore , rightmark 10.
9) Compare leftmark (ie. 50) and rightmark (ie. 10) with the pivot value 81.
leftmark value 50 < Pivot value 81. So we can move right. Therefore , leftmark 15.
rightmark value 10 < Pivot value 81. So we need to stop.
10) Compare leftmark (ie. 15) and rightmark (ie. 10) with the pivot value 81.
leftmark value 15 < Pivot value 81. So we can move right. Therefore , leftmark 788.
rightmark value 10 < Pivot value 81. So we need to stop.
11) Compare leftmark (ie. 788) and rightmark (ie. 10) with the pivot value 81.
leftmark value 788 > Pivot value 81. So we need to stop.
rightmark value 10 < Pivot value 81. So we need to stop.
Compare leftmark (788) with rightmark (10). Swap the 2 values since leftmark>rightmark.
Therefore, array now becomes : 81, 8, 18, 4, 1 ,50, 15, 10, 788, 300 , 288, 384, 898
Now, leftmark=10 and rightmark=788
12) Compare leftmark (ie. 10) and rightmark (ie. 788) with the pivot value 81.
leftmark value 10 < Pivot value 81. So we can move right. Therefore , leftmark 788.
rightmark value 788 > Pivot value 81. So we can move left. Therefore , rightmark 10.
Now, since leftmark>rightmark. We observed that this is the split point where rightmark is the splitpoint.
Therefore, split point=10.
13) Pivot element can now be exchanged with rightmark. Therefore array becomes :
10, 8, 18, 4, 1 ,50, 15, 81, 788, 300 , 288, 384, 898
14) We can now subdivide the complete array into 2 sub arrays.
Array1 (<81): 10, 8, 18, 4, 1 ,50, 15
Array2 (>81) : 788, 300 , 288, 384, 898
15) Repeat the same procedure from step 1 to 14 to further sort the sub arrays and the complete array at the end.

