Introduction to bubble sort
Bubble sort, also known as sinking sort, is one of the simplest sorting algorithms that works by moving an item to its correct position by comparing it against the element that comes after it. If the current element is larger than the element after it, the two are swapped, pushing the larger value one step toward the end. This process is repeated until no more swaps need to be performed in a pass, resulting in a final sorted list (in ascending order).
Why is this sort called bubble sort?
This process is similar to how bubbles rise to the surface of water, where the lighter bubbles move upwards while the heavier ones sink. In Bubble sort, the smaller (or lighter) elements "bubble" to the front of the list, while the larger (or heavier) elements "sink" to the end.
This process is similar to how bubbles rise to the surface of water, where the lighter bubbles move upwards while the heavier ones sink. In Bubble sort, the smaller (or lighter) elements "bubble" to the front of the list, while the larger (or heavier) elements "sink" to the end.
Heavier bubble sinks down
Example
An example of this sorting process in action would be if you were a teacher tasked with organising a queue of students by their heights (shortest at the front, tallest at the back).
Liking the course? Check our discounted plans to continue learning.