Bubble sort
Bubble sort has a worst-case and average complexity of O(n2), where n is the number of items sorted.
Bubble sort performance over an already sorted list is O(n).
The position of elements in bubble sort plays an important role in determining performance. Large elements at the beginning do not pose a problem as they are easily swapped. The small elements toward the end move to the beginning slowly. As such, these elements are called rabbits and turtles.
The bubble sort algorithm can be optimized by placing larger elements in the final position. After every pass, all elements after the last swap are sorted and do not need to be checked again, thereby skipping the tracking of swapped variables.
Exercise
Create and comment a 'Bubble Sort' algorithm to improve the effectiveness of code using appropriate data structures
Show an example of code you have produced that uses a 'bubble sort' algorithm with it clearly commented in python.