GateAI
Linear Structures, Trees and Heaps

GATE CSE 2025 Set 2 · Q38

MCQ2 marksMedium

Time

A meld operation on two instances of a data structure combines them into one single instance of the same data structure. Consider the following data structures: P: Unsorted doubly linked list with pointers to the head node and tail node of the list. Q: Min-heap implemented using an array. R: Binary Search Tree.

Which ONE of the following options gives the worst-case time complexities for meld operation on instances of size nn of these data structures?

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: A) P: (1), Q: (n), R: (n)

Linear Structures, Trees and Heaps

Let us analyze the worst-case time complexity of the meld operation for two instances, each of size nn:

  1. P: Unsorted doubly linked list with head and tail pointers

    • Since the list is unsorted and we have direct pointers to the head and tail of both lists, we can concatenate the two lists in O(1)O(1) time by setting list1.tail->next = list2.head and list2.head->prev = list1.tail, followed by updating the overall tail pointer.

    • Hence, the time complexity is Θ(1)\Theta(1).

  2. Q: Min-heap implemented using an array

    • We can concatenate the two arrays of size nn into a single array of size 2n2n in Θ(n)\Theta(n) time.

    • Then, we run the standard bottom-up heap construction algorithm (Floyd's buildHeap) on the combined array of size 2n2n, which takes linear time Θ(n)\Theta(n).

    • Hence, the overall time complexity is Θ(n)\Theta(n).

  3. R: Binary Search Tree (BST)

    • Perform an in-order traversal of both BSTs to obtain two sorted arrays of size nn in Θ(n)\Theta(n) time.

    • Merge the two sorted arrays into a single sorted array of size 2n2n using standard two-pointer merging in Θ(n)\Theta(n) time.

    • Construct a balanced BST from the merged sorted array in Θ(n)\Theta(n) time using divide-and-conquer.

    • Hence, the overall time complexity is Θ(n)\Theta(n).

Therefore, the correct worst-case time complexities are P: Θ(1)\Theta(1), Q: Θ(n)\Theta(n), R: Θ(n)\Theta(n), matching Option (A).

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Linear Structures, Trees and Heaps previous year question is Q38 of the GATE CSE 2025 Set 2 paper. Find more GATE CSE PYQs on Linear Structures, Trees and Heaps in Programming and Data Structures, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Linear Structures, Trees and Heaps PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Linear Structures, Trees and Heaps in GATE CSE

Linear Structures, Trees and Heaps has 14 GATE CSE PYQs across 12 papers from 2012 to 2026. 4 of them are 2-mark MCQs like this one, and it is the only one in GATE CSE 2025 Set 2.

How GATE tests Linear Structures, Trees and Heaps

More from GATE CSE 2025 Set 2

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2025 Set 2 · Q38 · MCQ

A meld operation on two instances of a data structure combines them into one single instance of the same data structure. Consider the following data structures: P: Unsorted doubly linked list with pointers to the head node and tail node of the list. Q: Min-heap implemented using an array. R: Binary Search Tree. Which ONE of the following options gives the worst-case time complexities for meld operation on instances of size n of these data structures?

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.