Skip to content
Official PYQ · 1997

GATE CS 1997 Q4.7 — Arrays, Stacks and Queues

Explain with AI

A priority queue QQ is used to implement a stack that stores characters. PUSH (C) is implemented as INSERT (Q,C,K)(Q, C, K) where KK is an appropriate integer key chosen by the implementation. POP is implemented as DELETEMIN(Q)(Q). For a sequence of operations, the keys chosen are in

Choose one option
View worked solution

Answer: D

A stack operates on the Last-In-First-Out (LIFO) principle, meaning the element inserted last must be the first one to be removed.

In the given implementation:

  • PUSH(C) is implemented as INSERT(Q, C, K).
  • POP() is implemented as DELETEMIN(Q), which retrieves the element with the minimum key value.

To ensure that the most recently pushed element has the minimum key (so it gets popped first), each new element pushed must be assigned a key that is strictly smaller than the keys of all previously pushed elements.

For example, if we push elements C1,C2,C3C_1, C_2, C_3 in sequence, their assigned keys K1,K2,K3K_1, K_2, K_3 must satisfy:

K1>K2>K3K_1 > K_2 > K_3

This ensures that C3C_3 (the last pushed element with the minimum key K3K_3) is popped first by DELETEMIN(Q).

Thus, the keys chosen for successive push operations must be in strictly decreasing order.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Arrays, Stacks and Queues questions