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 1–5 of 24
Consider an array . Suppose the merge sort algorithm is executed on array to sort it in increasing order. The merge sort algorithm will carry out a total of merge operations.
A merge operation on sorted left array and sorted right array is said to be void if the output of the merge operation is the elements of array followed by the elements of array .
The number of void merge operations among these merge operations is ________. (answer in integer)
A merge operation on sorted left array and sorted right array is said to be void if the output of the merge operation is the elements of array followed by the elements of array .
The number of void merge operations among these merge operations is ________. (answer in integer)
Answer: 3
A merge is void when every element of the left array is at most every element of the right array , that is, the largest of is at most the smallest of . Then the output is just followed by .
Pairs:
: output is then , not void.
: already then , void.
: not void.
: void.
Quads:
: the elements interleave, not void.
: output is then (every element of is smaller than every element of ), not void.
Final merge: : , so the output is then , void.
Merges: , of which 3 are void.
Answer: 3
Pairs:
: output is then , not void.
: already then , void.
: not void.
: void.
Quads:
: the elements interleave, not void.
: output is then (every element of is smaller than every element of ), not void.
Final merge: : , so the output is then , void.
Merges: , of which 3 are void.
Answer: 3
Consider the following array.
Which algorithm out of the following options uses the least number of comparisons (among the array elements) to sort the above array in ascending order?
Which algorithm out of the following options uses the least number of comparisons (among the array elements) to sort the above array in ascending order?
Answer: (C)
The array is already in sorted order.
- Insertion sort: every element is compared just once with the element on its left n 1 = 7 comparisons (best case).
- Selection sort always makes n(n 1)/2 = 28 comparisons.
- Merge sort needs more than 7 comparisons (about 12 here).
- Quicksort with the last element as pivot, on sorted input, gives the worst case (28).
Answer: Insertion sort
- Insertion sort: every element is compared just once with the element on its left n 1 = 7 comparisons (best case).
- Selection sort always makes n(n 1)/2 = 28 comparisons.
- Merge sort needs more than 7 comparisons (about 12 here).
- Quicksort with the last element as pivot, on sorted input, gives the worst case (28).
Answer: Insertion sort
An array of 25 distinct elements is to be sorted using quicksort. Assume that the pivot element is chosen uniformly at random. The probability that the pivot element gets placed in the worst possible location in the first round of partitioning (rounded off to 2 decimal places) is _________.
Answer: 0.08
The pivot lands in the worst place when it ends up at either end of the array. This happens when the pivot is the smallest or the largest element. So there are 2 favourable choices out of 25.
Answer: 0.08
Answer: 0.08
The worst case running times of Insertion sort, Mergesort and Quicksort, respectively, are:
Answer: (D)
Let us check each sort one by one:
- Insertion sort, worst case (the input is in reverse order):
- Merge sort takes the same time in every case:
- Quicksort, worst case (a bad pivot is chosen every time):
Answer:
- Insertion sort, worst case (the input is in reverse order):
- Merge sort takes the same time in every case:
- Quicksort, worst case (a bad pivot is chosen every time):
Answer:
Assume that the algorithms considered here sort the input sequences in ascending order. If the input is already in ascending order, which of the following are TRUE?
I. Quicksort runs in time
II. Bubblesort runs in time
III. Merge sort runs in time
IV. Insertion sort runs in time
I. Quicksort runs in time
II. Bubblesort runs in time
III. Merge sort runs in time
IV. Insertion sort runs in time
Answer: (D)
When the input is already sorted:
- Quicksort (pivot is the first or last element) gets the most unbalanced splits . Statement I is True.
- Bubble sort with a "no swap" check ends after a single pass . Statement II is False.
- Merge sort always takes . Statement III is False.
- Insertion sort compares each element only once . Statement IV is True.
Answer: I and IV only
- Quicksort (pivot is the first or last element) gets the most unbalanced splits . Statement I is True.
- Bubble sort with a "no swap" check ends after a single pass . Statement II is False.
- Merge sort always takes . Statement III is False.
- Insertion sort compares each element only once . Statement IV is True.
Answer: I and IV only
Keep practising