GATE Computer ScienceVery hardGATE CS (PYQ pattern)
The infix expression a + b * (c ^ d - e) ^ (f + g * h) - i (with ^ right-associative and higher than * and +) is converted to postfix with the usual operator-stack algorithm. Counting '(' as a stack entry, what is the maximum number of symbols on the stack at any moment, and what is the 6th symbol of the postfix result?
- A. 5 and e
- B. 6 and e
- C. 6 and -
- D. 7 and ^
Correct answer: B. 6 and e
Postfix is abcd^e-fgh*+^*+i-. The stack is fullest while reading g * h: + * ^ ( + * (6 symbols); the sixth symbol is e.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- Evaluate the postfix expression 9 3 - 4 2 5 - 7 3 / + where / is integer division truncating toward zero.
- Ten people numbered 1 to 10 stand in a circle (a circular linked list in increasing order). Counting starts at person s, who is counted as…
- A singly linked list has 17 nodes numbered 0 to 16 from the head; node 16 points back to node 7 (so the tail of length 7 leads into a…
- A routine rev(k) reverses every block of k consecutive nodes of a singly linked list in place, leaving a final block of fewer than k nodes…
- A queue is built from two stacks: enqueue pushes onto stack IN; dequeue pops from OUT, and if OUT is empty it first moves every element of…
- A BST is built by inserting 50, 30, 70, 20, 40, 60, 80 in some order into an initially empty tree. The final tree is the perfectly…