Data Structures & AlgorithmsHardTCS NQT · Infosys pattern

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

  1. A. - + a b + * f e j
  2. B. j e + f * b a + -
  3. C. j e f * + b a + -
  4. D. j e f b a + - * +

Correct answer: C. j e f * + b a + -

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

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

Exams that ask this topic