Searching, Sorting & Selection
![Question 32, GATE 2026: Merge sort sorts [10,7,8,19,41,35,25,31] using its usual balanced contiguous halves and seven merges. A merge is void if its output is the sorted left half followed directly by the sorted right half. Count void merges.](../../assets/questions/CS-2026-S2-Q32-1.webp)
Answer & solution
Official answer: 3
Step through it (9 steps)
Givens and goal
Merge sort sorts [10,7,8,19,41,35,25,31] using its usual balanced contiguous halves and seven merges. A merge is void if its output is the sorted left half followed directly by the sorted right half. Count void merges.
Approach
List all seven merges and test max(left)≤min(right).
Step-by-step solution
1. At the lowest level the pairs are [10] with [7], [8] with [19], [41] with [35], and [25] with [31]. The second and fourth are already in concatenated sorted order; the first and third are not. This level contributes two void merges.
2. The next left merge combines [7,10] and [8,19]. Since 10>8, their elements interleave and it is not void. The next right merge combines [35,41] and [25,31]; since 41>25, it is not void either.
3. At the root the sorted halves are [7,8,10,19] and [25,31,35,41]. Because 19<25, concatenating them is already sorted. The final merge is void.
4. The count is 2+0+1=3 among the 4+2+1=7 merges. Void means the resulting ordering needs no interleaving, not that the recursive subarrays were originally sorted or that the implementation necessarily skips its merge routine.