Cocktail sort can be considered as an extension to Bubble Sort Algorithm.Here instead of moving in one direction from left to right we move in the opposite direction right to left.Cocktail sort will be faster than bubble sort, but it will not change the complexity.The complexity will be still O(n^2).Our algorithm uses “is_swapped” variable to know if the array is sorted or not.The sorted array need not do any swapping.Hence taking that as a basis we terminate the main loop.Time complexity is O(n^2).In the first pass, lowest element is at the left and the highest element is at the right.In the second pass, the array is sorted.