Online Course Discussion Forum

By the 2 direction bubble sort, do you mean the cocktail sort?

 
 
Picture of Joseph Quan
By the 2 direction bubble sort, do you mean the cocktail sort?
by Joseph Quan - Friday, 26 June 2020, 9:07 AM
 

Do you mean the 2 direction bubble sort, or the original bubble sort.

 
Picture of John Lensmire
Re: By the 2 direction bubble sort, do you mean the cocktail sort?
by John Lensmire - Friday, 26 June 2020, 12:29 PM
 

Hi Joseph. I'd rather not worry about specific names, so as an example, if we had the list$$[A, B, C, D, E, F, G, H]$$a normal bubble sort would start by comparing positions $A,B$ then positions $B,C$, etc. up to positions $G,H$ and then continue back at the start with $A,B$ again.

For a two direction bubble sort, it starts the same, $A,B$, then $B,C$ up to $G,H$, but then reverses and works it's way back "down" the list, comparing $F,G$, then, $E,F$, etc.

To summarize, a regular bubble sort keeps looping through list in the same direction ("up" over and over) while the two direction swaps after each pass ("up", "down", "up", "down", etc.)

Hope this helps!