The Gateway to Computer Science Excellence
+1 vote
313 views

Consider the following code segment:

c=b+a

e=c-a

f=c*e

h=c+a

i=h+f 

The minimum number of  $\color{blue} {total}$ and $\color{blue} {temporary }$ variable required to convert the above code segment to static single assignment form are  ________

in Compiler Design by Active (1.3k points) | 313 views
0
answer is 5 don't worry!!
0
Akash what these command execute.
0
@Anu007 sir ,I didn't get u!!
+2
Temp : 5

Total: 7
0
explain your approach
0

2 Answers

+4 votes
Best answer
c(temp 1) = a ( variable )+ b ( variable )

e(temp 2) = c - a

f(temp 3) = c * e

h(temp 4) = c + a

i(temp 5) = h + f

So temp = 5

Total = temporary + variable

Total = 7
by Active (2k points)
selected by
0
I think code optimization not part of syllabus.
0
This question has been asked in made easy's Mock test.

Are you sure about the no. of temp variables being 5?  because acc. to them it's 4.
+2
Yes I am sure, and you can check more  similar kinds of questions which already asked in previous year gate paper.
+1
0
answer is correct!
+2 votes

c=b+a                              ;  t1= b + a

e=c-a     , e=b+a -a = b => e=b

f=c*e                                ; t2=t1*b  // e=b

h=c+a                              ; t3=t1*a

i=h+f                               ; t4=t3+t2

# Temporary Variables = 4

# Total Variables = 4 +2  = 6

Here, we are doing Code optimization.

Ref:https://gateoverflow.in/2068/gate2014-3-34#q2068

by Boss (10.9k points)
+1
answer is wrong.. it will be $5,7$ below given answer is correct indeed .

Also the link/reference you are giving are completely different from the qstn asked .
0

Here we are asked the minimum number of temporary variables.

In the reference that I have provided, it is not completely different.

There we need to design a DAG.

First we have done Code optimization , then designed it.

Now,

 

You can check code optimization is not possible.

I think for answering such question because minimum number is asked , we should do code optimization

0

https://gateoverflow.in/39675/gate-2016-1-19

Here, in one of the answers , Someone even made a DAG and then counted the

#internal nodes = # temporary variables used,

If we also follow the same approach then my answer is correct.

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,388 answers
198,576 comments
105,414 users