Which one of the following in place sorting algorithms needs the minimum…

2006

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

  1. A.

    Quick sort

  2. B.

    Insertion sort

  3. C.

    Selection sort

  4. D.

    Heap sort

Attempted by 284 students.

Show answer & explanation

Correct answer: C

Answer: Selection sort

Why this is correct:

  • Selection sort selects the smallest (or largest) element remaining and swaps it into its final position once per pass.

  • Because it does at most one swap per position, the total number of swaps is at most n-1 for an array of size n.

  • Other in-place sorts:

    • Insertion sort can require up to O(n^2) swaps or shifts in the worst case (though it moves fewer elements for nearly-sorted input).

    • Quick sort performs many partition swaps (average O(n log n) swaps), so it generally uses more swaps than selection sort.

    • Heap sort also requires O(n log n) swaps while building and maintaining the heap.

Conclusion: Selection sort minimizes the number of swaps (at most n-1), so it is the correct choice when counting swaps among these in-place algorithms.

Explore the full course: Gate Guidance By Sanchit Sir