PROGRAM DESCRIPTION
Implement the combined O(n) radix/bucket sort as described in class. (i.e. divide the input by radix, bucket sort (with no insertion sort step) once for each radix starting from the least significant. Make sure that your overall implementation is O(n)
NPUT
The input to your program will an unspecified number of entries. Each entry is a non-negative integer containing nine (zero padded) digits ( this means that the integer may have either leading or trailing zeros), one per line. Read your input from STDIN.
OUTPUT
Send the values, one per line, as they were input (all nine digits including leading zeroes, if any), sorted in ascending order, to STDOUT. The only output of your program is the numeric results. (i.e. don't output your name, assignment number, prompts etc.)
NOTES
You may use vectors for your buckets.
CODE:
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class BucketSort {
public static void main(String[] args) {
Scanner getInput = new Scanner(System.in);
System.out.println("Enter total number of values you want to sort");
int arraySize = getInput.nextInt();
List numbers = new ArrayList<>();
System.out.println("Enter " + arraySize + " values");
for (int i = 0; i < arraySize; i++) {
int num = getInput.nextInt();
numbers.add(num);
}
System.out.println("Sorted values...");
for (Integer value : sort(numbers, numbers.size())) {
System.out.println(value);
}
}
public static List sort(List array, int bucketSize) {
if (array.size() == 0) {
return null;
}
// Determine minimum and maximum
valuesInteger minValue = array.get(0);
Integer maxValue = array.get(0);
for (int i = 1; i < array.size(); i++) {
if (array.get(i) < minValue) {
minValue = array.get(i);
}
else if (array.get(i) > maxValue) {
maxValue = array.get(i);
}
}
// Initialise buckets
int bucketCount = (maxValue - minValue) / bucketSize + 1;
List> buckets = new ArrayList>(bucketCount);
for (int i = 0; i < bucketCount; i++) {
buckets.add(new ArrayList());
}
// Distribute input array values into buckets
for (int i = 0; i < array.size(); i++) {
buckets.get((array.get(i) - minValue) / bucketSize).add(array.get(i));
}
// Sort buckets and place back into input array
int currentIndex = 0;
array.clear();
for (int i = 0; i < buckets.size(); i++) {
Integer[] bucketArray = new Integer[buckets.get(i).size()];
bucketArray = buckets.get(i).toArray(bucketArray);
InsertionSort.sort(bucketArray);
for (int j = 0;
j < bucketArray.length; j++) {
array.add(currentIndex++, bucketArray[j]);
}
}
return array;
}
static class InsertionSort {
public static > void sort(T[] array) {
for (int i = 1; i < array.length; i++) {
T item = array[i];
int indexHole = i;
while (indexHole > 0 && array[indexHole - 1].compareTo(item) > 0) {
array[indexHole] = array[--indexHole];
}
array[indexHole] = item;
}
}
}
}
PROGRAM DESCRIPTION Implement the combined O(n) radix/bucket sort as described in class. (i.e. divide the input...
Java, Please implement the way the interface specifies. Part A:Radix Sort Implement a radix sort as described in the last section of Chapter 7 in your text. It should handle variable amounts of data and variable numbers of digits in the key values. Use testing to ensure radix sort works for at least three examples of different input sizes and various max digit length. I need to implement the radix sort using the below java interface. /** * <h1><LeastSignificantDigit Radix...
Objective: Implement a sorting algorithm. Description: Implement a radix sort in a Java class named RadixSort.java. Your program should receive its input from a file named "input.txt", which contains one integer per line. It should produce a sorted output file named "output.txt". Include a main method which demonstrates that your algorithm works.
Need a quick solution to this in Java!
OPTION 2: RADIX SORT TESTING Write a version of Radix Sort to sort an ArrayList or array of ints / Integers that you will place in a file. The integers should all be four digits long. Run the algorithm on at least 3 different files, of different sizes (i.e., each file should have a different number of integers) and have it print the results. The minimum file size should be 20 integers....
Description: An ISBN-10 (International Standard Book Number) consists of 10 digits: didzdzdad5d6d7d8d9d1o. The last digit, dio, is a checksum, which is calculated from the other nine digits using the following formula: (d, x 1 + d2 x 2 +d3 x 3 + da x4 + ds x 5 + de x 6 + d7 x 7+ d3 x 8+dex 9) % 11 If the checksum is 10, the last digit is denoted as X according to the ISBN-10 convention. Write...
Implement quicksort and bucket sort. Use the code in your book to help; the partition in quicksort is tricky. Make sure your implementations are correct — it is easy to gain some confidence in the correctness of your code by writing a program which creates arrays filled with random numbers, sorts them, and then checks that they are sorted. Then time your code (using clock() or similar methods) on both methods for arrays filled with random integers of the following...
PROGRAM DESCRIPTION Implement a hash table class. Your hash table should resolve collisions by chaining and use the multiplication method to generate hash keys. You may use your own linked list code from a previous assignment or you can use a standard sequence container. Partial definitions for the hash table class and a generic data class are provided (C++ and Java versions). You may use them as a starting point if you wish. If you choose to design your own...
IN PYTHON 3: In this version of Radix Sort we use Queues very naturally. Let us consider the following set of positive integers: 311, 96, 495, 137, 158, 84, 145, 63 We will sort these numbers with three passes. The number of passes is dependent on the number of digits of the largest number - in this case it is 495. In the first pass we will go through and sort the numbers according to the digits in the units...
LINUX C programming Please make sure the output is correct Please do read data from file, the example below is just a example Third: Hash table (20 points) In this part, you will implement a hash table containing integers. The hash table has 10,000 buckets. An important part of a hash table is collision resolution. In this assignment, we want you to use chaining with a linked list to handle a collision. This means that if there is a collision...
Ques) Write a program in c, which meets the following
requirements.
Requirements 1. Read integer values from stdin, separated by one or more spaces or newlines, until reaching EOF 2. The input is guaranteed to be well-formed. 3. The input contains no more than 80 values. 4. on standard output, render a simple vertical column graph representation of the input values, in order left to right, using hash'#' characters as shown in the examples below. The number of hashes printed...
Problem Description proving program correctness Consider the following program specification: Input: An integer n > 0 and an array A[0..(n - 1)] of n integers. Output: The smallest index s such that A[s] is the largest value in A[0..(n - 1)]. For example, if n = 9 and A = [ 4, 8, 1, 3, 8, 5, 4, 7, 2 ] (so A[0] = 4, A[1] = 8, etc.), then the program would return 1, since the largest value in...