UGC-NET Jun 2019 · Heap Sort & Non-Comparison Sorts

MCQ · 2 marks · Problem PROG-SORT-0009

Which of the following is best running time to sort $n$ integers in the range $0$ to $n^2-1$?
  1. A
    $O(\text{lg } n)$
  2. B
    $O(n)$
  3. C
    $O(n\text { lg }n)$
  4. D
    $O(n^2)$

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

Show the worked solutionWrite each number in base \(n\): any value in \([0,n^2-1]\) has exactly 2 base-\(n\) digits. Radix sort with counting sort per digit then costs\[d(n+k)=2(n+n)=O(n).\]This beats the \(O(n\lg n)\) comparison bound because it does not compare keys.Answer: B

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