Skip to content
Official PYQ · 2026

GATE CS 2026 Set 2 Q22 — Searching, Sorting, Hashing

Explain with AI
Consider an array A=[10,7,8,19,41,35,25,31]A=[10,7,8,19,41,35,25,31]. Suppose the merge sort algorithm is executed on array AA to sort it in increasing order. The merge sort algorithm will carry out a total of 77 merge operations.

A merge operation on sorted left array LL and sorted right array RR is said to be void if the output of the merge operation is the elements of array LL followed by the elements of array RR.

The number of void merge operations among these 77 merge operations is ____\_\_\_\_. (answer in integer)
View worked solution

Answer: 3:3

A merge operation on sorted arrays LL and RR is void if the merged output is exactly LL concatenated with RR. Since LL and RR are already sorted, this condition holds if and only if:

max⁡(L)≤min⁡(R)\max(L) \le \min(R)

Let us trace the standard merge sort execution on the array A=[10,7,8,19,41,35,25,31]A = [10, 7, 8, 19, 41, 35, 25, 31] by recursively splitting it into halves:

  1. Merge 1: L=[10]L = [10], R=[7]R = [7]
    max⁡(L)=10>min⁡(R)=7\max(L) = 10 > \min(R) = 7 → Not Void
  2. Merge 2: L=[8]L = [8], R=[19]R = [19]
    max⁡(L)=8≤min⁡(R)=19\max(L) = 8 \le \min(R) = 19 → Void
  3. Merge 3: L=[7,10]L = [7, 10], R=[8,19]R = [8, 19]
    max⁡(L)=10>min⁡(R)=8\max(L) = 10 > \min(R) = 8 → Not Void
  4. Merge 4: L=[41]L = [41], R=[35]R = [35]
    max⁡(L)=41>min⁡(R)=35\max(L) = 41 > \min(R) = 35 → Not Void
  5. Merge 5: L=[25]L = [25], R=[31]R = [31]
    max⁡(L)=25≤min⁡(R)=31\max(L) = 25 \le \min(R) = 31 → Void
  6. Merge 6: L=[35,41]L = [35, 41], R=[25,31]R = [25, 31]
    max⁡(L)=41>min⁡(R)=25\max(L) = 41 > \min(R) = 25 → Not Void
  7. Merge 7: L=[7,8,10,19]L = [7, 8, 10, 19], R=[25,31,35,41]R = [25, 31, 35, 41]
    max⁡(L)=19≤min⁡(R)=25\max(L) = 19 \le \min(R) = 25 → Void

Thus, there are exactly 3 void merge operations (Merge 2, Merge 5, and Merge 7).

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Searching, Sorting, Hashing questions