GATE / CS ARCHIVE

GATE CSE 2025 SET 2 / QUESTION 38

GATE CSE 2025 Set 2 Q38

Data Structures · Other / Mixed Topics · Full GATE CSE 2025 Set 2 paper

GATE 2025 Set 2, Q38 2 marks · MCQ
Report issue

Other / Mixed Topics

Question 38, GATE 2025: Meld combines two size-n instances into one of the same data structure. Let P be an unsorted doubly linked list with head and tail pointers, Q an array-based min-heap, and R a binary search tree. Choose the best worst-case time complexities.
A. P Θ(1), Q Θ(n), R Θ(n).
B. P Θ(1), Q Θ(n log n), R Θ(n).
C. P Θ(n), Q Θ(n log n), R Θ(n²).
D. P Θ(1), Q Θ(n), R Θ(n log n).
Tap to enlarge
Your answer
Answer & solution

Official answer: A

P: join the first list's tail to the second list's head, set the corresponding previous pointer, and choose the resulting head and tail. Only a constant number of pointer changes are needed, with separate constant-time handling of empty lists. The list is unsorted, so no ordering merge is required: Θ(1).

Q: place both arrays into one 2n-element array and apply bottom-up build-heap. Build-heap is linear, not Θ(n log n): there are many nodes near leaves that require only short sift-down operations, and summing their heights gives O(n). The concatenation/output work is also linear, so Θ(n) suffices. Inserting each item separately is valid but needlessly slower in the worst case.

R: perform inorder traversals to get two sorted sequences in Θ(n), merge them in Θ(n), and build a balanced BST from the merged sequence by choosing midpoints recursively in Θ(n). Arbitrarily interleaved key sets require linear worst-case work/comparisons to establish their joint ordering, so the meld bound is Θ(n), rather than the cost of repeated naive insertions into a possibly skewed tree.

The three bounds are Θ(1),Θ(n),Θ(n): A.

Original paper, page 29 · Answer key