Bucket Sort
Definition:
Bucket sort is a comparison-based sorting algorithm that works by distributing elements into several "buckets" or ranges. Each bucket is sorted individually, either using another sorting algorithm or recursively applying bucket sort. Finally, the sorted buckets are concatenated to produce the final sorted array.
Video Explanation

Characteristics:
-
Distribution-Based Sorting:
- Bucket sort distributes elements into different buckets, typically based on their value ranges, and then sorts the individual buckets.
-
Efficient for Uniform Data Distribution:
- Bucket sort is efficient when the input elements are uniformly distributed across the range, as each bucket will contain a relatively even number of elements.
-
Not In-Place:
- Bucket sort uses additional memory for the buckets, making it not an in-place algorithm.
-
Stable:
- Bucket sort is stable when the underlying sorting algorithm used within each bucket is stable.
Time Complexity:
-
Best Case: O(n + k)
In the best case, where the elements are evenly distributed across the buckets, and each bucket contains only a few elements, the overall time complexity is linear. -
Average Case: O(n + k)
On average, bucket sort performs well when the elements are uniformly distributed. The average-case complexity is O(n + k), wherenis the number of elements andkis the number of buckets. -
Worst Case: O(n²)
The worst-case scenario occurs when all elements are placed in the same bucket, reducing bucket sort to a slower sorting algorithm (like insertion sort), leading to quadratic time complexity.
Space Complexity:
- Space Complexity: O(n + k)
Bucket sort requires extra space for the buckets and the array storing the final result, leading to a space complexity of O(n + k).