Data Structures & AlgorithmsModerateTCS NQT · Infosys pattern

Operators have the usual precedence (* and / above + and −, all left-associative). What is the postfix form of A * (B + C) / D − E?

  1. A. A B C + D / * E −
  2. B. A B C + * D E − /
  3. C. A B + C * D / E −
  4. D. A B C + * D / E −

Correct answer: D. A B C + * D / E −

The bracket is evaluated first (B C +), then * with A, then / with D (left to right, same precedence), and finally − E: A B C + * D / E −. 'A B C + D / *' does the division before the multiplication, which breaks left-associativity.

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

Exams that ask this topic