in Algorithms recategorized by
238 views
1 vote
1 vote
Consider the QuickSort algorithm with the last element chosen as the pivot. If the goal is to sort the given array \(a = [30, 40, 50, 60, 70, 80]\) in ascending order, how many swaps will occur during the execution of the algorithm?
in Algorithms recategorized by
238 views

1 Answer

0 votes
0 votes

In quick sort, every iteration attempts to move the elements larger than the pivot to the right side of the pivot elements. Whereas smaller elements are to the left of the pivot elements. 

In the given question since the last element is chosen as the pivot and the elements are in sorted order no elements will change their place after every interaction. so there will be no swapping of elements. 

The orignal question was |60|70|80|90|100|

The answer will be 0 (Zero).

Related questions