Data Structures & AlgorithmsHardGATE CS · DSA

Evaluate the postfix expression 1 9 9 ÷ 4 − 7 + − (all divisions are exact). What is its value, and what is the maximum number of operands on the stack at any moment?

  1. A. -3; 3
  2. B. -3; 4
  3. C. 9; 3
  4. D. 9; 2

Correct answer: A. -3; 3

On each operator pop b (top) then a, and push a op b — the first popped value is the RIGHT operand. Tracing gives -3, with the stack peaking at 3 values. Swapping the operand order gives 9.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic