Data Structures & AlgorithmsHardProduct company OA

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

  1. A. f d + h * i e + -
  2. B. - + e i + * h d f
  3. C. f d h i e + - * +
  4. D. f d h * + i e + -

Correct answer: D. f d h * + i e + -

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

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

Exams that ask this topic