Control Flow Graph (CFG) – Software Engineering

Last Updated : 07 Jan, 2024
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
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 Graph

  1. The control flow graph is process-oriented.
  2. The control flow graph shows all the paths that can be traversed during a program execution.
  3. A control flow graph is a directed graph.
  4. 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:

  1. Entry Block: The entry block allows the control to enter into the control flow graph.
  2. 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 Graphs

Control Flow Graph is represented differently for all statements and loops. Following images describe it:

1. If-else

2. While

3. do-while

4. for

Example

if A = 10 then

if B > C

A = B

else A = C

endif

endif

print A, B, C

Flowchart of above example will be:

Control Flow Graph of above example will be:

Advantage of CFG

There are many advantages of a control flow graph.

  1. It can easily encapsulate the information per each basic block.
  2. It can easily locate inaccessible codes of a program and syntactic structures such as loops are easy to find in a control flow graph.

Similar Reads

Difference between Cash Flow and Fund Flow
Prerequisite - Cash Flow Forecasting | Software Engineering 1. Cash Flow : Cash flow refers to the concept of inflow and outflow of cash and cash equivalents during a particular period. In cash flow cash from the operations is calculated. It is useful for short term financing. It starts with opening and closing balance of cash and deals only with c
2 min read
Control Flow Software Testing
Control flow testing is a type of software testing that uses a program's control flow as a model. Control flow testing is a structural testing strategy. This testing technique comes under white box testing. For the type of control flow testing, all the structure, design, code and implementation of the software should be known to the testing team. T
3 min read
Cash Flow Forecasting - Software Engineering
Cash flow is the movement of money in and out of an organization. It involves the expenditure and income of an organization. This article focuses on discussing Cash flow forecasting in detail. Cash Flow ForecastingCash flow forecasting is the estimation of the cash flow over some time. It is important to do cash flow forecasting to ensure that the
2 min read
Introduction to Software Engineering - Software Engineering
Software is a program or set of programs containing instructions that provide the desired functionality. Engineering is the process of designing and building something that serves a particular purpose and finds a cost-effective solution to problems. Table of Content What is Software Engineering?Key Principles of Software EngineeringMain Attributes
9 min read
Process and Control Specification in Software Engineering
The process and control specifications help us to create mechanisms to show that the software developers can have a basic understanding of what they are going to develop for a particular company and understand the goals of a particular software more easily. Table of Content What is Process Specification in Software Engineering?What is Control Speci
7 min read
Numeric Control (NC) and Computer Numeric Control (CNC)
1. Numeric Control (NC) : Numeric Control is a traditional way of establishing an automated control on machining tools.This process is controlled by numbers, letters, symbols.The processes here are controlled by set of instructions which is called as a program.As it is a traditional or naive method, so it has less computational capability.It is les
2 min read
Reverse Engineering - Software Engineering
Software Reverse Engineering is a process of recovering the design, requirement specifications, and functions of a product from an analysis of its code. It builds a program database and generates information from this. This article focuses on discussing reverse engineering in detail. What is Reverse Engineering?Reverse engineering can extract desig
6 min read
Difference between Software Engineering process and Conventional Engineering Process
Software Engineering Process and Conventional Engineering Process, both are processes related to computers and development. In this article, we will see the similarities as well as differences between both, that is Software Engineering Process and the Conventional Engineering Process. Table of Content Software Engineering ProcessConventional Engine
4 min read
Re-engineering - Software Engineering
Software Re-engineering is a process of software development that is done to improve the maintainability of a software system. Re-engineering is the examination and alteration of a system to reconstitute it in a new form. This process encompasses a combination of sub-processes like reverse engineering, forward engineering, reconstructing, etc.  Tab
8 min read
Difference between Software Engineering and Computer Engineering
Software engineering and Computer engineering are two distinct disciplines that focus on different aspects of computer systems. While both fields require a strong foundation in computer science and mathematics, software engineering is focused on software development processes, while computer engineering is focused on the physical components and sys
6 min read
Article Tags :
three90RightbarBannerImg