Skip to content
Official PYQ · 2011

GATE CS 2011 Q36 — Runtime Environments

Explain with AI

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,a, b, c, d, and ee are initially stored in memory. The binary operators used in this expression tree can be evaluated by the machine only when 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?

Choose one option
View worked solution

Answer: D

To find the minimum number of registers required to evaluate the expression tree on a load-store architecture, we use the Sethi-Ullman labeling algorithm. For a load-store architecture, the rules for labeling the nodes are as follows:

  1. Leaf Nodes: Since variables reside in memory and must be loaded into registers first, every leaf node (variables a,b,c,d,ea, b, c, d, e) is labeled as 11.
  2. Internal Nodes: For any internal node with left child label LL and right child label RR:
    • If L=RL = R, the label of the node is L+1L + 1.
    • If L≠RL \neq R, the label of the node is max⁡(L,R)\max(L, R).

Applying these rules bottom-up to the given expression tree:

  • For the leaf nodes: Label(a)=Label(b)=Label(c)=Label(d)=Label(e)=1Label(a) = Label(b) = Label(c) = Label(d) = Label(e) = 1.
  • For the sub-expression containing dd and ee (let's call this node N1N_1): Label(N1)=1+1=2Label(N_1) = 1 + 1 = 2
  • For the sub-expression containing cc and N1N_1 (let's call this node N2N_2): Label(N2)=max⁡(Label(c),Label(N1))=max⁡(1,2)=2Label(N_2) = \max(Label(c), Label(N_1)) = \max(1, 2) = 2
  • For the sub-expression containing aa and bb (let's call this node N3N_3): Label(N3)=1+1=2Label(N_3) = 1 + 1 = 2
  • For the root node (which combines N3N_3 and N2N_2): Label(Root)=2+1=3Label(\text{Root}) = 2 + 1 = 3

Thus, the minimum number of registers needed to evaluate the expression tree is 33.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Runtime Environments questions