Consider an array A = [10, 7, 8, 19, 41, 35, 25, 31]. Suppose the merge sort…

2026

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)

Attempted by 15 students.

Show answer & explanation

Correct answer: 3

The array A = [10, 7, 8, 19, 41, 35, 25, 31] has n=8 elements. Merge sort performs n-1 = 7 merge operations.

Level 1 Merges (4 operations):

1. Merge [10] and [7]: 10 > 7, not void. 2. Merge [8] and [19]: 8 < 19, void. 3. Merge [41] and [35]: 41 > 35, not void. 4. Merge [25] and [31]: 25 < 31, void.

Level 2 Merges (2 operations):

5. Merge [7, 10] and [8, 19]: max(10) > min(8), not void. 6. Merge [35, 41] and [25, 31]: max(41) > min(25), not void.

Level 3 Merge (1 operation):

7. Merge [7, 8, 10, 19] and [25, 31, 35, 41]: max(19) < min(25), void.

Total void merge operations = 3.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir