Зміст курсу
Sorting Algorithms
Sorting Algorithms
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).
Завдання
Follow the comments to complete the Cocktail Sort algorithm. Add missing lines to code.
Дякуємо за ваш відгук!
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).
Завдання
Follow the comments to complete the Cocktail Sort algorithm. Add missing lines to code.
Дякуємо за ваш відгук!
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).
Завдання
Follow the comments to complete the Cocktail Sort algorithm. Add missing lines to code.
Дякуємо за ваш відгук!
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).
Завдання
Follow the comments to complete the Cocktail Sort algorithm. Add missing lines to code.