GATE CS 2025 Set 2 | Question 45

Programming & Data Structures › Stacks & Queues · MSQ · 2 marks · Answer: A

  1. Question 45Programming & Data Structuresmsq2 marks
    We augment a stack (distinct positive keys) with an MIN operation returning a pointer to the smallest key, (1) without deleting it and (2) without increasing the complexity of standard stack operations. Which approach(es) achieve this?
    • 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 are maintained in sorted order.
    • D.
      Keep a Min-Heap in which the key values are maintained.

    Answer: A

    Solution

    Answer: (A) (A) Store with each pushed record the pointer to the minimum of the stack below it; on push, the new record's "min" is computed in ; MIN and pop stay . This works. - (B) A single min pointer cannot be restored in after popping the minimum. Fails. - (C) Maintaining a sorted array costs per push/pop. Increases complexity. - (D) A min-heap makes push/pop . Increases complexity.

More GATE PYQ on Stacks & Queues

All GATE CS Programming & Data Structures PYQ →

Attempt GATE CS 2025 Set 2 in real GATE exam mode

Full paper with a timer, the GATE interface and a topic-wise analysis — free.

Create free account →