Partition Steps in Quick Sort
The steps in the partition function are as follows:
Step 1: First, assign the last value as a pivot and start comparing it with the elements while iterations. Here, compare 10 with 40 as the element is smaller so swap it with first available position. As 10 itself is at the correct possition there will be no change.
Step 2: Here compare 2nd value with the pivot as the value 80 is greater so there will be no swapping.
Step 3: Now, compare the third element i.e. 30 with pivot value 40. as it is smallar so swap 30 with the next available position i.e. 2 nd. Hence, swap 80 and 30.
Step 4: For position 4 the value 90 is larger. Hence, there will be no swap.
Step 5: In the last step swap the pivot element woth the next position available for swapping which is position 3 with value 80. So swap pivot with 80 as shown.
Contact Us