Comparison of sorts
It is important to understand that different algorithmA sequence of logical instructions for carrying out a task. In computing, algorithms are needed to design computer programs. might be best used in different situations. For example, sometimes an algorithm won’t work with a particular set of dataUnits of information. In computing there can be different data types, including integers, characters and Boolean. Data is often acted on by instructions., and in some instances one algorithm will be much quicker or more efficient than another.
Bubble sort
One of the main advantages of a bubble sortA sorting algorithm that repeatedly passes through a list to be sorted, comparing and swapping items that are in the wrong order. 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 programSequences of instructions for a 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.
Bucket sort
One of the main advantages of a bucket sortA sorting algorithm that separates data into different collections, called buckets, which are filled with data and then sorted. 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 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