Cocktail Sort: Bidirectional Bubble Sort Algorithm

Опубликовано: 31 Июль 2021
на канале: Stephen Melvin
4,182
134

The cocktail sort algorithm, also known as the cocktail shaker sort algorithm, shaker sort algorithm or bidirectional bubble sort algorithm, is a variation of bubble sort that alternates between left to right and right to left passes. In this video, I write the code for cocktail sort by combining the code for left to right and right to left passes from my right to left bubble sort algorithm video. I show how alternating directions solves a problem that holds back bubble sort and use visualisations to show what happens if the input is already sorted, almost sorted or reversed.

Sorting Algorithms playlist:    • Sorting Algorithms  

0:00 Overview
0:35 Showing bubble sort's weakness
3:01 Writing the cocktail sort code
3:57 Fixing the bug
5:21 Tidying up
6:19 Showing the already sorted case
6:36 Showing how it handles bubble sort's weakness
7:39 Showing the reverse order case
8:10 Showing the almost sorted case


На этой странице сайта вы можете посмотреть видео онлайн Cocktail Sort: Bidirectional Bubble Sort Algorithm длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Stephen Melvin 31 Июль 2021, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 4,182 раз и оно понравилось 134 зрителям. Приятного просмотра!