Data Structures & AlgorithmsHardGATE CS · ICPC regional

Convert the infix expression a+b*(c-d)/e to postfix with the shunting-yard algorithm (operators '+', '-', '*', '/' with '*' and '/' binding tighter, left-associative). What is the postfix string?

  1. A. abcd-*e/+
  2. B. acbd-*e/+
  3. C. abdc-*e/+
  4. D. bacd-*e/+

Correct answer: A. abcd-*e/+

Operands go straight to the output; operators wait on the stack and are popped while the top has priority at least as high. The closing bracket pops the subtraction first.

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

Exams that ask this topic