This question evaluates a candidate's understanding of sorting algorithms and algorithmic optimization, specifically implementation and enhancement of cocktail shaker sort, plus analysis of time and space complexity, stability, and counts of comparisons and swaps.
Implement the cocktail shaker sort (bidirectional bubble sort) for an array of integers. Optimize it with early termination and shrinking bounds, and include basic tests. Analyze time and space complexity, stability, and when it outperforms or underperforms standard bubble sort; provide worst-, average-, and best-case comparisons and swaps.