Data Structures & Algorithms Multiple Choice Questions on “Stooge Sort”.
1. Which one of the following sorting algorithm requires recursion? Answer: b 2. What is the recurrence relation for stooge sort? 3. In which of the following case stooge sort is most efficient (in terms of time complexity)? Answer: d 4. What is the space complexity of stooge sort? Answer: a 5. What is the first step in the algorithm of stooge sort(after base case)? Answer: d 6. Stooge sort is a comparison based sorting algorithm. 7. Stooge sort is a stable sorting algorithm. Answer: b 8. What is the average time complexity of stooge sort? 9. How many recursive statements are used in the algorithm of stooge sort? Answer: d 10. Which of the following sorting algorithm has the same time complexity in every case? Answer: a 11. Which of the following sorting algorithm is worst in terms of time complexity? Answer: d 12. Which of the following is not an adaptive sorting algorithm? Answer: c 13. Choose the correct function for stooge sort? b) c) d)
a) odd even sort
b) stooge sort
c) selection sort
d) counting sort
Clarification: Stooge sort requires the use of recursion for implementing its algorithm. On the other hand, the sorting algorithms given in the remaining options use iterative methods.
a) T(n) = 2T(2/3n) + O(n)
b) T(n) = 2T(2/3n) + O(1)
c) T(n) = 3T(2/3n) + O(n)
d) T(n) = 3T(2/3n) + O(1)
Answer: d
Clarification: In stooge sort recursion is applied to 2/3 part of the array 3 times. Rest of the portion of code has a constant time complexity. So the overall recurrence relation becomes T(n) = 3T(2/3n) + O(1).
a) when input array is already sorted
b) when input array is reverse sorted
c) when input array is large
d) it has the same time complexity in any case
Clarification: Stooge sort has the same time complexity under any case. It is given by the recurrence relation T(n) = 3T(2/3n) + O(1).
a) O(n)
b) O(1)
c) O(log n)
d) O(n log n)
Clarification: The space complexity of the stooge sort is O(n). It is used to store the input array.
a) apply stooge sort on first 2/3 elements of array
b) apply stooge sort on last 2/3 elements of array
c) apply stooge sort on first 1/3 elements of array
d) compare first and last element of the array
Clarification: The first step in the algorithm of stooge sort is to compare the first and last element of the array and switch them if found out of order. In the second step stooge sort is applied on the first 2/3 elements of the array.
a) true
b) false
Answer: a
Clarification: Stooge sort is an example of a comparison based sorting algorithm. This is because it compares the value of elements present in a list in order to sort them.
a) true
b) false
Clarification: Stooge sort is not a stable sorting algorithm. It is because the elements with identical values do not appear in the same order in the output array as they were in the input array.
a) O(n2)
b) O(n3)
c) O(n2.6)
d) O(n2.7)
Answer: d
Clarification: The recurrence relation of stooge sort is given as T(n) = 3T(2/3n) + O(1). It is found to be equal to O(n2.7) using the master’s theorem.
a) 0
b) 1
c) 2
d) 3
Clarification: The algorithm of stooge sort uses 3 recursive statements in its algorithm. The first and third recursive statement applies stooge sort to the first 2/3 elements of the array and the second recursive statement applies stooge sort to last 2/3 elements of the array.
a) stooge sort
b) strand sort
c) quick sort
d) bubble sort
Clarification: Stooge sort has the same time complexity of O(n2.7) in any case. This also shows that it is not an adaptive sorting algorithm.
a) bubble sort
b) selection sort
c) insertion sort
d) stooge sort
Clarification: Stooge sort has a time complexity of O(n2.7) which is the worst out of the given options. This shows that stooge sort is even less efficient than bubble sort which is itself considered to be a very inefficient sort.
a) insertion sort
b) strand sort
c) stooge sort
d) bubble sort
Clarification: Stooge sort is not an adaptive sorting algorithm. This is because it does not perform better in the case when the array is already/almost sorted.
a)void stooge_sort(int arr[], int l, int r)
{
if (l >= r)
return;
if (arr[l] > arr[r])
swap(arr[l], arr[h]);
if (r - l + 1 > =3)
{
int p = (r - l + 1) / 3;
stooge_sort(arr, l, r - p);
stooge_sort(arr, l + p, r);
stooge_sort(arr, l, r - p);
}
}
void stooge_sort(int arr[], int l, int r)
{
if (l >= r)
return;
if (arr[l] < arr[r])
swap(arr[l], arr[h]);
if (r - l + 1 >=3)
{
int p = (r - l + 1) / 3;
stooge_sort(arr, l, r - p);
stooge_sort(arr, l + p, r);
stooge_sort(arr, l, r - p);
}
}
void stooge_sort(int arr[], int l, int r)
{
if (l >= r)
return;
if (arr[l] > arr[r])
swap(arr[l], arr[h]);
if (r - l + 1 > =3)
{
int p = (r - l + 1) / 3;
stooge_sort(arr, l, r - p);
stooge_sort(arr, l, r - p);
stooge_sort(arr, l + p, r);
}
}
void stooge_sort(int arr[], int l, int r)
{
if (l >= r)
return;
if (arr[l] > arr[r])
swap(arr[l], arr[h]);
if (r - l + 1 >=3)
{
int p = (r - l + 1) / 3;
stooge_sort(arr, l + p, r);
stooge_sort(arr, l, r - p);
stooge_sort(arr, l, r - p);
}
}
Answer: a
Clarification: Stooge sort compare first and last element of the array and switch them if found out of order. Then it has 3 recursive statements. The first and third recursive statement applies stooge sort to the first 2/3 elements of the array and the second recursive statement applies stooge sort to last 2/3 elements of array.
& Algorithms.
