Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

Convert a*(b+c)-d/e to postfix with the shunting-yard algorithm (+ and - have lower precedence than * and /; all operators are left-associative). What is the postfix string?

  1. A. abc+*de/-
  2. B. acb*+de/-
  3. C. bac+*de/-
  4. D. abd+*ce/-

Correct answer: A. abc+*de/-

Operators wait on the stack until a lower-precedence operator or a bracket forces them out. The bracket group b+c is output before the multiplication by a.

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

Exams that ask this topic