I am learning bubble sort. And I tend to forget about the type of sort everytime. So I am trying to find the logical meaning of each sort so that it helps in recalling the logic of sort :
I could not understand exact meaning that why bubble sort is named bubble sort?
Bubble sort algorithm, also known as sinking sort, is the simplest sorting algorithm that runs through the list repeatedly, compares adjacent elements, and swaps them if they are out of order.
This algorithm is called selection sort because it repeatedly selects the next-smallest element and swaps it into place.
Bubble sort starts with very first two elements, comparing them to check which one is greater. ( 5 1 4 2 8 ) –> ( 1 5 4 2 8 ), Here, algorithm compares the first two elements, and swaps since 5 > 1. ( 1 5 4 2 8 ) –> ( 1 4 5 2 8 ), Swap since 5 > 4. ( 1 4 5 2 8 ) –> ( 1 4 2 5 8 ), Swap since 5 > 2.
The term “Bubble Sort ” was first used by Iverson in 1962 [5]. Invariant: At the end of ith iteration, the last i elements contain i largest elements. i.e. a[n] contains the largest, a[n − 1] contains the second largest, and so on. At the end of nth iteration, the array is sorted as it contains n largest elements.
Why is it called bubble sort?
The bubble sort gets its name because elements tend to move up into the correct order like bubbles rising to the surface.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With