GATE Computer ScienceHardGATE CS (PYQ pattern)
A bracket checker pushes every opening bracket and, on a closing bracket, pops and compares. For the string {[()()]([{}])}[({[]}) the checker ends with the stack not empty. How many symbols remain on the stack at the end, and what is the greatest stack height reached during the scan?
- A. 1 remaining, maximum height 4
- B. 2 remaining, maximum height 4
- C. 1 remaining, maximum height 5
- D. 0 remaining, maximum height 4
Correct answer: A. 1 remaining, maximum height 4
The first block {[()()]([{}])} is balanced (its deepest point is the stack { ( [ { of height 4). In the final block [({[]}) the ) closes ( but the opening [ is never closed, so exactly one symbol remains.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- A queue holds 5, 12, 7, 3, 9, 14, 2, 8 (front first). To reverse the first 5 elements, they are dequeued onto a stack, popped back and…
- In the binary tree (key, left, right) = (44, (20, (12), (8)), (24, (9, (4), (5)), (15, -, (15)))), how many non-leaf nodes have a key…
- int ds(int n) { return n < 10 ? n : ds(n / 10) + n % 10; } int steps(int n) { int c = 0; while (n >= 10) { n = ds(n); c++; } return c; }…
- The keys 3, 9, 6, 12, 1, 15, 8 are inserted one after another into an initially empty max-heap (each insertion places the key at the end…
- int fib(int n) { if (n < 2) return n; return fib(n-1) + fib(n-2); } Including the initial call, how many times is fib executed in total…
- A hash table of size 13 uses double hashing with h1(k) = k mod 13, h2(k) = 1 + (k mod 11) and probe sequence (h1 + i·h2) mod 13. The keys…