using java 1)The radix sort algorithm sorts an array of n integers with d digits
ID: 3739312 • Letter: U
Question
using java
1)The radix sort algorithm sorts an array of n integers with d digits, using ten auxiliary arrays. First, pad each integer with 0s on the left so that all n integers have the same number of digits. Then, to sort the integers:
-Place each value v into the auxiliary array whose index corresponds to the last digit of v.
-Move all values back into the original array, preserving their order.
-Repeat the process, now using the next-to-last (tens) digit, then the hundreds digit, and so on.
Trace a walkthrough of radix sort with these lists:
a. 5 11 7 3 5 4 7 11 4 9
b. 9 0 11 10 5 8 9 6 8 7 5
2)A stable sort does not change the order of elements with the same value. This is a desirable feature in many applications. Consider a sequence of e-mail messages. If you sort by date and then by sender, you’d like the second sort to preserve the relative order of the first, so that you can see all messages from the same sender in date order. Is selection sort stable? Insertion sort? Why or why not?
Explanation / Answer
Solution:
1)
We have the list
a)
5 11 7 3 5 4 7 11 4 9
Pass 1:
Let's sort the LSB first
11, 11, 3, 4, 4, 5, 5, 7, 7, 9
Pass 2:
sorting the second bit from the LSB
3, 4, ,4, 5, 5, 7, 7, 9, 11, 11.
b)
The given list is:
9 0 11 10 5 8 9 6 8 7 5
Pass 1:
0, 10, 11, 5, 5, 6, 7, 8, 8, 9, 9
Pass 2:
0, 5, 5, 6, 7, 7, 8, 8, 9, 9, 10, 11
2)
Insersion sort is a stable sorting technique
while selection sort is not.
Because insertion sort start from the left side of the array and start looking for the smallest number whichever is found first will occupy the first spot, in this fashion, there is no chance that stability if the elements gets violated that is why insertion sort is stable sorting technique.
I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.