Cocktail shaker sort [SEP] based on
Cocktail shaker sort
Cocktail shaker sort, also known as bidirectional bubble sort, cocktail sort, shaker sort (which can also refer to a variant of selection sort), ripple sort, shuffle sort, or shuttle sort, is a variation of bubble sort that is both a stable sorting algorithm and a comparison sort. The algorithm differs from a bubble sort in that it sorts in both directions on each pass through the list. This sorting algorithm is only marginally more difficult to implement than a bubble sort, and solves the
limit and the algorithm has shorter passes. As the cocktail shaker sort goes bidirectionally, the range of possible swaps, which is the range to be tested, will reduce per pass, thus reducing the overall running time slightly.
Complexity.
The complexity of the cocktail shaker sort in big O notation is formula_1 for both the worst case and the average case, but it becomes closer to formula_2 if the list is mostly ordered before applying the sorting algorithm. For example, if every element is at a position that differs