GateAI
Searching, Sorting and Hashing

GATE CSE 2026 Set 2 · Q32

NAT1 markMedium

Time

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 7 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 7 merge operations is _______. (answer in integer)

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 3

Searching, Sorting and Hashing

Standard top-down merge sort divides the array into two halves until single-element arrays are reached, and then merges them bottom-up.

A merge of sorted arrays LL and RR produces LL followed by RR (a void merge) if and only if max⁡(L)≤min⁡(R)\max(L) \le \min(R).

Let's trace the 7 merge steps for A=[10,7,8,19,41,35,25,31]A = [10, 7, 8, 19, 41, 35, 25, 31]:

  1. Left half [10,7,8,19][10, 7, 8, 19]:

    • Merge 1: L=[10]L = [10], R=[7]  ⟹  R = [7] \implies Output is [7,10][7, 10]. Not void.

    • Merge 2: L=[8]L = [8], R=[19]  ⟹  R = [19] \implies Output is [8,19][8, 19]. Since max⁡(L)=8≤19=min⁡(R)\max(L) = 8 \le 19 = \min(R), output is LL followed by RR. (Void #1)

    • Merge 3: L=[7,10]L = [7, 10], R=[8,19]  ⟹  R = [8, 19] \implies Output is [7,8,10,19][7, 8, 10, 19]. Not void.

  2. Right half [41,35,25,31][41, 35, 25, 31]:

    • Merge 4: L=[41]L = [41], R=[35]  ⟹  R = [35] \implies Output is [35,41][35, 41]. Not void.

    • Merge 5: L=[25]L = [25], R=[31]  ⟹  R = [31] \implies Output is [25,31][25, 31]. Since max⁡(L)=25≤31=min⁡(R)\max(L) = 25 \le 31 = \min(R), output is LL followed by RR. (Void #2)

    • Merge 6: L=[35,41]L = [35, 41], R=[25,31]  ⟹  R = [25, 31] \implies Output is [25,31,35,41][25, 31, 35, 41]. Not void.

  3. Final Merge:

    • Merge 7: L=[7,8,10,19]L = [7, 8, 10, 19], R=[25,31,35,41]  ⟹  R = [25, 31, 35, 41] \implies Output is [7,8,10,19,25,31,35,41][7, 8, 10, 19, 25, 31, 35, 41]. Since max⁡(L)=19≤25=min⁡(R)\max(L) = 19 \le 25 = \min(R), the output is array LL followed by array RR. (Void #3)

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

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Searching, Sorting and Hashing previous year question is Q32 of the GATE CSE 2026 Set 2 paper. Find more GATE CSE PYQs on Searching, Sorting and Hashing in Algorithms, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Searching, Sorting and Hashing PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Searching, Sorting and Hashing in GATE CSE

Searching, Sorting and Hashing has 27 GATE CSE PYQs across 20 papers from 2012 to 2026. 5 of them are 1-mark NAT questions like this one, and GATE CSE 2026 Set 2 has 2.

How GATE tests Searching, Sorting and Hashing

More from GATE CSE 2026 Set 2

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2026 Set 2 · Q32 · NAT

Consider an array A = [10, 7, 8, 19, 41, 35, 25, 31]. Suppose the merge sort algorithm is executed on array A to sort it in increasing order. The merge sort algorithm will carry out a total of 7 merge operations. A merge operation on sorted left array L and sorted right array R is said to be void if the output of the merge operation is the elements of array L followed by the elements of array R. The number of void merge operations among these 7 merge operations is … (answer in integer)

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.