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?
- A. 6
- B. 5
- C. 7
- 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
- With instructions OP R, R and OP R, M (a leaf that is a right child can be a memory operand), the Sethi-Ullman algorithm labels a left…
- For S′ → S; S → ( L ) | x; L → S | L , S, LALR(1) is formed by merging canonical LR(1) states with equal cores. The LALR state reached…
- int j = 2; int A[0..4] = {0, 3, 1, 4, 2}; int Sum(k, lo, hi, e) { int s = 0; for (k = lo; k <= hi; k++) s = s + e; return s; } All…
- An SLR(1) shift-reduce parser for E → E + T | T; T → T F | F; F → ( E ) | id parses "( id + id ) id". Each shift and each reduce counts as…
- An LR parser for S → S ( S ) | ε parses "( ( ) ) ( )". Each shift and each reduce (including reductions by S → ε) counts as one move. What…
- Minimal SSA form (φ-functions at the iterated dominance frontier of each variable's defining blocks, no pruning) is built for 1: x = 1; 2…