• edited by
862 views
0 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.

1 Answer

Best answer
2 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
Position:
Show:

Related questions

0 0 votes
1 answers 1 answer
704
704 views
Kai asked Nov 18, 2016
704 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 1 vote
1 1 answer
841
841 views
Tushar Shinde asked Jan 12, 2016
841 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??