UGC-NET Dec 2014 · Selection Sort

MCQ · 2 marks · Problem PROG-SORT-0007

You have to sort a list $L$, consisting of a sorted list followed by a few ‘random’ elements. Which of the following sorting method would be most suitable for such a task ?
  1. A
    Bubble sort
  2. B
    Selection sort
  3. C
    Quick sort
  4. D
    Insertion sort

Solve it on GATE DA practice →More Searching & Sorting Algorithms problems

Show the worked solutionInsertion sort runs in \(O(n+I)\), where \(I\) is the number of inversions. A sorted list followed by a few (say \(k\)) random elements has at most about \(kn\) inversions, so insertion sort takes about \(O(kn)\), nearly linear for small \(k\).(A) Bubble sort makes many passes and swaps, slower in practice — incorrect.(B) Selection sort always takes \(\Theta(n^2)\) comparisons — incorrect.(C) Quick sort with a first or last pivot is at its worst, \(O(n^2)\), on nearly sorted input — incorrect.Answer: D

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com