GATE / CS ARCHIVE

GATE CSE 2003 / QUESTION 23

Fixed-rank selection from a min heap

Data Structures · Heaps & Priority Queues · Full GATE CSE 2003 paper

GATE 2003, Q23 1 mark · MCQ
Report issue

Heaps & Priority Queues

Question 23, GATE 2003: A min-heap has n elements, with its smallest at the root. For n≥7, what time is sufficient to find the seventh smallest element, as a function of n? A. Θ(n log n); B. Θ(n); C. Θ(log n); D. Θ(1).
Question 23, GATE 2003: A min-heap has n elements, with its smallest at the root. For n≥7, what time is sufficient to find the seventh smallest element, as a function of n? A. Θ(n log n); B. Θ(n); C. Θ(log n); D. Θ(1).
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

1. The candidate frontier contains the roots of all unexplored subheaps. Heap order makes its minimum the smallest unseen element. Extract that node and add at most its two children, preserving the invariant. After seven iterations the frontier and work are bounded by constants independent of n.

2. Maintain a small candidate min-priority queue initially containing the root. Repeatedly remove its minimum and insert that node’s children; after seven removals the extracted value is seventh smallest. Only a constant number of nodes and candidate operations are used because rank 7 is fixed, hence Θ(1) with respect to n, D, assuming n≥7. Repeatedly deleting from the original n-element heap is unnecessarily expensive.

Original paper, page 3