Data Structures & AlgorithmsVery hardProduct company OA

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

  1. A. j g + h * i c + -
  2. B. - + c i + * h g j
  3. C. j g h * + i c + -
  4. D. j g h i c + - * +

Correct answer: C. j g h * + i c + -

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

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

Exams that ask this topic