Bubble sort is an algorithm to sort a list through repeated swaps of adjacent elements. It has a runtime of
For nearly sorted lists, bubble sort performs relatively few operations since it only performs a swap when elements are out of order.
Bubble sort is a good introductory algorithm which opens the door to learning more complex algorithms. It answers the question, “How can we algorithmically sort a list?” and encourages us to ask, “How can we improve this sorting algorithm?”
Does bubble sort have to sort in ascending order?