Question: Ruby is a fan of radix-sort! Given n two-digit numbers in base n, she wants sort the numbers using radix-sort which would need two calls

 Ruby is a fan of radix-sort! Given n two-digit numbers inbase n, she wants sort the numbers using radix-sort which would needtwo calls to the counting-sort algorithm. In her algorithm, first she callscounting-sort on the second digit (right digit), and then calls counting-sort anothertime on the first digit (left digit). However, since it is prettylate and she feels sleepy, she makes a critical mistake in the

Ruby is a fan of radix-sort! Given n two-digit numbers in base n, she wants sort the numbers using radix-sort which would need two calls to the counting-sort algorithm. In her algorithm, first she calls counting-sort on the second digit (right digit), and then calls counting-sort another time on the first digit (left digit). However, since it is pretty late and she feels sleepy, she makes a critical mistake in the implementation: In the first call to counting-sort, instead of using the value of the second digit (say d2) as the key, she uses (d2 + i)%n as the key, where i is the current index of the number in the array. (indices start from 0.) Also, in the second call to counting-sort instead of using di as the key, she uses (di + 2 * i)%n as the key. Compute and print the array after being "almost" sorted using Ruby's radix-sort algorithm. (See the output section for print instructions.) Input Format The first line of the input has two integers n and k. (k will be used in the output section.) To save the trouble of reading the numbers from the input, after you read n from the input, you use the following line that provides you with an array of n two-digit numbers (in base n). There is no need to use FastReader. Pair[] inputArrayinputGenerator (n); Each number is represented as an object of the class Pair. The field first gives you the first (left) digit, and the field second gives you the second digit. You should also put the following piece of code above your main method and inside your public class private static class Pair int first int second public Pair (int first, int second) this.first first; this.second - second; public static Pair[] inputGenerator (int n) /* be careful to not modify this function / long last5000011; long multi 5000087; long mult25000167 Pair[] arrnew Pair[n] for (int i-0; i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!