Sie sind auf Seite 1von 9

Cocktail Shaker Sorting

Shivam Prasher | 002


Tarkesh Dewangan | 004
Kevin Bobby | 005
Bhawna Arya | 007
Hari Narayanan | 017
Aditya Sreenath | 019
Sorting
~ What is sorting?
Sorting is nothing but storage of data in sorted order, it can be in
ascending or descending order.

~ Why do we need sorting?


The term Sorting comes into picture with the term Searching.

~ Why do we have so many sorting techniques?


We have different ones to meet various different sorting requirements
like minimal time and space, array and linked list sorting, etc
Sorting Visualisation
Cocktail Sorting
~ Variation of Bubble Sort
It sorts in both directions on each passes through the list from bottom to top
and then from top to bottom, hence called bi-directional bubble sort .

~ Stable Sorting Algorithm


Unlike other sorting techniques, cocktail sort can be used to sort alphanumeric
datas both signed and unsigned.

~ Comparison Sort
Cocktail Sort uses the method of comparing adjacent datas and then
swapping, hence comparison / exchange sort
Bubble Sort

Cocktail Shaker
Sort
Implementation
procedure cocktail_sort(a[], n) // a[] = list of sortable items & n =
number of elements
{
flag=true;
do{
flag=false
for each i=n-1 to 0, do : // Left to Right
if a[i-1] > a[i]
//swap both & flag=true

for each i=1 to n, do : // Right to Left


if a[i-1] > a[i]
//swap both & flag=true

}while flag==true // sort until no exchanges take place


}
Complexity Analysis
o To analyse the complexity of Cocktail Sort, we can
count the number of comparisons between pair of
elements, do a step count analysis, or proceed
directly to do an asymptotic analysis.

o Both space and time complexity are the same as


that of the Bubble Sort for exactly the same
reasons. That is time complexity is O(n) and space
complexity is O(1) .
Advantages & Disadvantages
It is easy to implement It does not deal well with a list
Elements are swapped in place containing a huge number of items.
without using additional temporary It requires n-squared processing
storage. steps for every n number of
They are more efficient and elements to be sorted.
faster than normal bubble sort It is mostly suitable for academic
The space requirement is teaching but not for real-life
minimum applications.
THANK YOU !

Das könnte Ihnen auch gefallen