Question
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 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)
Official answer and solution
- Official answer
- 3
- From
- Official GATE 2026 answer key
Solution
Check each of the 7 merge steps in bottom-up/top-down merge sort to see when .
A merge of sorted arrays and (with distinct elements) produces followed by if and only if every element of is smaller than every element of , i.e., .
Tracing the 7 merges on :
- Level 1 (size 1 + 1):
- Merge and (not void, ).
- Merge and (void, ).
- Merge and (not void, ).
- Merge and (void, ).
- Level 2 (size 2 + 2):
- Merge and (not void, ).
- Merge and (not void, ).
- Level 3 (size 4 + 4):
- Merge and (void, since ).
Total void merge operations .
3
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2026 Computer Science and Information Technology - Session 2 (CS2)
- Question
- 32 of 65
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.