Data Structures & AlgorithmsHardProduct-company MCQ pattern

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

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

Correct answer: B. i j + d * b h / -

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

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

Exams that ask this topic