• edited by
33,351 views
82 82 votes

If we use Radix Sort to sort $n$ integers in the range $\left (n^{k/2}, n^k \right ]$, for some $k > 0$ which is independent of $n$, the time taken would be?

  1. $\Theta(n)$
  2. $\Theta(kn)$
  3. $\Theta(n \log n)$
  4. $\Theta(n^2)$

8 Answers

Best answer
78 78 votes

Answer: C

The complexity of Radix Sort is $O(wn)$, for $n$ keys which are integers of word size $w$.

Here, $w = \log_2(n^k) = k \times \log_2(n)$

So, the complexity is $O(wn) = O(k \times \log_2(n) \times n)$, which leads to option C.

• edited by
65 65 votes

TIME COMPLEXITY OF RADIX SORT IS THETA ((n+k)d))

where n= no of numbers

k= base of number system

d= no of digits.

Here let base is b. 

Numbers are are in range (n^k/2,n^k).

No of digits required= (log n^k)base b=k log n base b.

thus time complexity =( n+b) k log n base b.

Since b and k are constants with respect to n  time complexity = Θ(nlogn)

11 11 votes

I am not sure my approach is correct or not but I have seen something like this in CLRS.

When we represent nk/2 and nk in base n, we need atmost k+1 bits.

And to sort k+1 bit positions apply any stable sorting algorithm like counting sort(O(n) time ).

So, time complexity = O(k*n) i.e. apply counting sort for each of the k+1 bit positions.

So, answer (b).

If my approach is wrong,can anyone explain why ??

8 8 votes

Answer would be C.

P.S- The question mention "n integer values" somehow implies it is decimal representation system. So we can say k=10 and d=k*$log_{10}N$

Time complexity = O (n.log n)

• edited by
2 2 votes

Radix sort sorts numbers from LSB to MSB one column of digits at a time.

Each sort of a column (imagine a Matrix where each row is a candidate number) takes $O(n)$ time

Hence total time complexity would be $O(pn)$ where p = number of columns or the word length.

 

The maximum number we'd require to sort would be $n^k$. (given)
The word length of such a number would be $log (n^k)$ or $klogn$ or $O(logn)$ because k is independent of n.

Hence p = $O(logn)$

So, time complexity of radix sort here would be $O(pn) = O(nlogn)$

 

Option C

2 2 votes
$Answer: option B$

Method 1: n elements range of elements n^(k/2) to n^k

No. of digits (d) = logbase10(n^k) = θ(klogn)
Radix sort time complexity : θ(n * k * logn)

$Method 2$ : n elements given

Convert each element into radix n number system. Time complexity for this n elements θ(n)

Number of digits is become log basen(n^k) = k digits.

Applying radix sort time complexity θ(n * k)
Answer:
Position:
Show:

Related questions

23 23 votes
3 answers 3 answers
12.8k
12.8k views
Ishrat Jahan asked Oct 29, 2014
12,808 views
Consider the code fragment written in C below : void f (int n) { if (n <= 1) { printf ("%d", n); } else { f (n/2); printf ("%d", n%2); } }Which of the following im...
21 21 votes
5 answers 5 answers
12.0k
12.0k views
Ishrat Jahan asked Oct 29, 2014
12,026 views
Consider the code fragment written in C below :void f (int n) { if (n <=1) { printf ("%d", n); } else { f (n/2); printf ("%d", n%2); } }What does f(173) print?$010110101$...
32 32 votes
4 answers 4 answers
12.7k
12.7k views
Ishrat Jahan asked Oct 28, 2014
12,703 views
Consider the following sequence of nodes for the undirected graph given below:$a$ $b$ $e$ $f$ $d$ $g$ $c$$a$ $b$ $e$ $f$ $c$ $g$ $d$$a$ $d$ $g$ $e$ $b$ $c$ $f$$a$ $d$ $b$...
39 39 votes
5 answers 5 answers
23.2k
23.2k views
Ishrat Jahan asked Oct 28, 2014
23,235 views
For the undirected, weighted graph given below, which of the following sequences of edges represents a correct execution of Prim's algorithm to construct a Minimum Span­n...