2.5k views

Which one of the following in place sorting algorithms needs the minimum number of swaps?

1. Quick sort
2. Insertion sort
3. Selection sort
4. Heap sort
Shouldn't this be Insertion Sort?

As in Insertion Sort, we "technically" don't swap, but shift elements to place the element under consideration in proper place
does swap here means shifting the elements??
NU OF SWAP
IN BUBBLE SORT =O(n2)
in selection sort=n
in insertion sort =0

(C) Selection sort
selected by
Selection sort

because in selection the maximum swaps which can take place are O(n)

because we pick up an element an find the minimum(in case of forward sorting) from the next index till the end of array and than perform the swap

hence O(n) whereas in all other algos the swaps are greater
Please compare number of swaps in selection sort with other sorting techniques given in above question.
+1 vote
Number of swaps
Quick sort = $\Theta (nlogn)$
Insertion sort =  $\Theta (n^{2})$
Selction sort = no swaps required since we are shifting elements in the array and not swapping
Heap sort =  $\Theta (nlogn)$

Option C
in  quick  wont it be n^2 ?