Open in App
Not now

GATE | GATE-CS-2006 | Question 60

• Last Updated : 17 Sep, 2021

Consider the following C code segment.

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

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

Explanation:

```4*j is common subexpression elimination so B is true.

5*i can be moved out of inner loop so can be i%2.
Means, A is true as we have loop invariant computation.

Next, 4*j as well as 5*i can be replaced with a = - 4;
before j loop then a = a + 4; where 4*j is computed,
likewise for 5*i. C is true as there is scope of strength
reduction.

By choice elimination, we have D.```

Quiz of this Question
Please comment below if you find anything wrong in the above post

My Personal Notes arrow_drop_up
Related Articles