Software Engineering (2160701)

BE | Semester-6   Winter-2018 | 16-11-2018

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. The following steps should be followed for computing Cyclomatic complexity. Step 1 - Construction of graph with nodes and edges from the code Step 2 - Cyclomatic Complexity Calculation using formula V(G) = E - N + 2 Step 3 - Identification of independent paths Example
  1. Sum = 0;
  2. i = 1;
  3. While (i<=n){
  4. sum += i;
  5. ++I;
  6. }
  7. Printf(“%d”,sum)
  8. If(sum>0){
  9. printf(“Positive”);
  10. }
Step 1 - Construction of graph with nodes and edges from the code Example Step 2 - Cyclomatic Complexity Calculation using formula   V(G) = E - N + 2
  • Number of Node in given flow graphs is 10
  • Number of Edges in given flow graphs is 11
  • Number of nodes that have exit Points is 1.
So, Cyclomatic complexity   = E - N + 2*P   = 11 – 10+ 2(1)   = 3 Step 3 - Identification of independent paths   Path 1: 1 - 2 - 3 – 7 – 8 – 10   Path 2: 1 - 2 - 3 – 7 – 8 – 9 - 10   Path 3: 1 - 2 - 3 – 4 – 5 - 6 – 7 - 8 - 10