2,664 views
3 votes
3 votes

Consider the code segment

int i,j,x,y,m,n;
n=20;
for(i=0;i<n;i++)
{
        for(j=0;j<n;j++)
        {
            if(i%2)
            {
                x+=((4*j)+5*i);
                y+=(7+4*j);
            }
        }
}
m=x+y;

Which one of the following is false ?

A) The code contains loop invariant computation

B) There is scope of common sub-expression elimination in this code

C)There is scope of strength reduction in this code

D)There is scope of dead code elimination in this code

1 Answer

0 votes
0 votes

Option A : Why the code 

x+=((4*j)+5*i);
y+=(7+4*j);

is loop invariant ? x and y get updated with with change in values of i,j for every iteration

Option D: Also if we use constant propogation for n the loop headers become .. i<20... and j<20... respectively.

Hence n = 20 is a possible candidate for dead code elimination 

So isnt A the right option ?

Related questions

6 votes
6 votes
3 answers
1
junaid ahmad asked Dec 17, 2017
7,292 views
Q.A strictly binary tree with 10 leavesA) cannot have more than 19 nodesB) has exactly 19 nodesC)has exactly 17 nodesD) has exactly 20 nodes
0 votes
0 votes
1 answer
2
junaid ahmad asked Dec 17, 2017
2,212 views
Let S be an NP-complete problem.Q and R are other two problems not known to be NP.Q is polynomial time reducible to S and S is polynomial time reducible to R.Which of the...
8 votes
8 votes
1 answer
4
sh!va asked May 7, 2017
6,519 views
Estimation at software development effort for organic software in basic COCOMO is:E = 2.0 (KLOC) 1.05 PME = 3.4 (KLOC) 1.06 PME = 2.4 (KLOC) 1.05 PME = 2.4 (KLOC) 1.07...