Implement cocktail shaker sort and analyze
UiPathMachine Learning Engineer · Technical ScreenLast updated
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.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.