GATE Computer ScienceHardGATE CS (PYQ pattern)
Two stacks (values and operators) evaluate 12-(3+4*(5-2))/5*3+8/(1+1) with all operators left-associative and integer division truncating toward zero: before pushing an operator, apply stack operators of equal or higher precedence. What is the result, and what is the maximum height reached by the value stack?
- A. 10 and height 5
- B. 7 and height 5
- C. 7 and height 6
- D. 4 and height 4
Correct answer: B. 7 and height 5
Inside: 5 - 2 = 3, 4 * 3 = 12, 3 + 12 = 15; then 15 / 5 = 3, 3 * 3 = 9, 12 - 9 = 3, and 8 / 2 = 4, so the total is 7.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- How many index pairs i < j satisfy a[i] + a[j] == 10 in the array {3, 8, 5, 2, 7, 4, 6, 1, 9, 5, 3, 7}?
- unsigned x = 0x369; / binary 11 0110 1001 / unsigned s = 0, c = 0; while (x) { unsigned t = x & -x; c++; s += t c; x -= t; } What is s…
- int a[3][4] = {{3,1,4,1},{5,9,2,6},{5,3,5,8}}; int t = 0; for (int j = 0; j < 4; j++) for (int i = 0; i < 3; i++) t += ((a + i) + j) (j +…
- A queue is a circular array that starts with capacity 4 and doubles (copying every element) when an enqueue finds it full; dequeues never…
- unsigned char x = 0x5B; unsigned s = 0; for (int i = 0; i < 6; i++) { x ^= (unsigned char)(x << 3); x ^= x >> 2; s += x; } printf("%u %u"…
- A bracket checker pushes every opening bracket and, on a closing bracket, pops and compares. For the string {[()()]([{}])}[({[]}) the…