edited by
24,467 views
49 49 votes

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

  1. Heap sort
  2. Quick sort
  3. Merge sort
  4. Radix sort

6 Answers

Best answer
70 70 votes

Answer is $(D)$ Part.

Although people have provided correct  answers but it seems some more explanation is required.
Let there be $\mathbf{d}$ digits in max input integer, b is the base for representing input numbers and $\mathbf{n}$ is total numbers then Radix Sort takes $\mathbf{O(d*(n+b))}$ time. Sorting is performed from least significant digit to most significant digit. 

For example, for decimal system, $b$ is $10$. What is the value of $d$? If $k$ is the maximum possible value, then $d$ would be $O(\log_b (k))$. So overall time complexity is $O((n+b) * \log_b(k))$. Which looks more than the time complexity of comparison based sorting algorithms for a large $k$. Let us first limit $k$. Let $k \leqslant n^{c}$ where $c$ is a constant. In that case, the complexity becomes $O(n \log_b(n))$. But it still does not beat comparison based sorting algorithms.
What if we make value of $b$ larger?. What should be the value of $b$ to make the time complexity linear? If we set $\mathbf{b}$ as $\mathbf{n}$ then  we will get the time complexity as $O(n)$.

In other words, we can sort an array of integers with range from $1$ to $n^{c}$, If the numbers are represented in base $n$ (or every digit takes $\log_2(n)$ bits).

Reference: http://www.geeksforgeeks.org/radix-sort/

edited by
23 23 votes
Answer :- $D$

As no comparison based sort can ever do any better than $n$ $log$ $n$ (Unless in special cases) $a,b,c$ are eliminated. $n$ $log$ $n$ is lower bound for comparison based sorting.

As Radix sort is not comparison based sort (it is counting sort) So, $D$ is correct !
edited by
11 11 votes
Answer: D

Radix sort complexity is O(wn) for n keys which are integers of word size w.
0 0 votes
Radix Sort can be used here.

Initially you can figure it out that Merge Sort has O(nlogn) and Quick Sort has O(n^2) and Insertion Sort has O(n^2) as worst case time complexity and Merge Sort has O(nlogn) and Quick Sort has O(nlogn) and Insertion Sort has O(n) as best case time complexity. Insertion Sort gives best case if array is sorted or almost-sorted. But here nothing is given about elements of array.

So ans would be Radix Sort only. Also, the idea of Radix Sort is to do digit by digit sort starting from least significant digit to most significant digit. Radix sort uses counting sort as a subroutine to sort. Radix Sort takes O(d*(n+b)) time where b is the base for representing numbers, example Decimal.
0 0 votes

Radix Sort is a non-comparative integer sorting algorithm that sorts numbers by processing individual digits that share the same position and value. It can sort n integers in the range [1, n³] in O(n) time because it uses digit-by-digit counting (using Counting Sort as a subroutine), which runs in linear time when the number of digits is constant.

In contrast, Heap Sort, Quick Sort, and Merge Sort are comparison-based sorting algorithms and therefore have a lower bound of Ω(n log n) on their time complexity.

Therfore ans: D) Radix Sort

Answer:
Position:
Show:

Related questions

48 48 votes
13 answers 13 answers
27.0k
27.0k views
Kathleen asked Sep 12, 2014
27,015 views
Complexity of Kruskal’s algorithm for finding the minimum spanning tree of an undirected graph containing $n$ vertices and $m$ edges if the edges are sorted is _______
8 8 votes
6 6 answers
3.8k
3.8k views
Arjun asked Feb 27, 2025
3,797 views
Suppose that insertion sort is applied to the array $[1,3,5,7,9,11, x, 15,13]$ and it takes exactly two swaps to sort the array. Select all possible values of $x$.$10$$12...
32 32 votes
3 answers 3 answers
7.6k
7.6k views
Kathleen asked Sep 13, 2014
7,604 views
Assume that the last element of the set is used as partition element in Quicksort. If $n$ distinct elements from the set $\left[1\dots n\right]$ are to be sorted, give an...
35 35 votes
3 answers 3 answers
9.3k
9.3k views
Kathleen asked Sep 13, 2014
9,331 views
In which of the cases stated below is the following statement true?"For every non-deterministic machine $M_{1}$ there exists an equivalent deterministic machine $M_{2}$ r...