Data Structures & AlgorithmsHardIBM · Deloitte pattern

Infix A * (B + C * (D − E)) / F is converted to postfix with an operator stack (operators and '(' are pushed onto it). What is the largest number of items on the stack at any moment?

  1. A. 3
  2. B. 6
  3. C. 4
  4. D. 5

Correct answer: B. 6

After reading the second '(' the stack holds *, (, +, *, ( (5 items), and pushing − makes 6. The output is A B C D E − * + * F /. Counting only operators and forgetting the parentheses gives 4.

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

Exams that ask this topic