IAE Academy

GATE 2026 CS2 Q.45: solution and answer

GATE 2026 · CS2Q.45 · 2 marks · MCQ

Consider the control flow graph given below.

Which one of the following options is the set of live variables at the exit point of each basic block?

GATE 2026 CS2 question 45: Control flow graph.Tap to open full size
Figure from the GATE 2026 CS2 paper. It is part of the question.
Figure description

Control flow graph. ENTRY has an edge to B1. B1: a = b + c. B1 has two outgoing edges: one to B2 and one to B3. B2: d = a + e; B2 has an edge to B4. B3: e = a + f; B3 has an edge back to the top of B1. B4: g = d + e; B4 has an edge to EXIT.

  1. (A)

    B1:{a, b, c, e, f}, B2:{d, e}, B3:{b, c, e, f}, B4:∅

  2. (B)

    B1:∅, B2:{d, e}, B3:{a, c, f}, B4:∅

  3. (C)

    B1:{a, b, c, e, f}, B2:{d, e}, B3:{c, e, f}, B4:∅

  4. (D)

    B1:∅, B2:{d, e, f}, B3:{a, b, c, e, f}, B4:∅

Answer and solution

ANSWER

The live variables at the exit of each block are B1: {a, b, c, e, f}, B2: {d, e}, B3: {b, c, e, f}, B4: ∅. This is option A.

Official answer: ASource: Official answer key, GATE 2026 CS2 (IIT Guwahati)

  1. A variable is live at a point if its current value may be used on some path before it is redefined. Liveness runs backward: and .

  2. Block use and def sets: B1 use , def . B2 use , def . B3 use , def . B4 use , def . Successors: B1 to B2 and B3, B2 to B4, B3 to B1, B4 to EXIT.

  3. B4: because nothing is used after EXIT. So .

  4. B2: , and .

  5. B1 and B3 form a loop, so iterate from empty sets. Start with . Then and .

  6. Then and .

  7. Second pass: , so .

  8. Then and . This is unchanged, so a fixed point is reached.

  9. Live at block exits: B1 , B2 , B3 , B4 . This is option A.

KEY IDEA

Live-variable analysis is a backward data-flow problem. Compute OUT as the union of the successors' IN sets, and IN = use ∪ (OUT − def). Where blocks form a loop, iterate from empty sets until nothing changes.

WATCH OUT FOR

Reporting the live-in sets instead of the live-out sets. Another slip is stopping after one pass over the B1–B3 loop, which leaves B3's exit set short of {b, c, e, f}. A third is forgetting that B3 redefines e, so e is removed from IN(B3) and enters OUT(B1) only through B2's use of e.

From the GATE 2026 CS2 paper. Every question of this paper · Download the full paper · All 6 Optimisation questions, with notes

More Optimisation questions