Data Structures & AlgorithmsHardGATE CS · Product placement

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

  1. A. 5; 5
  2. B. 6; 5
  3. C. 5; 4
  4. D. 6; 6

Correct answer: B. 6; 5

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

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

Exams that ask this topic