• edited by
39,526 views
59 59 votes

Consider the intermediate code given below.

(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 (2)

The number of nodes and edges in control-flow-graph constructed for the above code, respectively, are

  1. $5$ and $7$
  2. $6$ and $7$
  3. $5$ and $5$
  4. $7$ and $8$

7 Answers

Best answer
81 81 votes

Answer is $6,7$ if we add an explicit start and end nodes. This follows from the definition of CFG in the below IITM link

http://www.cse.iitm.ac.in/~krishna/cs3300/pm-lecture1.pdf

But many of the standard books/universities don't follow this definition. 

• edited by
7 7 votes

Following are the Candidates for leader :

1.. First statement is a leader 

2. the target of unconditional and conditional instruction is a leader 

3. Statement following  unconditional and conditional instruction is a leader .

So let us count number of nodes :

Node1 :statement 1 

node 2 : Statement 2 

Node 3 : Statement 3 

node 4 : statement 4--9 

node 5 : Statement 10-11

Plus if i add one start and end nodes 

So in all there will be 7 nodes 

And the number of edges : 

We know that in a simple  connected graph with n nodes we have n-1 edges,

So here with 7 nodes we would have 6 edges + 2 edges ( GOTO 3 and GOTO 2--->backedges  ) = 8 edges .

1 flag:
✌ Edit necessary (aashish1406 “incorrect solution please edit it”)
6 6 votes

 4 NODES 5-edges

and if we add start and end nodes then

6-nodes and 7-edges

• edited by
2 2 votes
1. First statement is a leader. 2.target of go to is leader. 3.next statement of goto is leader. so

1.leader.

2.leader.

3.leader

10.leader.

now there will be 4 basic blocks made out of it.

Add start and stop to these four blocks.

Also number for nodes would be 6.and edges would be 7..

 

1 is b1.

2 is b2.

3-9 is b3

10-11 is b4
Answer:
Position:
Show:

Related questions

47 47 votes
5 answers 5 answers
11.9k
11.9k views
go_editor asked Feb 12, 2015
11,943 views
Match the following:$$\begin{array}{|ll|ll|}\hline \text{P.} & \text{Lexical analysis} & \text{1.} & \text{Graph coloring} \\\hline \text{Q.} & \text{Parsing} & \text{2....
97 97 votes
9 answers 9 answers
44.1k
44.1k views
Misbah Ghaya asked Feb 13, 2015
44,143 views
The least number of temporary variables required to create a three-address code in static single assignment form for the expression $q + r / 3 + s - t * 5 + u * v/w$ is_...
73 73 votes
5 answers 5 answers
29.6k
29.6k views
Misbah Ghaya asked Feb 12, 2015
29,641 views
For computer based on three-address instruction formats, each address field can be used to specify which of the following:(S1) A memory operand(S2) A processor register(S...
63 63 votes
5 answers 5 answers
21.3k
21.3k views
go_editor asked Feb 12, 2015
21,336 views
In the context of abstract-syntax-tree (AST) and control-flow-graph (CFG), which one of the following is TRUE?In both AST and CFG, let node $N_2$ be the successor of node...