Engineering Questions with Answers - Multiple Choice Questions

# Cocktail Sort Multiple Choice MCQ

1 - Question

Cocktail sort is also known as ________________
a) bidirectional sort
b) bubble sort
c) brick sort
d) ripple sort

Explanation: Cocktail sort is also known by the name of ripple sort. It is also known by other names like – bidirectional bubble sort, cocktail shaker sort, shuttle sort, shuffle sort etc.

2 - Question

Cocktail sort is a variation of _____________
a) Bubble sort
b) Selection sort
c) Insertion sort
d) Gnome sort

Explanation: Cocktail sort is very similar to bubble sort. It works by traversing an array in both directions alternatively. It compares the adjacent elements in each iteration and swaps the ones which are out of order.

3 - Question

Auxiliary space requirement of cocktail sort is _____________
a) O(n)
b) O(log n)
c) O(1)
d) O(n2)

Explanation: In cocktail sort manipulation is done on the input array itself. So no extra space is required to perform sorting. Thus it requires constant auxiliary space.

4 - Question

Which of the following sorting algorithm is NOT stable?
a) Quick sort
b) Cocktail sort
c) Bubble sort
d) Merge sort

Explanation: Out of the given options quick sort is the only algorithm which is not stable. Cocktail sort like bubble sort is a stable sorting algorithm.

5 - Question

Which of the following sorting algorithm is in place?
a) cocktail sort
b) merge sort
c) counting sort

Explanation: Cocktail sort is an in place sorting technique as it only requires constant auxiliary space for manipulating the input array. Rest all other options are not in place.

6 - Question

Cocktail sort is a comparison based sort.
a) True
b) False

Explanation: Cocktail sort compares the value of different elements in the array for sorting. Thus, it is a comparison based sort.

7 - Question

Cocktail sort uses which of the following methods for sorting the input?
a) selection
b) partitioning
c) merging
d) exchanging

Explanation: Cocktail sort uses a method of exchanging as it swaps the elements which are out of order. This swapping is done in two phases i.e. forward phase and backward phase.

8 - Question

What is the worst case time complexity of cocktail sort?
a) O(n)
b) O(n log n)
c) O(n2)
d) O(log n)

Explanation: Worst case complexity is observed when the input array is reverse sorted. This is the same as the worst case complexity of bubble sort.

9 - Question

What is the best case time complexity of cocktail sort?
a) O(n)
b) O(n log n)
c) O(n2)
d) O(log n)

Explanation: Best case complexity is observed when the input array is already sorted. This is the same as the best case complexity of bubble sort.

10 - Question

What is the average case time complexity of odd-even sort?
a) O(n)
b) O(n log n)
c) O(n2)
d) O(log n)

Explanation: Cocktail sort takes O(n2) time on average as it keeps on applying bubble sort on the elements in two phases until they are sorted. This is the same as the average time complexity of bubble sort.

11 - Question

How many iterations are required to sort the array arr={2,3,4,5,1} using bubble sort and cocktail sort respectively?
a) 4,2
b) 5,3
c) 5,2
d) 4,3

Explanation: Cocktail sort applies bubble sort in two phases until the array gets sorted. So here bubble sort will take 4 iterations to sort the given array whereas cocktail sort takes only 2 iterations. This shows cocktail sort has a comparatively better performance.

12 - Question

The following function represents which sorting?

void Sorting(int a[], int n)
{
bool swap = true;
int first = 0;
int last = n - 1;

while (swap)
{

swap = false;

for (int i = first; i < last;i++)
{
if (a[i] > a[i + 1])
{
swap(a[i], a[i + 1]);
swap = true;
}
}

if (!swap)
break;

swap = false;

--last;

for (int i = last - 1; i >= first; i--)
{
if (a[i] > a[i + 1])
{
swap(a[i], a[i + 1]);
swap = true;
}
}

++first;
}
}

a) Bubble sort
b) Selection sort
c) Bidirectional bubble sort
d) Odd-even sort

Explanation: The given function represents bidirectional bubble sort also known as cocktail sort. In this sort, we apply bubble sort in two phases i.e. forward and backward phase until the array gets sorted.

13 - Question

Bubble sort performs better as compared to cocktail sort.
a) True
b) False