There are various ways of sorting a list, for example:
- bubble sort
- merge sort
- shell sort
- insertion sort
- quick sort
The bubble sort is one method we can use to sort a list.
For example, we want to sort the list below:
In this course we will look at the bubble sort and insertion sort (required by the AQA A-Level specification) and the quick sort (required by the OCR A-Level specificaton).
Here is the algorithm for the bubble sort:
1 2 3 4 5 6 7 8 9 10 11 12 13
Implementing a bubble sort in Python
- Implement the bubble sort from the pseudocode. Follow the video if you need to.
- Extend your program by adding a counter to count the number of comparisons.
- Compare your count with the insertion sort (next page) to see which is the most efficient sort.