GATE / CS ARCHIVE

GATE CSE 1997 / QUESTION 4.7

Implementing a stack with delete-min

Data Structures · Stacks & Queues · Full GATE CSE 1997 paper

GATE 1997, Q4.7 2 marks · MCQ
Report issue

Stacks & Queues

Question 4.7, GATE 1997: A priority queue is used to implement a LIFO stack. PUSH inserts an item with a chosen integer key; POP deletes the minimum. Should keys be nonincreasing, nondecreasing, strictly increasing, or strictly decreasing?
Tap to enlarge
Your answer
Answer & solution

Answer: D as the sufficient unambiguous scheme (no official key was published)

The newest live item must have the smallest key so it is returned first. Assign successively decreasing keys, for example 0, −1, −2, …; then delete-min exactly follows last-in-first-out order. Strict decrease prevents ties whose unspecified resolution could return an older item. Thus D is the standard sufficient choice. A merely nonincreasing sequence permits equal keys and does not guarantee LIFO without an extra tie rule. Keys need only outrank still-live items, so global decrease is a simple implementation policy rather than the only possible schedule-aware assignment.

Original paper, page 4