First time here? Checkout the FAQ!
+3 votes

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
asked in Algorithms by Loyal (4k points)   | 1.1k views
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

3 Answers

+7 votes
Best answer
(C) Selection sort
answered by Boss (6.3k points)  
selected by
+9 votes
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
answered by (299 points)  
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
answered by Active (1.6k points)  
in  quick  wont it be n^2 ?
Top Users Feb 2017
  1. Arjun

    5410 Points

  2. Bikram

    4230 Points

  3. Habibkhan

    3952 Points

  4. Aboveallplayer

    3086 Points

  5. Debashish Deka

    2564 Points

  6. sriv_shubham

    2318 Points

  7. Smriti012

    2240 Points

  8. Arnabi

    2008 Points

  9. mcjoshi

    1696 Points

  10. sh!va

    1684 Points

Monthly Topper: Rs. 500 gift card

20,864 questions
26,030 answers
22,144 users