ISBN : 978-81-963532-2-3 (E-Book) can bedefinedin terms ofthecontrol flow graph (CFG)ofaprogram. ControlFlow Graph(CFG) A control flow graph describes the sequence in which the different instructions of a program getexecuted. In other words, a control flow graph describes how the control flows through theprogram. In order to draw the control flow graph of a program, all the statements of a programmust be numbered first. The different numbered statements serve as nodes of the control flowgraph (as shown in fig. 20.2). An edge from one node to another node exists if the execution ofthestatementrepresentingthefirst nodecanresultinthetransferof controltotheothernode. The CFG for any program can be easily drawn by knowing how to represent the sequence,selection, and iteration type of statements in the CFG. After all, a program is made up from thesetypes of statements. Fig. 20.2summarizes how the CFG for these three types of statements canbe drawn. It is important to note that for the iteration type of constructs such as the whileconstruct, the loop condition is tested only at the beginning of the loop and therefore the controlflow from the last statement of the loop is always to the top of the loop. Using these basic ideas,theCFGofEuclid’sGCDcomputationalgorithmcan bedrawnas shown infig. 20.3. Sequence: a=5; b=a*2-1; Fig.(a):CFGforsequenceconstructs Selection: if(a>b) c=3; else 94 Software Engineering Keerthana P, Manasa KN, Ganga D Bengal
100 Publizr Home