GATE Computer ScienceVery hardGATE CS (PYQ pattern)
A min-stack keeps an auxiliary stack: a value is pushed on it when it is less than or equal to the current auxiliary top (or it is empty); on a pop, if the popped value equals the auxiliary top it is popped there too. The operations are push 5, 7, 5, 3, 3, pop, pop, push 9, 2, pop, pop, pop, push 1. How many pushes were made on the auxiliary stack in total, and what is its final size?
- A. 5 pushes, final size 2
- B. 6 pushes, final size 2
- C. 6 pushes, final size 3
- D. 8 pushes, final size 1
Correct answer: B. 6 pushes, final size 2
With the <= rule duplicates of the minimum are also stored. Tracing the operations gives 6 auxiliary pushes and a final auxiliary stack [5, 1].
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- for (i = 1; i < 1000; i = 2) for (j = 0; j < i; j++) cnt++; What is the final value of cnt (starting from 0)?
- A table of size 11 uses linear probing with h(k) = k mod 11 and tombstones: a deleted slot is marked DELETED; search continues past…
- The maximum of every window of 3 consecutive elements of [4, 2, 12, 11, -5, 7, 9, 3, 1, 6] is found with a deque of indices: before…
- A singly linked list has 25 nodes. A routine places pointer p at the head and pointer q at the 6th node from the head, then advances both…
- 12-bit sets are stored as bit vectors: A = 101101101101, B = 011010110011, C = 111000011010 (most significant bit first). What are the…
- int f(int a[], int l, int r) { if (l == r) return a[l]; int m = (l + r) / 2; int x = f(a, l, m), y = f(a, m + 1, r); return x > y ? x : y…