NICERC’s Computer Science curriculum covers several traditional sorting algorithms that can be used to sort a list of items. One of the covered algorithms in the curriculum is bubble sort.
Bubble sort makes pairwise comparisons that result in larger numbers “bubbling” to the end of the list. A traditional bubble sort must iterate a specific number of times to guarantee the list is sorted when the algorithm terminates. Optimized bubble sort potentially shortens the length of a bubble sort by including a variable that stores whether or not a swap was made during an iteration. If no swaps are made during an iteration, the algorithm terminates since the lack of a swap would indicate that the items are already sorted.
Check out this video for a visualized example of an optimized bubble sort.