Skip to main content

GATE CSE 2025Data Structures › Hashing & Complexity AnalysisVerified

GATE CSE 2025 PYQ: ​A meld operation on two instances of a data structure combines them into one single instance of the same…

​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?

  1. A
    P:Θ(1),Q:Θ(n),R:Θ(n)\mathrm{P}: \Theta(1), \mathrm{Q}: \Theta(n), \mathrm{R}: \Theta(n)
    Correct answer
  2. B
    P\text{P}: Θ(1),Q:Θ(nlog⁡n),R:Θ(n)\Theta(1), \mathrm{Q}: \Theta(n \log n), \mathrm{R}: \Theta(n)
  3. C
    P\text{P}: Θ(n),Q:Θ(nlog⁡n),R:Θ(n2)\Theta(n), \mathrm{Q}: \Theta(n \log n), \mathrm{R}: \Theta\left(n^{2}\right)
  4. D
    P\text{P}: Θ(1),Q:Θ(n),R:Θ(nlog⁡n)\Theta(1), \mathrm{Q}: \Theta(n), \mathrm{R}: \Theta(n \log n)

Answer

(A) P : Θ ( 1 ) , Q : Θ ( n ) , R : Θ ( n ) \mathrm{P}: \Theta(1), \mathrm{Q}: \Theta(n), \mathrm{R}: \Theta(n) P : Θ ( 1 ) , Q : Θ ( n ) , R : Θ ( n )

Approach

Evaluate the best possible worst-case time for melding two size-n instances of each structure: P (unsorted doubly linked list with head/tail pointers), Q (array-based min-heap), and R (binary search tree). The key is to use optimal algorithms: O(1) pointer splicing for P, O(n) build-heap after array concatenation for Q, and O(n) inorder traversal + merge + balanced construction for R.

The optimal worst-case meld costs are P: Θ(1), Q: Θ(n), and R: Θ(n), exactly as in option A. The other options incorrectly inflate Q and/or R by using suboptimal algorithms such as repeated insertion or assuming comparison-based n log n behavior when a linear-time merge-like construction is available.

Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.