Sorting · Algorithms
24 questions · asked in 15 of 27 years (2000–2026)
MCQ 22 · NAT 21-mark 17 · 2-mark 7
2000Questions per year2026
Questions 11–15 of 24
The number of elements that can be sorted in time using heap sort is
Answer: (C)
Sorting k elements with heap sort takes . Now put .
This gives , and here .
Answer:
This gives , and here .
Answer:
Which one of the following is the tightest upper bound that represents the number of swaps required to sort n numbers using selection sort?
Answer: (B)
In selection sort, each pass makes at most one swap. So the total number of swaps is at most n 1.
Answer: O(n)
Answer: O(n)
A list of n strings, each of length n, is sorted into lexicographic order using the merge-sort algorithm. The worst case running time of this computation is
Answer: (B)
Merge sort does comparisons. Comparing two strings of length n can cost O(n) each time.
Total time =
Answer:
Total time =
Answer:
In quick sort, for sorting n elements, the (n/4)th smallest element is selected as pivot using an O(n) time algorithm. What is the worst case time complexity of the quick sort?
Answer: (B)
The pivot is the (n/4)-th smallest element, so it splits the array into n/4 1 elements on the left and 3n/4 on the right. Finding the pivot costs and partitioning costs . The recurrence is
.
Draw the recursion tree. The sizes at any level add up to at most n, so each level costs at most . The longest branch always takes the 3n/4 part, so its depth is , which is . So .
The shortest branch takes the n/4 part and has depth about . Every level above that depth is full and costs , so as well.
So the worst case is . It is not because the split is never worse than n/4 : 3n/4.
Answer: (B)
.
Draw the recursion tree. The sizes at any level add up to at most n, so each level costs at most . The longest branch always takes the 3n/4 part, so its depth is , which is . So .
The shortest branch takes the n/4 part and has depth about . Every level above that depth is full and costs , so as well.
So the worst case is . It is not because the split is never worse than n/4 : 3n/4.
Answer: (B)
What is the number of swaps required to sort n elements using selection sort, in the worst case?
Answer: (A)
Selection sort runs one pass for each position . In a pass it first finds the minimum of the unsorted part using only comparisons, then makes a single swap to put that minimum in position i.
So each pass does at most 1 swap, and there are passes. The number of swaps is at most in the worst case, and the worst case does reach about n swaps. So the number of swaps is . The part of selection sort comes from the comparisons, not from the swaps.
Answer: (A)
So each pass does at most 1 swap, and there are passes. The number of swaps is at most in the worst case, and the worst case does reach about n swaps. So the number of swaps is . The part of selection sort comes from the comparisons, not from the swaps.
Answer: (A)
Keep practising