GATE Computer ScienceVery hardGATE CS (PYQ pattern)

In the loop 1: i = 0; 2: j = 5; 3: L1: t1 = i * 4; 4: t2 = t1 + b; 5: j = j + 3; 6: k = j * 2; 7: m = m * 2; 8: u = i + n; 9: i = i + 1; 10: if i < n goto L1 (loop body = statements 3 to 10; b and n are not changed inside it), how many variables are induction variables, counting basic ones and those derived from them as a linear function?

  1. A. 6
  2. B. 5
  3. C. 7
  4. D. 4

Correct answer: A. 6

Basic: i (i = i + 1) and j (j = j + 3). Derived: t1 = i*4, t2 = t1 + b, u = i + n (family of i) and k = j*2 (family of j): 6 in all. m = m*2 is multiplicative, not linear, so it is not an induction variable.

More Compiler Design questions

Exams that ask this topic