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

Conteúdo do Curso

Sorting Algorithms

Sorting Algorithms

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

Cocktail 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).

Tarefa

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

Tarefa

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

Mude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo

Tudo estava claro?

Seção 1. Capítulo 7
toggle bottom row

Cocktail 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).

Tarefa

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

Tarefa

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

Mude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo

Tudo estava claro?

Seção 1. Capítulo 7
toggle bottom row

Cocktail 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).

Tarefa

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

Tarefa

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

Mude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo

Tudo estava claro?

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).

Tarefa

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

Mude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Seção 1. Capítulo 7
Mude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
We're sorry to hear that something went wrong. What happened?
some-alt