GATE 2015 CS (CS2) – Question 44
Find the numbers of basic-block nodes and edges in the control-flow graph for:
1: i=1
2: j=1
3: t1=5*i
4: t2=t1+j
5: t3=4*t2
6: t4=t3
7: a[t4]=−1
8: j=j+1
9: if j<=5 goto 3
10: i=i+1
11: if i<5 goto 2Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: (B) 6 and 7
Explanation
The four nonempty basic blocks are [1], [2], [3–9], [10–11]. Their edges are first→second, second→third, third→itself, third→fourth, fourth→second and fourth→exit. Including the conventional entry and exit nodes gives six nodes and adds entry→first, for seven edges. Therefore the source convention yields B.