Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Cocktail Sort | Simple Algorithms
Sorting Algorithms
course content

Course Content

Sorting Algorithms

Sorting Algorithms

1. Simple Algorithms
2. Divide and Conquer Algorithms
3. Problems

bookCocktail Sort

Cocktail sort is another kind of Bubble sort. In Bubble sort, we traverse the array from left to right to push the greatest element to the end of the unsorted part. In Cocktail sort, we do iterations in both directions: first move the greatest element to the right, then move the least element to the left, and then repeat it again until array is sorted.

Example 1

Time Complexity: O(N^2).

Space Complexity: O(1).

Task

Follow the comments to complete the Cocktail Sort algorithm. Add missing lines to code.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 7
toggle bottom row

bookCocktail Sort

Cocktail sort is another kind of Bubble sort. In Bubble sort, we traverse the array from left to right to push the greatest element to the end of the unsorted part. In Cocktail sort, we do iterations in both directions: first move the greatest element to the right, then move the least element to the left, and then repeat it again until array is sorted.

Example 1

Time Complexity: O(N^2).

Space Complexity: O(1).

Task

Follow the comments to complete the Cocktail Sort algorithm. Add missing lines to code.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 7
toggle bottom row

bookCocktail Sort

Cocktail sort is another kind of Bubble sort. In Bubble sort, we traverse the array from left to right to push the greatest element to the end of the unsorted part. In Cocktail sort, we do iterations in both directions: first move the greatest element to the right, then move the least element to the left, and then repeat it again until array is sorted.

Example 1

Time Complexity: O(N^2).

Space Complexity: O(1).

Task

Follow the comments to complete the Cocktail Sort algorithm. Add missing lines to code.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Cocktail sort is another kind of Bubble sort. In Bubble sort, we traverse the array from left to right to push the greatest element to the end of the unsorted part. In Cocktail sort, we do iterations in both directions: first move the greatest element to the right, then move the least element to the left, and then repeat it again until array is sorted.

Example 1

Time Complexity: O(N^2).

Space Complexity: O(1).

Task

Follow the comments to complete the Cocktail Sort algorithm. Add missing lines to code.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Section 1. Chapter 7
Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
some-alt