Skip to content
Official PYQ · 1992

GATE CS 1992 Q02 — Searching, Sorting, Hashing

Explain with AI

Following algorithm(s) can be used to sort nn in the range [1…n3][1\ldots n^3] in O(n)O(n) time

Choose one option
View worked solution

Answer: D

To sort nn integers in the range [1…n3][1 \dots n^3] in O(n)O(n) time, we analyze the given sorting algorithms:

  1. Comparison-based Sorting Algorithms (Heap Sort, Quick Sort, Merge Sort):

    Any comparison-based sorting algorithm has a lower bound of Ω(nlog⁡n)\Omega(n \log n) in the worst case. Therefore, Heap sort, Quick sort, and Merge sort cannot achieve O(n)O(n) time complexity.

  2. Radix Sort:

    Radix sort is a non-comparison-based sorting algorithm. It sorts nn keys of dd digits where each digit can take up to bb different values (base bb) in O(d(n+b))O(d(n + b)) time using Counting Sort as a stable sorting subroutine.

    For numbers in the range [1…n3][1 \dots n^3], we can represent them in base b=nb = n. In base nn, the maximum number of digits dd required to represent any number up to n3n^3 is:

    d=log⁡n(n3)=3d = \log_n(n^3) = 3

    Substituting b=nb = n and d=3d = 3 into the Radix sort time complexity formula:

    T(n)=O(3⋅(n+n))=O(n)T(n) = O(3 \cdot (n + n)) = O(n)

Thus, Radix sort can be used to sort the given numbers in O(n)O(n) time.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Searching, Sorting, Hashing questions