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 and 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?

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:
- Leaf Nodes: Since variables reside in memory and must be loaded into registers first, every leaf node (variables ) is labeled as .
- Internal Nodes: For any internal node with left child label and right child label :
- If , the label of the node is .
- If , the label of the node is .
Applying these rules bottom-up to the given expression tree:
- For the leaf nodes: .
- For the sub-expression containing and (let's call this node ):
- For the sub-expression containing and (let's call this node ):
- For the sub-expression containing and (let's call this node ):
- For the root node (which combines and ):
Thus, the minimum number of registers needed to evaluate the expression tree is .
Free practice · Your answers on this page are not saved.
