Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts Of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

4th Edition

ISBN: 0619064625, 978-0619064624

More Books

Students also viewed these Databases questions