Which data structure can be used to evaluate the postfix expression A B + C D…

2012

Which data structure can be used to evaluate the postfix expression A B + C D - *?

Answer: A. stackConceptPostfix evaluation processes tokens from left to right. Each operand is stored until an operator consumes the two most recent unresolved values, so the…

  1. A.

    stack

  2. B.

    tree

  3. C.

    queue

  4. D.

    linked list

Attempted by 362 students.

Show answer & explanation

Correct answer: A

Concept

Postfix evaluation processes tokens from left to right.

Each operand is stored until an operator consumes the two most recent unresolved values, so the required access rule is last-in, first-out.

Application

Apply that rule to A B + C D - *:

  1. Read A and B and store them as unresolved operands.

  2. At +, remove B and then A, form (A + B), and store that intermediate result.

  3. Read C and D and store them as unresolved operands.

  4. At -, remove D and then C, form (C - D), and store that intermediate result.

  5. At *, remove the two intermediate results and form (A + B) * (C - D).

Cross-check

Every operator consumes the newest unresolved operands first. FIFO access would consume older values in the wrong order, while hierarchical or linked storage is not required for this evaluation rule.

Therefore, the postfix expression is evaluated using a stack.

Explore the full course: Coding For Placement

Loading lesson…