Data Structures & AlgorithmsHardHCLTech · Wipro pattern

What is the postfix (Reverse Polish) form of the infix expression "e *(a + b)- h / d", built with the standard stack-based conversion (^ right-associative, others left-associative)?

  1. A. - / d h * + b a e
  2. B. e a b + * h - d /
  3. C. e a b + * h d / -
  4. D. e a b h d / - + *

Correct answer: C. e a b + * h d / -

Using a stack to hold pending operators and popping higher-or-equal precedence operators before pushing a new one (left-associative) gives "e a b + * h d / -". Treating all operators as equal precedence instead would wrongly give "e a b + * h - d /".

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

Exams that ask this topic