Bubble Sort
Adding to the list of sorting algorithms that I have shared, here is another famous sorting algorithm that everyone comes across whether its your academic career or professional life. If would like to see the post where I shared ‘Insertion sort’ in detail, you can check the story below:
As the name indicates, in bubble sort, we work in a bubble of 2. Like a sliding window, we keep on comparing the 2 numbers in the bubble and slide this bubble towards right, until we reach the very last number. This would then conclude the pass 1 of sorting where the biggest most element of the array reaches its correct position as the last element in the array.
Let us take an example and see how this works.
1. Given an unsorted array with n elements
2. We would create a bubble of 2 numbers starting with the first 2 and compare them.
3. If the second number is less than the first one, we would swap the number otherwise, just slide the bubble over to the 2nd and 3rd number as depicted in the following image.