In: Computer Science
Given the following array of 8 elements, show the steps to sort the elements in ascending order using a radix sort. Fill in each of the following blanks.
81 546 677 9 97 12 53 22
Adjust with 0s:
Buckets for ones digit:
Buckets for tens digit:
Final Result:
The given array is : 81 546 677 9 97 12 53 22
Step Number 1:
Append 0 for double and single digit numbers so all the numbers consist of three digits.
Now we got : 081, 546, 677, 009, 097, 012, 053, 022.
Step Number 2:
Now the numbers are sorted based on one's digit in the ascending order.
We have : 081, 546, 677, 009, 097, 012, 053, 022.
Now we got : 081, 012, 022, 053, 546, 677, 097, 009.
Step Number 3:
Now the numbers are sorted based on ten's digit in the ascending order.
We have : 081, 012, 022, 053, 546, 677, 097, 009.
Now we got : 009, 012, 022, 546, 053, 677, 081, 097.
Step Number 4:
Now the numbers are sorted based on hundred's digit in the ascending order.
We have : 009, 012, 022, 546, 053, 677, 081, 097.
Now we got : 009, 012, 022, 053, 081, 097, 546, 677.
That is the sorted array.