0
$\begingroup$

I found a question.

Least number of temporary variables required to create three address code in static single assignment form for the expression $p+q*r-s/(q*r)$

My attempt:

$t_1 = q*r$
$t_2 = s/t_1$
$t_3 = p + t_1$
$t_4 = t_3 - t_2$

So, I got $4$ variables but their answer is $5$. Am I missing something? Where I am being wrong?

$\endgroup$
  • 1
    $\begingroup$ Looks fine to me. Maybe I'm missing something as well. $\endgroup$ – orlp Dec 18 '18 at 16:23
  • $\begingroup$ Who are "they"? If you can provide an accessible source of question, this question should be simple enough to answer. $\endgroup$ – Apass.Jack Dec 19 '18 at 1:59
  • $\begingroup$ @Apass.Jack a local question from an online test series. $\endgroup$ – Mr. Sigma. Dec 19 '18 at 3:20
2
$\begingroup$

You used the optimisation of calculating q * r only once. Maybe someone considered that "cheating" and is insisting that it must be calculated twice. I wouldn't agree with that at all, but it would explain the different answers.

$\endgroup$
  • $\begingroup$ Is it possible the source has committed mistake in its solution? What's the standard procedure? Should optimization not be done while generating $3-$ address code? $\endgroup$ – Mr. Sigma. Dec 19 '18 at 0:13
  • 1
    $\begingroup$ It looks like a homework question. There are correct answers, there is your answer, and there’s the answer the teacher expects. $\endgroup$ – gnasher729 Dec 19 '18 at 9:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.