Question: Language: Java // Exercise 19.7 Solution: BucketSort.java // Sort an array's values into ascending order using bucket sort. import java.util.Random; public class BucketSort { //
Language: Java


![// You are provided with these declarations private int[] data; // array](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f5233579d79_36466f52334c6700.jpg)


// Exercise 19.7 Solution: BucketSort.java // Sort an array's values into ascending order using bucket sort. import java.util.Random; public class BucketSort { // You are provided with these declarations private int[] data; // array of values private static Random generator = new Random(); // create a constructor with an array and fill with random integers public BucketSort(int size) { } // perform the bucket sort algorithm on array public void sort() { // store maximum number of digits in numbers to sort // bucket array where numbers will be placed // loop through all digit places and sort each number // according to digit place value for (int pass = 1; pass 2 int bucketNumber = (element % divisor) / (divisor / 10); // retrieve value in pail[bucketNumber][0] to // determine which element of the row to store c[i] } // end for } // end method distributeElements // return elements to original array public void collectElements(int pails[][]) { // initialize location in data // loop over "buckets" // loop over elements in each bucket (column) // add element to array } // set all buckets to zero public void emptyBucket(int pails[][]) { // set size of bucket to 0 } // method to output values in array public String toString() { } } // end class BucketSortA BucketSort Overview Not all sorting algorithms are comparison sorts. The bucket sort is one such algorithm. Just like it sounds, a bucket sort places array items in buckets based on some formula or on a non-comparative set of steps A security application of this type of sort involves hashing algorithms, which are used in cryptographic applications. These typically map a key to a bucket using a formula. To learn more about hashing from an algorithmic and coding perspective, visit this course site: https://opendsa- server.cs.vt.edu/ODSA/Books/CS3/html/HashFuncExamp.html In this challenge, you will create a variant of the bucket sort with the BucketSort class (described below) and a BucketSortTest driver that will call the BucketSort sort method This bucket sort begins with a one-dimensional array of positive integers to be sorted. It also uses a two- dimensional array of integers with rows indexed from 0 to 9 and columns indexed from 0 to n 1, where n is the number of values to be sorted. The rows represent the buckets; the columns that create the two-dimensional array represent the numbers that will fill any particular bucket. The digits of each integer, from right to left, will be placed in buckets 0 to 9 based on their value in passes, processing one digit placeholder at a time. After each pass, the values are placed back in the original array by copying the values, in order, from the two-dimensional array back into the original array. After the leftmost digit is processed, the original array will be in order
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
