Sorting Algorithms # MCQs Practice set

Q.1 Which of the following sorting algorithms has the best average-case time complexity?

Bubble Sort
Insertion Sort
Merge Sort
Selection Sort
Explanation - Merge Sort has an average-case time complexity of O(n log n), which is better than Bubble Sort, Insertion Sort, and Selection Sort which are O(n^2).
Correct answer is: Merge Sort

Q.2 What is the worst-case time complexity of Quick Sort?

O(n)
O(n^2)
O(log n)
O(n log n)
Explanation - Quick Sort has a worst-case complexity of O(n^2), which occurs when the pivot selection is poor, such as when the array is already sorted and the first or last element is chosen as pivot.
Correct answer is: O(n^2)

Q.3 Which sorting algorithm is stable?

Quick Sort
Heap Sort
Merge Sort
Selection Sort
Explanation - Merge Sort is stable because it preserves the relative order of equal elements, whereas Quick Sort, Heap Sort, and Selection Sort are not stable by default.
Correct answer is: Merge Sort

Q.4 In Bubble Sort, how many comparisons are made in the worst case for an array of n elements?

n
n-1
n(n-1)/2
n^2
Explanation - In the worst case, Bubble Sort performs n-1 comparisons in the first pass, n-2 in the second, and so on, totaling n(n-1)/2 comparisons.
Correct answer is: n(n-1)/2

Q.5 Which sorting algorithm is most efficient for small arrays or nearly sorted arrays?

Quick Sort
Insertion Sort
Merge Sort
Heap Sort
Explanation - Insertion Sort is efficient for small or nearly sorted arrays due to its low overhead and adaptive nature.
Correct answer is: Insertion Sort

Q.6 Heap Sort is based on which data structure?

Stack
Queue
Heap
Linked List
Explanation - Heap Sort uses a binary heap data structure to repeatedly extract the maximum or minimum element and build a sorted array.
Correct answer is: Heap

Q.7 Which of the following sorting algorithms is in-place and not stable?

Merge Sort
Heap Sort
Bubble Sort
Insertion Sort
Explanation - Heap Sort is in-place but not stable because it may change the relative order of equal elements.
Correct answer is: Heap Sort

Q.8 What is the space complexity of Merge Sort?

O(1)
O(n)
O(log n)
O(n log n)
Explanation - Merge Sort requires O(n) extra space to store temporary arrays during the merging process.
Correct answer is: O(n)

Q.9 Which sorting algorithm repeatedly selects the smallest (or largest) element and moves it to the sorted part?

Selection Sort
Bubble Sort
Insertion Sort
Quick Sort
Explanation - Selection Sort repeatedly selects the minimum (or maximum) element from the unsorted part and swaps it with the first unsorted element.
Correct answer is: Selection Sort

Q.10 Which of these sorting algorithms is not comparison-based?

Radix Sort
Quick Sort
Merge Sort
Heap Sort
Explanation - Radix Sort sorts elements by processing individual digits and does not rely on comparisons, unlike Quick, Merge, or Heap Sort.
Correct answer is: Radix Sort

Q.11 What is the best-case time complexity of Bubble Sort?

O(n)
O(n^2)
O(log n)
O(n log n)
Explanation - In the best case (already sorted array), Bubble Sort only needs one pass and performs n-1 comparisons, resulting in O(n) time.
Correct answer is: O(n)

Q.12 Which sorting algorithm is recursive by nature?

Bubble Sort
Quick Sort
Insertion Sort
Selection Sort
Explanation - Quick Sort is a divide-and-conquer algorithm and is typically implemented using recursion.
Correct answer is: Quick Sort

Q.13 What is the main advantage of Merge Sort over Quick Sort?

Less space usage
Better worst-case time complexity
In-place sorting
Faster on small arrays
Explanation - Merge Sort has a guaranteed worst-case time complexity of O(n log n), while Quick Sort can degrade to O(n^2).
Correct answer is: Better worst-case time complexity

Q.14 Which algorithm repeatedly swaps adjacent elements if they are in the wrong order?

Bubble Sort
Selection Sort
Merge Sort
Quick Sort
Explanation - Bubble Sort repeatedly compares adjacent elements and swaps them if they are out of order.
Correct answer is: Bubble Sort

Q.15 Which sorting algorithm is generally considered fastest for large, random arrays in practice?

Bubble Sort
Quick Sort
Insertion Sort
Selection Sort
Explanation - Quick Sort is highly efficient in practice for large datasets due to good cache performance and average O(n log n) time complexity.
Correct answer is: Quick Sort

Q.16 Which sorting algorithm divides the array into two halves, sorts them, and merges them?

Quick Sort
Merge Sort
Heap Sort
Selection Sort
Explanation - Merge Sort uses the divide-and-conquer approach: it divides the array into halves, recursively sorts them, and merges the sorted halves.
Correct answer is: Merge Sort

Q.17 What is the primary disadvantage of Bubble Sort?

Not stable
High time complexity
Requires extra space
Difficult to implement
Explanation - Bubble Sort has a worst-case time complexity of O(n^2), making it inefficient for large arrays.
Correct answer is: High time complexity

Q.18 Which sorting algorithm works by building a heap and repeatedly removing the maximum element?

Heap Sort
Merge Sort
Insertion Sort
Selection Sort
Explanation - Heap Sort constructs a binary heap and then repeatedly extracts the largest element to build the sorted array.
Correct answer is: Heap Sort

Q.19 Which algorithm is adaptive, performing better when the array is nearly sorted?

Bubble Sort
Insertion Sort
Selection Sort
Heap Sort
Explanation - Insertion Sort is adaptive: its time complexity approaches O(n) for nearly sorted arrays.
Correct answer is: Insertion Sort

Q.20 Which sorting algorithm can be implemented without recursion and still maintain O(n log n) time complexity?

Merge Sort
Quick Sort
Heap Sort
Radix Sort
Explanation - Heap Sort can be implemented iteratively using a binary heap and maintains O(n log n) time complexity.
Correct answer is: Heap Sort

Q.21 Radix Sort is most efficient when sorting:

Large numbers with few digits
Small datasets
Nearly sorted arrays
Strings only
Explanation - Radix Sort performs well when the number of digits is small relative to the number of elements, making it efficient for such cases.
Correct answer is: Large numbers with few digits

Q.22 Which algorithm repeatedly selects a pivot and partitions the array around it?

Merge Sort
Quick Sort
Heap Sort
Selection Sort
Explanation - Quick Sort selects a pivot element and partitions the array such that elements less than the pivot come before and greater come after.
Correct answer is: Quick Sort

Q.23 Which sorting algorithm can be classified as a stable comparison-based algorithm?

Bubble Sort
Heap Sort
Quick Sort
Selection Sort
Explanation - Bubble Sort is stable because equal elements retain their relative order after sorting.
Correct answer is: Bubble Sort

Q.24 Which sorting algorithm's performance is unaffected by initial order of elements?

Insertion Sort
Bubble Sort
Heap Sort
Adaptive Sorts
Explanation - Heap Sort always has O(n log n) time complexity regardless of the initial order of the elements.
Correct answer is: Heap Sort

Q.25 Which sorting algorithm is especially used in external sorting for large datasets that do not fit in memory?

Quick Sort
Merge Sort
Heap Sort
Selection Sort
Explanation - Merge Sort is ideal for external sorting because it can handle large datasets and allows sequential access to data.
Correct answer is: Merge Sort