@@ -0,0 +1,2004 @@
+/*%0AIntro to Algo-%0A*Bucket sort or bin sort is a sorting algorithm that works by distributing the elements into a number of buckets, homogenously. Each bucket is then sorted individually. In order to sort the bucket, we use the sort() method of the Arrays class. It is usually used to sort floating-point numbers.%0AImplementation technique-%0AThe basic idea to perform the bucket sort is:%0A  1)Partition the range into a fixed number of buckets.%0A  2)Toss each element into its appropriate bucket.%0A  3)Sort each bucket individually using insertion sort.%0A  4)Concatenate all the sorted buckets.%0ATime Complexity-%0AWorst Case:%09O(n2)%0ABest Case:%09O(n+k)%0AAverage Case:%09O(n+k)%0A*/%0Aimport java.util.*;  %0Apublic class BucketSortalgo %0A%7B  %0A//user-defined method to sort array  %0Aprivate static void binSort(int%5B%5D array, int bucketSize)  %0A%7B  %0A//creating a list of buckets for storing lists  %0AList%3CInteger%3E%5B%5D buckets = new List%5BbktSize%5D;  %0A// Linked list with each bucket array index  %0A// as there may be hash collision   %0Afor(int i = 0; i %3C bktSize; i++)  %0A%7B  %0Abuckets%5Bi%5D = new LinkedList%3C%3E();  %0A%7D  %0A//calculate the hash and assigns elements to the proper bucket  %0Afor(int num : array)  %0A%7B  %0Abuckets%5Bhash(num, bktSize)%5D.add(num);  %0A%7D  %0A//iterate over the buckets and sorts the elements  %0Afor(List%3CInteger%3E bucket : buckets)  %0A%7B  %0A//sorts the bucket      %0ACollections.sort(bucket);  %0A%7D  %0Aint index = 0;  %0A//gethered the buckets after sorting  %0Afor(List%3CInteger%3E bucket : buckets)  %0A%7B  %0Afor(int num : bucket)  %0A%7B  %0Aarray%5Bindex++%5D = num;  %0A%7D  %0A%7D  %0A%7D  %0A//distributing elements   %0Aprivate static int hash(int num, int bucketSize)  %0A%7B  %0Areturn num/bucketSize;  %0A%7D  %0Apublic static void main(String args%5B%5D)   %0A%7B  %0A//array to be sort      %0Aint%5B%5D array = %7B22, 45, 12, 8, 10, 6, 72, 81, 33, 18, 50, 14, 55, 0, 12, 55%7D;  %0ASystem.out.println(%22Unsorted Array: %22 + Arrays.toString(array));  %0A//calling the user-defined method to sort the array  %0AbinSort(array, 10);  %0ASystem.out.println(%22Sorted Array: %22 + Arrays.toString(array));  %0A%7D  %0A%7D  %0A

Create bucketsort.java