Question:

Consider an array 𝐴= [10, 7, 8, 19, 41, 35, 25, 31]. 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 7 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 7 merge operations
is __________. (answer in integer)

Show Hint

A merge is void when the largest element of the left sub-array is already smaller than the smallest element of the right sub-array. Trace the merge sort recursion tree and check this condition at every merge step.
Updated On: Aug 4, 2026
Show Solution
collegedunia
Verified By Collegedunia

Correct Answer: 3

Solution and Explanation

Step 1: The array is \(A = [10, 7, 8, 19, 41, 35, 25, 31]\). Merge sort splits it recursively into halves: left half \([10, 7, 8, 19]\) and right half \([41, 35, 25, 31]\).
Step 2: The left half splits into \([10, 7]\) and \([8, 19]\). Merging \([10]\) and \([7]\) is not void since \(10 > 7\), giving \([7, 10]\). Merging \([8]\) and \([19]\) is void since \(8 < 19\) already, giving \([8, 19]\).
Step 3: Merging \([7, 10]\) with \([8, 19]\) is not void because the last element of the left part, \(10\), is greater than the first element of the right part, \(8\).
Step 4: The right half splits into \([41, 35]\) and \([25, 31]\). Merging \([41]\) and \([35]\) is not void since \(41 > 35\), giving \([35, 41]\). Merging \([25]\) and \([31]\) is void since \(25 < 31\) already, giving \([25, 31]\).
Step 5: Merging \([35, 41]\) with \([25, 31]\) is not void because \(41 > 25\), so elements interleave.
Step 6: The final merge combines \([7, 8, 10, 19]\) with \([25, 31, 35, 41]\). Since the maximum of the left part, \(19\), is less than the minimum of the right part, \(25\), this merge is void.
Step 7: Counting all void merges: merge of \([8],[19]\), merge of \([25],[31]\), and the final merge of \([7,8,10,19],[25,31,35,41]\) - a total of 3 void merges out of 7.
Final Answer: \[\boxed{3}\]
Was this answer helpful?
0
0

Top GATE CS Computer Science and IT Engineering Questions

View More Questions