Data Structures & AlgorithmsHardIBM · Deloitte pattern

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

  1. A. i f c + * a h / -
  2. B. i f c + * a - h /
  3. C. - / h a * + c f i
  4. D. i f c a h / - + *

Correct answer: A. i f c + * a h / -

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

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

Exams that ask this topic