Skip to main content

GATE CSE 2026Algorithms › Sorting AlgorithmsVerified

GATE CSE 2026 PYQ: Consider an array A = [ 10 , 7 , 8 , 19 , 41 , 35 , 25 , 31 ] A=[10,7,8,19,41,35,25,31] A = [ 10 , 7 , 8 ,…

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)

    Answer

    3

    Approach

    Simulate the recursive merge sort on the 8-element array and, at each of the 7 merges, test whether all elements of the sorted left half L are less than all elements of the sorted right half R. If so, the merge is void; otherwise it interleaves elements.

    A merge is void exactly when max(L) < min(R) for distinct elements, i.e. the two sorted runs are already in the correct relative order. Checking all seven merge operations gives three such merges: [8]&[19], [25]&[31], and the final merge of [7,8,10,19]&[25,31,35,41].

    Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.