Data Structures & AlgorithmsHardTCS NQT · Infosys pattern

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

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

Correct answer: B. c i + a * j d / -

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

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

Exams that ask this topic