Question

Show how the Radix sort algorithm sorts the array: 36 14 27 40 31 17 5....

  1. Show how the Radix sort algorithm sorts the array: 36 14 27 40 31 17 5. Must show the operation of the algorithm in details.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Radix sort algorithm

Step 1:Starting Radix Sort. We will process digits from right to left. The first step will be to count occurances of digits from the input array.

  
Step 2: 36 has current digit 6. Add one to the 6 bin.   

  
Step 3: 14 has current digit 4. Add one to the 4 bin.

   
Step 4:   27 has current digit 7. Add one to the 7 bin.

  
Step 5: 40 has current digit 0. Add one to the 0 bin.

Step 6 : 31 has current digit 1. Add one to the 1 bin.

  

Step 7: 17 has current digit 7. Add one to the 7 bin.

Step 8: 5 has current digit 5. Add one to the 5 bin.



Step 9: Now we will do a rolling summation of the count array, to be used next as positions

But first we subtract 1 from the 0 position so that the resulting sums yield correct positions in the Auxilliary array.

Step 10: 0 + 1 is 1. Put that in position 1

  
  
Step 11: 1 + 0 is 1. Put that in position 2


Step 12: 1 + 0 is 1. Put that in position 3

  

  
Step 13: 1 + 1 is 2. Put that in position 4

  

  
Step 14: 2 + 1 is 3. Put that in position 5

  

  
Step 15: 3 + 1 is 4. Put that in position 6

Step 16 : 4 + 2 is 6. Put that in position 7

  

Step 17: 6 + 0 is 6. Put that in position 8

Step 18: 6 + 0 is 6. Put that in position 9



Step 19: Now use the Count array to decide where to move values into the Auxilliary array

5 has current digit 5. So we look in position 5 of the Count array, to see that we put it in position 3 of the Auxilliary array.

And we decrement the value of Count array position 5


Step 20:   17 has current digit 7. So we look in position 7 of the Count array, to see that we put it in position 6 of the Auxilliary array.

And we decrement the value of Count array position 7


Step 21: 31 has current digit 1. So we look in position 1 of the Count array, to see that we put it in position 1 of the Auxilliary array.

And we decrement the value of Count array position 1

  
Step 22: 40 has current digit 0. So we look in position 0 of the Count array, to see that we put it in position 0 of the Auxilliary array.   

And we decrement the value of Count array position 0

  
Step 23: 27 has current digit 7. So we look in position 7 of the Count array, to see that we put it in position 5 of the Auxilliary array.

And we decrement the value of Count array position 7

  

  
Step 24: 14 has current digit 4. So we look in position 4 of the Count array, to see that we put it in position 2 of the Auxilliary array.

And we decrement the value of Count array position 4

  

  
Step 25: 36 has current digit 6. So we look in position 6 of the Count array, to see that we put it in position 4 of the Auxilliary array.

And we decrement the value of Count array position 6

Done with this pass1.

Step 26 : Now we move the value back to the Input Array

40 has current digit 4. Add one to the 4 bin.

  

Step 27: 31 has current digit 3. Add one to the 3 bin.

Step 28: 14 has current digit 1. Add one to the 1 bin



Step 29:   5 has current digit 0. Add one to the 0 bin.

36 has current digit 3. Add one to the 3 bin.

Step 30: 36 has current digit 3. Add one to the 3 bin.


Step 31: 27 has current digit 2. Add one to the 2 bin.


Step 32: 17 has current digit 1. Add one to the 1 bin.


Step 33: Now we will do a rolling summation of the count array, to be used next as positions

But first we subtract 1 from the 0 position so that the resulting sums yield correct positions in the Auxilliary array.
Step 34: 0 + 2 is 2. Put that in position 1


Step 35: 2 + 1 is 3. Put that in position 2

3 + 2 is 5. Put that in position 3
Step 36:

3 + 2 is 5. Put that in position 3
Step 37:

5 + 1 is 6. Put that in position 4
Step 38:

5 + 1 is 6. Put that in position 4
Step 39:

6 + 0 is 6. Put that in position 5
Step 40:

6 + 0 is 6. Put that in position 6
Step 41:

6 + 0 is 6. Put that in position 7
Step 42:

6 + 0 is 6. Put that in position 8

Step 43:

6 + 0 is 6. Put that in position 9
Step 44:


Step 45: Now use the Count array to decide where to move values into the Auxilliary array

And we decrement the value of Count array position 1


Step 46: 27 has current digit 2. So we look in position 2 of the Count array, to see that we put it in position 3 of the Auxilliary array.

And we decrement the value of Count array position 2


Step 47: 36 has current digit 3. So we look in position 3 of the Count array, to see that we put it in position 5 of the Auxilliary array.

And we decrement the value of Count array position 3


Step 48: 5 has current digit 0. So we look in position 0 of the Count array, to see that we put it in position 0 of the Auxilliary array.

And we decrement the value of Count array position 0


Step 49: 14 has current digit 1. So we look in position 1 of the Count array, to see that we put it in position 1 of the Auxilliary array.

And we decrement the value of Count array position 1


Step 50: 31 has current digit 3. So we look in position 3 of the Count array, to see that we put it in position 4 of the Auxilliary array.

And we decrement the value of Count array position 3

Step 51: 40 has current digit 4. So we look in position 4 of the Count array, to see that we put it in position 6 of the Auxilliary array

And we decrement the value of Count array position 4

Done with this pass2.
Step 52: Now we move the value back to the Input Array


The array after Sorting is 5,14,17,27,31,36,40

Add a comment
Know the answer?
Add Answer to:
Show how the Radix sort algorithm sorts the array: 36 14 27 40 31 17 5....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT