In: Computer Science
trace by using quicksort on the array : 4 6 5 3 2 7 1 using 7 as the pivot
Steps involved in quick sort are: -
Now, The given array is {4,6,5,3,2,7,1}
pivot element is 7, left pointer is at 4 and right pointer is at 1.
Now, first element from left which is greater than or equal to 7 is 7 itself and 1st element from right which is smaller than 7 is 1. so left pointer is at 7 and right pointer is at 1. So, we swap them and array becomes
4,6,5,3,2,1,7
Now our pivot element is at it's right place in when the array is sorted. All elements before 7 are smaller than 7.