ISRO 2020 · Selection Sort

MCQ · 1 mark · Problem PROG-SORT-0020

Of the following sorting algorithms, which one runs in \(\Theta(n\log n)\) time whatever the initial ordering of the input?
  1. A
    Insertion sort
  2. B
    Quick sort
  3. C
    Merge sort
  4. D
    Selection sort

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

Show the worked solution\[\boxed{\text{merge sort: } T(n)=2T(n/2)+\Theta(n)=\Theta(n\log n) \text{ for every input order}}\](A) Insertion sort: \(\Theta(n)\) on sorted input, \(\Theta(n^{2})\) on reversed input.(B) Quick sort: \(\Theta(n\log n)\) on average but \(\Theta(n^{2})\) in the worst case (e.g. sorted input with the first element as pivot).(C) Merge sort always halves and merges, so it is \(\Theta(n\log n)\) for every ordering. correct.(D) Selection sort is also insensitive to the order (always \(n(n-1)/2\) comparisons), but it is \(\Theta(n^{2})\).Answer: C

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