GATE CS 2011 · Question 36 · Compiler Design · Multiple choice (MCQ) · 2 marks · −2/3 for a wrong answer

Consider evaluating the following expression tree on a machine with load-store architecture in which memory can be accessed only through load and store instructions. The variables a, b, c, d and e are initially stored in memory. The binary operators used in this expression tree can be evaluated by the machine only when the operands are in registers. The instructions produce result only in a register. If no intermediate results can be stored in memory, what is the minimum number of registers needed to evaluate this expression?

Expression tree. Root node '+' has two children: left child '-' and right child '-'. The left '-' has left child leaf a and right child leaf b. The right '-' has left child leaf e and right child '+'. That '+' has left child leaf c and right child leaf d. The expression is (a - b) + (e - (c + d)).
  1. (A) 2
  2. (B) 9
  3. (C) 5
  4. (D) 3
Answer

Answer (D)

Answer from the official GATE CS 2011 answer key.

The step-by-step solution, where available, is part of GATE CS Pro. See what Pro includes