Bubble sort: Difference between revisions

Content deleted Content added
Line 28:
Bubble sort should be avoided in the case of large collections. It will not be efficient in the case of a reverse-ordered collection.
 
===TortoiseRabbits and hareTurtles===
The distance and direction that elements must move during the sort determine bubble sort's performance because elements move in different directions at different speeds. An element that must move toward the end of the list can move quickly because it can take part in successive swaps. For example, the largest element in the list will win every swap, so it moves to its sorted position on the first pass even if it starts near the beginning. On the other hand, an element that must move toward the beginning of the list cannot move faster than one step per pass, so elements move toward the beginning very slowly. If the smallest element is at the end of the list, it will take {{math|''n''−1}} passes to move it to the beginning. This has led to these types of elements being named rabbits and turtles, respectively, after the characters in Aesop's fable of [[The Tortoise and the Hare]].