GATE | GATE CS 1997 | Question 32
A priority queue Q is used to implement a stack S that stores characters. PUSH(C) is implemented as INSERT(Q, C, K) where K is an appropriate integer key chosen by the implementation. POP is implemented as DELETEMIN(Q). For a sequence of operations, the keys chosen are in
(A) Non-increasing order
(B) Non-decreasing order
(C) strictly increasing order
(D) strictly decreasing order
Answer: (D)
Explanation: We are implementing a STACK using Priority Queue. Note that Stack implementation is always last in first out (LIFO) order.
As given “POP is implemented as DELETEMIN(Q)” that means Stack returns minimum element always.
So, we need to implement PUSH(C) using INSERT(Q, C, K) where K is key chosen from strictly-decreasing order(only this order will ensure stack will return minimum element when we POP an element). That will satify Last In First Out (LIFO) property of stack.
That is answer, option (D) is true.
Option (A) non-increasing order can not be true because two same (identical) numbers can not have same priority as priority should be distinguishable for each number.
Recommended Posts:
- GATE | GATE CS 1997 | Question 35
- GATE | GATE CS 1997 | Question 34
- GATE | GATE CS 1997 | Question 33
- GATE | GATE CS 1997 | Question 31
- GATE | GATE CS 1997 | Question 30
- GATE | GATE CS 1997 | Question 72
- GATE | GATE CS 1997 | Question 29
- GATE | GATE CS 1997 | Question 28
- GATE | GATE CS 1997 | Question 27
- GATE | GATE CS 1997 | Question 26
- GATE | GATE CS 1997 | Question 36
- GATE | GATE CS 1997 | Question 41
- GATE | GATE CS 1997 | Question 46
- GATE | GATE CS 1997 | Question 45
- GATE | GATE CS 1997 | Question 44



