Control Flow Graph (CFG) - Software Engineering Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report A Control Flow Graph (CFG) is the graphical representation of control flow or computation during the execution of programs or applications. Control flow graphs are mostly used in static analysis as well as compiler applications, as they can accurately represent the flow inside a program unit. The control flow graph was originally developed by Frances E. Allen.Characteristics of Control Flow GraphThe control flow graph is process-oriented. The control flow graph shows all the paths that can be traversed during a program execution. A control flow graph is a directed graph. Edges in CFG portray control flow paths and the nodes in CFG portray basic blocks. There exist 2 designated blocks in the Control Flow Graph: Entry Block: The entry block allows the control to enter into the control flow graph. Exit Block: Control flow leaves through the exit block. Hence, the control flow graph comprises all the building blocks involved in a flow diagram such as the start node, end node, and flows between the nodes. General Control Flow GraphsControl Flow Graph is represented differently for all statements and loops. The following images describe it: 1. If-else2. While3. do-while4. forExampleif A = 10 then if B > C A = B else A = C endif endifprint A, B, C Flowchart of above example will be: control flow graphControl Flow Graph of above example will be: control flow graphAdvantage of CFGVisualizes program flow: Easy to see how a program runs.Helps find errors: Detects unreachable code or infinite loops.Useful for optimization: Improves program performance.Aids testing: Ensures all parts of the code are tested.Disadvanatges of CFGComplex for big programs: Hard to understand.No unpredictable behavior: Can’t show unclear paths.No data info: Only shows program flow.Not scalable: Becomes messy for large projects.ConclusionControl Flow Graph (CFG) is a helpful tool to understand how a program works. It makes it easier to find errors, improve performance, and ensure thorough testing. While it can get complex for large programs, it’s still a valuable way to analyze and optimize code effectively. Comment More infoAdvertise with us Next Article Cause Effect Graphing Example in Software Engineering P pp_pankaj Follow Improve Article Tags : Software Engineering Similar Reads Cause Effect Graphing in Software Engineering Prerequisite - Black Box Testing Cause Effect Graphing based technique is a technique in which a graph is used to represent the situations of combinations of input conditions. The graph is then converted to a decision table to obtain the test cases. Cause-effect graphing technique is used because bo 3 min read Cause Effect Graphing in Software Engineering Prerequisite - Black Box Testing Cause Effect Graphing based technique is a technique in which a graph is used to represent the situations of combinations of input conditions. The graph is then converted to a decision table to obtain the test cases. Cause-effect graphing technique is used because bo 3 min read Cause Effect Graphing Example in Software Engineering Question: There are two columns: col1 and col2. The characters allowed in col1 are 'a' or 'b'. The characters allowed in col2 are digits 0-9. A file is updated if both the columns i.e. col1 and col2 are correct. If col1 is incorrect, message 'X' is displayed and if col2 is incorrect, message 'Y' is 1 min read Function Oriented Design - Software Engineering The design process for software systems often has two levels. At the first level, the focus is on deciding which modules are needed for the system based on SRS (Software Requirement Specification) and how the modules should be interconnected. Function Oriented Design is an approach to software desig 3 min read Function Oriented Design - Software Engineering The design process for software systems often has two levels. At the first level, the focus is on deciding which modules are needed for the system based on SRS (Software Requirement Specification) and how the modules should be interconnected. Function Oriented Design is an approach to software desig 3 min read Path Testing in Software Engineering Path Testing is a method that is used to design the test cases. In the path testing method, the control flow graph of a program is designed to find a set of linearly independent paths of execution. In this method, Cyclomatic Complexity is used to determine the number of linearly independent paths an 2 min read Like