Computer Sciences > GATE 2025 SET-2 > Stack Operations
Consider a stack data structure into which we can PUSH and POP records. Assume that each record pushed in the stack has a positive integer key and that all keys are distinct.
We wish to augment the stack data structure with an O(1) time MIN operation that returns a pointer to the record with smallest key present in the stack
1) without deleting the corresponding record, and
2) without increasing the complexities of the standard stack operations.
Which one or more of the following approach(es) can achieve it?
A
Keep with every record in the stack, a pointer to the record with the smallest key below it.
B
Keep a pointer to the record with the smallest key in the stack.
C
Keep an auxiliary array in which the key values of the records in the stack are maintained in sorted order.
D
Keep a Min-Heap in which the key values of the records in the stack are maintained.

Correct : a

The correct answer is Option A.
The goal is to support O(1) MIN without slowing down PUSH or POP. Let''s check each approach.
Option A - Store a min-pointer with every record: When a new element is pushed, compare it with the current top''s min-pointer and store whichever is smaller alongside the new record. MIN is O(1) - just read the top record''s min-pointer. PUSH and POP remain O(1). This works perfectly and is correct.
Option B - Single global min-pointer: Works for PUSH and MIN, but fails for POP. If the minimum element is popped, the pointer becomes stale and finding the new minimum requires a full scan - making POP O(n). Incorrect.
Option C - Sorted auxiliary array: Inserting into a sorted array during PUSH requires O(n) time for shifting. This violates the O(1) PUSH requirement. Incorrect.
Option D - Min-Heap: Heap insertion takes O(log n), not O(1). PUSH complexity increases. Incorrect.
Option A is the classic and correct approach — it essentially maintains a "running minimum" at every level of the stack, so no matter what gets popped, the new top always knows the current minimum instantly.

Similar Questions

A palindrome is a word that reads the same forwards and backwards. In a game of words, a player has the following two plates painted with letters. From...
#1 MCQ
Which number does not belong in the series below? 2, 5, 10, 17, 26, 37, 50, 64
#4 MCQ
Choose the word that is opposite in meaning to the word “coherent”.
#5 MCQ

Related Topics

stack O(1) min operation GATE 2025 GATE CS 2025 Set-2 Q44 augmented stack minimum min stack design PUSH POP MIN O(1) stack minimum pointer per record data structures GATE min heap stack GATE sorted array stack GATE GATE computer science 2025

Unique Visitor Count

Total Unique Visitors

Loading......