MCQ On Sorting - Data Structure
21. What is the average case complexity of bubble sort?
A. O(nlogn)
B. O(logn)
C. O(n)
D. O(n2)
View Answer
Ans : D
Explanation: Bubble sort works by starting from the first element and swapping the elements if required in each iteration even in the average case.
22. The given array is arr = {1,2,4,3}. Bubble sort is used to sort the array elements. How many iterations will be done to sort the array?
A. 4
B. 2
C. 1
D. 0
View Answer
Ans : A
Explanation: Even though the first two elements are already sorted, bubble sort needs 4 iterations to sort the given array.
23.What is the best case efficiency of bubble sort in the improvised version?
A. O(nlogn)
B. O(logn)
C. O(n)
D. O(n2)
View Answer
Ans : B
Explanation: Only 2 elements in the given array are not sorted, hence only 2 iterations are required to sort them.
24. QuickSort can be categorized into which of the following?
A. Brute Force technique
B. Divide and conquer
C. Greedy algorithm
D. Dynamic programming
View Answer
Ans : B
Explanation: First you divide(partition) the array based on the pivot element and sort accordingly.
25. What is a randomized QuickSort?
A. The leftmost element is chosen as the pivot
B. The rightmost element is chosen as the pivot
C. Any element in the array is chosen as the pivot
D. A random number is generated which is used as the pivot
View Answer
Ans : C
Explanation: QuickSort is randomized by placing the input data in the randomized fashion in the array or by choosing a random element in the array as a pivot.
Also Check :
Discussion