Bubble Sort is an algorithm used to sort an array or list that is considered to have a complexity O(n²). It compares adjacent elements and switches them if they are out of order. Each iteration through the list places the next largest element in its proper place. In essence, each item “bubbles” up to its proper order.

How it Works:

Given a list (or array), selection sort iterates over the list (referred to as a pass) until it is sorted. On each pass, a comparison is made to the adjacent element and switches them if the element on the left is larger than that on the right. The passes continue until there are no more switches to be made, as the list is finally sorted.

Below is a nice gif that shows this process (See my Python implementation at bottom):

bubble sort