Data Structures & AlgorithmsHardGATE CS · ICPC regional

Convert (a+b)*c/(d-e) to postfix with the shunting-yard algorithm (+ and - lowest, then * and /, all left-associative). What is the postfix string?

  1. A. ab+c*de-/
  2. B. ba+c*de-/
  3. C. ab+dc*e-/
  4. D. ac+b*de-/

Correct answer: A. ab+c*de-/

The bracketed sum comes out first as ab+, then the multiplication by c, and the bracketed difference de- is divided into the product. Compare the operator order carefully.

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

Exams that ask this topic