1,068 views

2 Answers

4 votes
4 votes

Assume $n$ keys sorts integers $\epsilon \left \{ 0,1,....(k-1) \right \}$

Then according to counting sort , for $k$ integers can sort $O(n)$ time.


Now, here is the  proof by an algorithm:

Say, $L=$ Array of $k$ empty lists for $j$ in $range\left ( n \right )$. 

$L\left [ key\left ( A\left [ j \right ] \right ) \right ],append\left ( A\left [ j \right ] \right )$

for $i$ in $range\left [ k \right ]:$

$Output.extend\left ( L\left [ i \right ] \right )$

This algorithm has time complexity $O\left ( n+k \right )$.........$(i)$

 

Now, using counting sort imagine each integer has base $b.$

Then, $digit=d=\log _{b}k+1$

Now, according to counting sort expression $(i)$ will be $O\left ( n+b \right )$

Then total time$=O\left ( \left ( n+b \right ).d \right )$

                         $=O\left ( \left ( n+b \right ).\log _{b}k \right )$

                         $=O\left ( \left ( n \right ).\log _{n}k \right )$ when $b\simeq n$

                        $=O\left ( 3n \right )=O\left ( n \right )$ [when $k=n^{3}$ a polynomial function]

Source:MIT Lecture

Related questions

0 votes
0 votes
0 answers
1
akash.dinkar12 asked Jun 28, 2019
582 views
Use induction to prove that radix sort works. Where does your proof need the assumption that the intermediate sort is stable?
0 votes
0 votes
1 answer
2
0 votes
0 votes
2 answers
3