Software Engineering (2160701)

BE | Semester-6   Winter-2017 | 11/03/2017

Q5) (a)

What is Cyclomatic complexity? Define Steps to find Cyclomatic complexity using flow graph.

Cyclomatic Complexity

  • Cyclomatic complexity is a source code complexity measurement that is being correlated to a number of coding errors. It is calculated by developing a Control Flow Graph of the code that measures the number of linearly-independent paths through a program module.
  • Lower the Program's Cyclomatic complexity, lower the risk to modify and easier to understand. It can be represented using the below formula:

Cyclomatic complexity = E - N + 2*P

Where,
E = number of edges in the flow graph.
N = number of nodes in the flow graph.
P = number of nodes that have exit points
 

Define Steps to find Cyclomatic complexity using flow graph

1. Count the number of regions on the graph
2. No. of predicates
3. No of edges – no. of nodes + 2
  • First and foremost start numbering the statement
  • Now you can clearly see which statement executes first and which last etc. so drawing the CFG becomes simple.
  • Now, to calculate Cyclomatic complexity you use one of three methods