GATE / CS ARCHIVE

GATE CSE 2003 / QUESTION 63

Ordered set supporting minimum deletion and unique insertion

Data Structures · Binary Search & Balanced Trees · Full GATE CSE 2003 paper

GATE 2003, Q63 2 marks · MCQ
Report issue

Binary Search & Balanced Trees

Question 63, GATE 2003: A set of n integers must support (I) deleting its smallest element and (II) inserting an element only if it is not already present, each in O(log n) time. Which structure suffices?
A. A heap, but not a balanced binary search tree
B. A balanced binary search tree, but not a heap
C. Both a balanced binary search tree and a heap
D. Neither
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

1. A balanced binary search tree has height O(log n). Follow left children to the minimum and delete/rebalance in O(log n). Search for a proposed key and, if absent, insert/rebalance along one root-to-leaf path in O(log n).
2. A min-heap can delete its root and sift down in O(log n), and can insert a known-new key in O(log n).
3. However, a heap is only partially ordered. Testing whether an arbitrary key already appears can require inspecting Θ(n) positions; insertion-if-absent includes that test.
4. Thus the balanced tree alone meets both requirements, B. A heap augmented with a separate search index is not the plain heap being compared.

Solution: A balanced binary search tree supports membership search, insertion, and deletion of its minimum in O(log n) worst-case time. A plain heap supports minimum deletion and unrestricted insertion in O(log n), but checking whether an arbitrary proposed value is already present may require Θ(n) comparisons. Therefore the uniqueness requirement rules out the heap alone, leaving B. Augmenting a heap with a separate membership structure is outside the listed plain-structure comparison.

Original paper, page 9