Question
The least number of temporary variables required to create a three-address code in static single assignment form for the expression is _____.
Official answer and solution
- Official answer
- 8
- From
- Official GATE 2015 answer key
Solution
Convert the arithmetic expression into Static Single Assignment three-address code by assigning each binary operation to a unique temporary variable.
Expression: .
In Static Single Assignment (SSA) form, every temporary variable is defined exactly once.
Evaluating operations adhering to standard operator precedence and left-to-right associativity:
-
Multiplications and Divisions (higher precedence):
-
Additions and Subtractions (evaluated left-to-right):
There are 8 distinct binary operations in the expression: two divisions, two multiplications, three additions, and one subtraction.
Each three-address code instruction computes one binary operator, requiring a distinct temporary variable under SSA rules ().
Therefore, the least number of temporary variables required is .
8
Reusing temporary variables (e.g., t1 = t1 + s) which violates the SSA property that every variable must be assigned exactly once.
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2015 Computer Science and Information Technology (CS) Session 1
- Question
- 65 of 65, printed as CS Q.55
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.