Shaker Sort Visualization


Shaker Sort - Sorting Algorithm Visualizer

DESCRIPTION

Shaker Sort, also known as **Cocktail Shaker Sort** or **Bidirectional Bubble Sort**, is a **comparison-based sorting algorithm** that extends Bubble Sort by sorting in both directions alternately.

The algorithm moves through the list in two phases: first, it moves from left to right, pushing the largest element to its correct position (like Bubble Sort). Then, it moves from right to left, pushing the smallest element to its correct position. This bidirectional movement helps reduce the number of passes needed compared to Bubble Sort.

Shaker Sort has a **worst-case and average time complexity of O(n²)**, making it inefficient for large datasets. However, for nearly sorted data, it can perform closer to **O(n)**, making it more efficient in such cases.

One advantage of Shaker Sort is that it **reduces the number of iterations** by moving in both directions, making it slightly more efficient than Bubble Sort. Like Bubble Sort, it is a **stable sorting algorithm** and works **in-place**, requiring no extra memory.

Although Shaker Sort is rarely used in practical applications, it is useful for educational purposes and for small datasets where a simple implementation is preferred.

COMPLEXITY

Average Complexity O(n²)
Best Case O(n)
Worst Case O(n²)
Space Complexity O(1)
Insertion Sort Visualization

Shaker SORT IMPLEMENTATION

                    
                
Shaker Sort Visualization