Data Structures & AlgorithmsHardTCS Digital · Infosys SP

^ is exponentiation (highest precedence, right-associative); * and / come next; + and − are lowest; others are left-associative. What is the prefix (Polish) form of A + B ^ (C ^ D) ^ E / F?

  1. A. +ABCD^E^^F/
  2. B. +A/^B^C^DEF
  3. C. +A/^B^^CDEF
  4. D. +/F^^E^DCBA

Correct answer: C. +A/^B^^CDEF

Build the expression tree respecting precedence and parentheses, then write it root-first. Reversing the postfix string is a common trap — it also reverses operand order.

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

Exams that ask this topic