GATE CSE
First time here? Checkout the FAQ!
x
+3 votes
1.2k 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
asked in Algorithms by Loyal (4k points)   | 1.2k 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 Mar 2017
  1. rude

    5118 Points

  2. sh!va

    3054 Points

  3. Rahul Jain25

    2920 Points

  4. Kapil

    2730 Points

  5. Debashish Deka

    2602 Points

  6. 2018

    1574 Points

  7. Vignesh Sekar

    1422 Points

  8. Akriti sood

    1382 Points

  9. Bikram

    1350 Points

  10. Sanjay Sharma

    1128 Points

Monthly Topper: Rs. 500 gift card

21,531 questions
26,861 answers
61,191 comments
23,207 users