edited by
559 views
0 votes
0 votes
Consider the following expression:

(a+a*(b-c)+(b-c)*d)

What is the minimum number of three address statements for the expression?

My question is whether we should optimize the expression before evaluating it or go as it is. For instance the above expression can be optimized as (a+(b-c)*(a+d)) which would generate lesser number of statements.
edited by

1 Answer

Best answer
2 votes
2 votes

5 statements would be needed.

t1=b-c;

t2=a*t1;

t3=d*t1;

t4=t2+t3;

t5=a+t4;

Never try to optimise the expression unless they say algebraic simplifications or code optimisations are allowed or place a restriction on number of temorary variables.

selected by

Related questions

0 votes
0 votes
1 answer
1
Kai asked Nov 18, 2016
469 views
The answer given was D but isn't array access not a TAC as the following link suggests:https://web.stanford.edu/class/archive/cs/cs143/cs143.1128/handouts/240%20TAC%20Exa...
1 votes
1 votes
1 answer
2
Tushar Shinde asked Jan 12, 2016
611 views
A) a & b both are wrongB) a & b both are correctC) a is correct & b is wrongD) b is correct & a is wrongHow to solve such qstn??
2 votes
2 votes
1 answer
4
rahul sharma 5 asked Jan 24, 2018
1,269 views
Consider the intermediate code given below:The number of nodes and edges in the control-flow graph constructed for the above code, respectively are X and Y. The value of ...