Java: Bucket Sort Algorithm
19. Bucket Sort Implementation
Write a Java program to sort an array of given integers using the Bucket Sort Algorithm.
Bucket sort is a sorting algorithm that distributes the elements of an array into a number of buckets. Each bucket is then sorted individually, either using a different sorting algorithm, or by recursively applying the bucket sorting algorithm. It is a distribution sort, a generalization of pigeonhole sort, and a cousin of radix sort in the most-to-least significant digit flavor.
Sample Solution:
Java Code:
Sample Output:
Original Array: [14, -15, 15, 17, 32, -4, 33, -42, 38, -36] Sorted array: [-42, -36, -15, -4, 14, 15, 17, 32, 33, 38]
Flowchart:

For more Practice: Solve these Related Problems:
- Write a Java program to implement bucket sort and distribute the elements into buckets based on a computed range.
- Write a Java program to modify bucket sort to sort floating-point numbers by normalizing them into buckets.
- Write a Java program to implement bucket sort and then merge the sorted buckets into a single sorted array.
- Write a Java program to optimize bucket sort for uniformly distributed data and analyze its average-case performance.
Go to:
PREV : Stooge Sort Implementation.
NEXT : Java Regular Expression Exercises Home
Java Code Editor:
Contribute your code and comments through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.