Data Structures & AlgorithmsModerateTCS Digital · Infosys SP

What is the minimum number of stacks needed to evaluate a fully parenthesised infix expression directly (without converting it first), using Dijkstra's two-stack algorithm?

  1. A. 3
  2. B. 0
  3. C. 2 (one for operands, one for operators)
  4. D. 1

Correct answer: C. 2 (one for operands, one for operators)

The two-stack algorithm pushes operands and operators onto separate stacks and applies an operator to the top two operands on each ')'. Postfix evaluation alone needs just one operand stack.

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

Exams that ask this topic