Bubble sort

Why is it called bubble sort?
larger elements "bubble" up to the top/end of the list

Green line seperates the ‘unsorted | sorted’ sections (unsorted left , sorted right)
‘12’ is largest and bubbled to end
‘8’ is largest in the unsorted section w/o ‘12’
‘7’ is largest in the unsorted section w/o ‘12’ & ‘8’
Compare consecutive indices
Swap the index if larger one is on the left
Largest index will bubble all the way right to the last index with each iteration
Sorted section will form at end of array
Time complexity : $O(n^2)$
Stable sorting algorithm
Last updated