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 16–20 of 24
If we use Radix Sort to sort n integers in the range , for some k>0 which is independent of n, the time taken would be?
Answer: (C)
Radix sort works digit by digit. Take a fixed digit base (for example binary), so a key with digits needs passes. Each pass over keys costs , so the time is .
The keys are less than , so a key has at most binary digits. The keys are also more than , so the largest key has at least digits. So . Since is a constant independent of , it drops out and .
Time . The lower bound on the range is what makes this tight () and not only an upper bound.
Option B, , would need only about passes. That happens only if the digit base itself grows with (base ). With a fixed base, the number of digits grows as , so (C) is the answer.
Answer: (C)
The keys are less than , so a key has at most binary digits. The keys are also more than , so the largest key has at least digits. So . Since is a constant independent of , it drops out and .
Time . The lower bound on the range is what makes this tight () and not only an upper bound.
Option B, , would need only about passes. That happens only if the digit base itself grows with (base ). With a fixed base, the number of digits grows as , so (C) is the answer.
Answer: (C)
Consider the Quicksort algorithm. Suppose there is a procedure for finding a pivot element which splits the list into two sub-lists each of which contains at least one-fifth of the elements. Let T(n) be the number of comparisons required to sort n elements. Then
Answer: (B)
The pivot splits the elements so that each part has at least elements. The other part then has at most elements, so the worst split is and .
Sorting the two parts costs . Partitioning compares every other element with the pivot, which is at most comparisons. So
.
(A) is wrong: its parts and cover only elements, so most of the list is not sorted. (C) charges to both parts, but the two parts together hold only elements, so it is not the recurrence of this split. (D) assumes an exactly even split, which this pivot rule does not guarantee.
Answer: (B)
Sorting the two parts costs . Partitioning compares every other element with the pivot, which is at most comparisons. So
.
(A) is wrong: its parts and cover only elements, so most of the list is not sorted. (C) charges to both parts, but the two parts together hold only elements, so it is not the recurrence of this split. (D) assumes an exactly even split, which this pivot rule does not guarantee.
Answer: (B)
Which of the following sorting algorithms has the lowest worst-case complexity?
Answer: (A)
Worst-case time of each algorithm:
- Merge sort:
- Bubble sort:
- Quick sort: (when the pivot is always the smallest or largest element)
- Selection sort:
grows slower than , so merge sort has the lowest worst case. Merge sort takes on every input because it always splits in halves.
Answer: (A)
- Merge sort:
- Bubble sort:
- Quick sort: (when the pivot is always the smallest or largest element)
- Selection sort:
grows slower than , so merge sort has the lowest worst case. Merge sort takes on every input because it always splits in halves.
Answer: (A)
The median of n elements can be found in O(n) time. Which one of the following
is correct about the complexity of quick sort, in which median is selected as pivot?
Answer: (B)
If we pick the median as the pivot, the array always splits into two equal halves. This is the best case of quick sort.
Recurrence:
Correct Answer:
Recurrence:
Correct Answer:
Which one the following in place sorting algorithms needs the minimum number of swaps?
Answer: (C)
Selection sort does at most one swap in each pass. So it makes at most n 1 swaps in total. Quick sort, insertion sort and heap sort can make or swaps.
Answer: Selection sort
Answer: Selection sort
Keep practising