GATE / CS ARCHIVE

SUBJECT COLLECTION

Data Structures · Other / Mixed Topics

3 questions, newest first

Browse topics
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

2 marks · NAT
Report issue

Other / Mixed Topics

Question 48, GATE 2015: Young tableau rows[1, 2, 5, 14], [3, 4, 6, 23], [10, 12, 18, 25], [31, ∞, ∞, ∞], increasing rows/columns. Remove 1 and move other entries so that the result remains a Young tableau, allowing unfilled entries to be marked ∞. What is the minimum number of other entries shifted? The solution below uses the conventional adjacent-hole deletion algorithm.
Tap to enlarge
Answer & solution

Official answer: 5

Standard Young-tableau deletion moves the smaller right/down neighbor into the hole. Removing 1 successively shifts 2, 4, 6, 18, 25, then places infinity at(3, 4), giving five moved entries. At each step selecting a larger adjacent neighbor would violate the row/column inequality with the smaller one, so this is the forced minimum adjacent-shift deletion path.

In conventional adjacent-hole deletion, after removing 1 the hole at the top-left must receive the smaller of its right/down neighbors to preserve both monotonic directions. The forced choices are 2, then 4, then 6, then 18, then 25; the hole finally reaches a position that may become∞. Moving the larger neighbor at an earlier step would leave a smaller value below or to the right of the moved entry, violating order. This proves minimality for the conventional adjacent-hole sliding model, not by itself for arbitrary whole-table rearrangement; the source does not explicitly restrict movements to adjacent cells.

Original paper, page 42 · Answer key

1 mark · MCQ
Report issue

Abstract data type interface

Other / Mixed Topics

Question 2, GATE 2005: An abstract data type is: A an abstract class; B a type that cannot be instantiated; C a type used through its defined operations rather than arbitrary representation operations; D all of these.
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

An ADT specifies values and the operations permitted on them while hiding representation. Clients use its defined interface, C. It is not identical to an abstract class and does not imply that values/instances cannot be created.

An ADT defines permitted values and operations independently of how data is stored. A stack, for example, offers push/pop without letting clients depend on array indices or linked-node layout. It can have instances and can be implemented in many languages, including languages without classes. Thus C describes abstraction; A and B confuse separate language mechanisms with the abstract specification.

Original paper, page 1