Bucket Sort Visualizer

Visualize Bucket Sort distributing values, sorting buckets, and gathering results with interactive playback and operation insights.

Current status: Sending the highlighted value to bucket 1.

Comma-separated numbers, up to 20 values.

Balanced

Live operation

distribute

Step 1 / 20
42
[0]
7
[1]
99
[2]
15
[3]
76
[4]
38
[5]
58
[6]
12
[7]
Distribute valueActive bucketMerge outputSorted

Distribution buckets

bucket 0

bucket 1

42

bucket 2

Merged output

Waiting for merge…

Comparisons

0

Moves / writes

0

Confirmed sorted

0 / 8

Algorithm notes

What to watch for

Bucket Sort works best when input values are spread fairly evenly across a known range. Good distribution keeps individual buckets small and cheap to sort.

Concept guide

Review the mental model, tradeoffs, and practical use cases after you experiment.

Bucket Sort Complete Info Card

Scatter-GatherDistribution Based

Bucket Sort works by distributing elements into multiple buckets, sorting individual buckets (typically using another algorithm), then combining results. Ideal for uniformly distributed data like floating-point numbers.

Algorithm Characteristics

Time Complexity (Best)

Uniform element distribution

O(n + k)

Time Complexity (Average)

Balanced bucket sizes

O(n + n²/k)

Time Complexity (Worst)

All elements in one bucket

O(n²)

Space Complexity

Bucket storage + sorting

O(n + k)

Stable

Based on internal sort used

Depends

In-Place

Requires auxiliary buckets

No

Sorting Process Steps

1

Create empty buckets (array of lists)

2

Calculate bucket range from max value

3

Distribute elements into buckets

4

Sort individual buckets (e.g., Insertion Sort)

5

Concatenate sorted buckets

Key Features & Trade-offs

FeatureAdvantagesConsiderations
Uniform DistributionOptimal performanceRequires known data distribution
Bucket CountMore buckets = better performanceMemory trade-off
Hybrid ApproachCombines scatter-sort-gatherMultiple algorithms involved
Floating PointsExcellent for [0,1) rangeNeeds value normalization
AdaptiveAdjusts to data characteristicsRequires careful tuning

Optimal Use Cases

  • Uniformly distributed floating-point numbers
  • When data characteristics are known
  • External sorting scenarios

When to Avoid

  • Non-uniform data distributions
  • Small datasets (overhead not justified)
  • Memory-constrained environments
Pro Tip: Bucket Sort's efficiency peaks when the number of buckets (k) ≈ number of elements (n). Use Insertion Sort for individual buckets when dealing with small bucket sizes.
Distribution SortAdaptiveHybrid Approach