Question
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 of these data structures?
Official answer and solution
- Official answer
- A
- From
- Official GATE 2025 answer key
Solution
Find the optimal worst-case algorithm for concatenating two doubly linked lists (P), building a heap from two arrays of size (Q), and merging two BSTs via sorted arrays (R).
- P (Unsorted doubly linked list with head and tail pointers): We link the
tailof the first list to theheadof the second list and update the combinedtailpointer in time. - Q (Array-based Min-Heap): We copy the two arrays of size into a single array of size in time and run Floyd's bottom-up
Build-Heapin worst-case time. - R (Binary Search Tree): We perform an inorder traversal of each BST to produce two sorted arrays of size in time, merge the two sorted arrays into a sorted array of size in time, and recursively construct a balanced BST from the sorted array in time.
Option (A)
Assuming merging two BSTs requires inserting elements one by one in time.
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2025 Computer Science and Information Technology - Session 2 (CS2)
- Question
- 38 of 65
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.