El Akioui Zouhaire (Zoher)
2 min readDec 12, 2019

The Bucket Sort algorithm,will increase you application performance

The Bucket sort is a comparison sort algorithm that operates on elements by dividing them into different buckets and then sorting these buckets individually.

It makes assumptions about the data, like radix and counting sort,because it makes assumptions, also it can sort in O(n) time.

Performs best when hashed values of items being sorted are evenly distributed, so there aren’t many collision.

The value in bucket X must be greater than the values in bucket X-1, and less than the values in bucket X + 1.

For Bucket Sort phases:

1. Distributed the items into buckets based on their hashed values (scattering phase),

2. Sort the items in each bucket,

3. Merge the buckets — can just concatenate them (gathering phase).

Example:

We want to sort this array, using the three phases I mentioned above :

For its time complexity:

A- Not in-place, it needs creation of another array in memory.

B- Stability will depend on sort algorithm used to sort the buckets, ideally you want a stable sort.

C- To achieve O(n), it must have only one item per buckets, because it is fast when the number of items is small.

In closing, I share with an example of implementation on Github : her

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

El Akioui Zouhaire (Zoher)
El Akioui Zouhaire (Zoher)

Written by El Akioui Zouhaire (Zoher)

Software Engineer (Java/spring/angular/devops) with big passion for the business.

No responses yet

Write a response