Engineering Questions with Answers - Multiple Choice Questions

Home » MCQs » Chemical Engineering » Cocktail Sort MCQ’s

# Cocktail Sort MCQ’s

Cocktail sort is also known as ________________

a) bidirectional sort

b) bubble sort

c) brick sort

d) ripple sort

**
View Answer**

Answer: d

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.

Cocktail sort is a variation of _____________

a) Bubble sort

b) Selection sort

c) Insertion sort

d) Gnome sort

**
View Answer**

Answer: a

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.

Auxiliary space requirement of cocktail sort is _____________

a) O(n)

b) O(log n)

c) O(1)

d) O(n^{2})

**
View Answer**

Answer: c

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.

Which of the following sorting algorithm is NOT stable?

a) Quick sort

b) Cocktail sort

c) Bubble sort

d) Merge sort

**
View Answer**

Answer: a

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

Which of the following sorting algorithm is in place?

a) cocktail sort

b) merge sort

c) counting sort

d) radix sort

**
View Answer**

Answer: a

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.

Cocktail sort is a comparison based sort.

a) True

b) False

**
View Answer**

Answer: a

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

Cocktail sort uses which of the following methods for sorting the input?

a) selection

b) partitioning

c) merging

d) exchanging

**
View Answer**

Answer: d

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.

What is the worst case time complexity of cocktail sort?

a) O(n)

b) O(n log n)

c) O(n^{2})

d) O(log n)

**
View Answer**

Answer: c

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.

What is the best case time complexity of cocktail sort?

a) O(n)

b) O(n log n)

c) O(n^{2})

d) O(log n)

**
View Answer**

Answer: a

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.

What is the average case time complexity of odd-even sort?

a) O(n)

b) O(n log n)

c) O(n^{2})

d) O(log n)

**
View Answer**

Answer: c

Explanation: Cocktail sort takes O(n^{2}) 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.

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

**
View Answer**

Answer: a

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.

. 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

**
View Answer**

Answer: c

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.

Bubble sort performs better as compared to cocktail sort.

a) True

b) False

**
View Answer**

Answer: b

Explanation: Both bubble sort and cocktail sort has the same time complexities. But cocktail sort has a comparatively better performance