SortingComparison of sorts

Putting data into order can be difficult and time consuming. Sorting algorithms, such as bubble sort and bucket sort can help with this.

Part ofComputer ScienceAlgorithms

Comparison of sorts

It is important to understand that different might be best used in different situations. For example, sometimes an algorithm won’t work with a particular set of , and in some instances one algorithm will be much quicker or more efficient than another.

Bubble sort

One of the main advantages of a is that it is a very simple algorithm to describe to a computer. There is only really one task to perform (compare two values and, if needed, swap them). This makes for a very small and simple computer .

The biggest problem with a bubble sort is that it takes a very long time to run. For example, if there are 100 values to sort, each pass through the list will take 99 comparisons – and you might have to repeat it 99 times.

sort image showing first, second, third pass with digits being swapped

Bucket sort

One of the main advantages of a is that is quicker to run than a bubble sort. Putting data into small buckets that can be sorted individually reduces the number of comparisons that need to be carried out.

The final part of the bucket sort process is to sort the numbers in each bucket and go through them in order.

The biggest problem with a bucket sort is that the algorithm is a bit more complicated than the bubble sort to describe for a computer. It might be easy to decide to sort numbers in groups of 10, but what about a list of names? Should there be a bucket for each letter of the alphabet, or perhaps one bucket for all of the X, Y and Z names because there aren’t many of those?

More sorting algorithms

There are lots and lots of different sorting algorithms. Many of these use clever ideas to make sorting lists much quicker, although the algorithms can get very complicated at times.

Other sorting algorithms include the:

  • merge sort
  • insertion sort
  • shell sort
  • quick sort