AiTechWorlds
AiTechWorlds
Watch Bucket Sort distribute values into buckets, sort each, and concatenate — fast on uniform data.
def bucket_sort(a):
n = len(a)
buckets = [[] for _ in range(n)]
for x in a:
buckets[int(n * x)].append(x)
for bk in buckets:
bk.sort()
idx = 0
for bk in buckets:
for v in bk:
a[idx] = v; idx += 1Bucket Sort distributes elements into a number of buckets by value range, sorts each bucket, then concatenates them — fast when input is uniformly distributed.
| Best | O(n + k) |
| Average | O(n + k) |
| Worst | O(n²) |
| Space | O(n + k) |
| Stable | Yes |
| In-place | No |
The Bucket Sort Visualizer animates how Bucket Sort works: it distributes elements into several buckets by value range, sorts each bucket individually, then concatenates them in order. Bucket Sort runs in O(n + k) on average for uniformly distributed data, but O(n²) in the worst case. It is stable when the per-bucket sort is stable and uses O(n + k) extra space.
Generate an array
Click New Array or adjust the size slider for a random dataset.
Play the animation
Press Play to watch values distributed into buckets, then written back sorted.
Step and scrub
Step forward/back or drag the timeline to follow each placement.
Read the synced code
The highlighted pseudocode line tracks the distribute and concatenate phases; switch tabs for C++, Java, Python, or JavaScript.
100% Private — No Server Required
All processing happens directly in your browser. No data is uploaded, stored, or transmitted to any server.
Last reviewed on June 14, 2026 by the AiTechWorlds Tools Team. All processing runs locally in your browser.