Essay record
Sorting Algorithms: Bubble Sort
- Record
- Essay / / 1 min read / 242 words
- Tags
- Unfiled
DISCLOSURE: Some links may be affiliate links. Details
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