Essay - Published: 2013.10.09 | 1 min read (242 words)
DISCLOSURE: If you buy through affiliate links, I may earn a small commission. (disclosures)
Bubble Sort
Bubble sort moves through the data set, comparing each pair of adjacent elements. If they are in the wrong order, it swaps them. It iterates through the data “bubbling” the largest piece of data to the top.
****In-Place: yes
Online: No
Stable: Yes
Big O: Best O(n), Worst O(n^2)
Example:
5 3 13 7 9 2 6
3 5 13 7 9 2 6
3 5 13 7 9 2 6
3 5 7 13 9 2 6
3 5 7 9 13 2 6
3 5 7 9 2 13 6
3 5 7 9 2 6 | 13
3 5 7 9 2 6 | 13
3 5 7 2 9 6 | 13
3 5 2 7 9 6 | 13
3 5 2 7 9 6 | 13
3 5 2 7 6 | 9 13
3 5 2 7 6 | 9 13
3 2 5 7 6 | 9 13
3 2 5 7 6 | 9 13
3 2 5 6 | 7 9 13
2 3 5 6 | 7 9 13
2 3 5 6 | 7 9 13
2 3 5 | 6 7 9 13
2 3 5 | 6 7 9 13
2 3 | 5 6 7 9 13
2 3 5 6 7 9 13
The best way to support my work is to like / comment / share this post on your favorite socials.