retagged by
565 views

1 Answer

0 votes
0 votes

After 3 passes the element 5 will be at its correct position.

It is given to us that the last element has to be taken as the pivot.

12 7 15 8 19 20 17 21 5 3

So 3 is the pivot .. After the first pass the element 3 will be at the correct position.

3 7 15 8 19 20 17 21 5 12

Now for the second pass the element 12 is pivot and it will come to its right position.

3 7 8 5 12 20 17 21 15 19

Now in the third pass the (7,8,5) and(20,17,21,15,19)will be sorted using the partition method and the quicksort method. 

So when quicksort will be called on (7,8,5) 5 will act as pivot and it will be placed at its right position.

So after 3 passes 5 will come at its correct position .

After three passes the array will look like this:

3 5 8 7 12 17 15 19 20 21

No related questions found