###### Software-Engineering

October 5, 2023###### Software-Engineering

October 5, 2023# Software-Engineering

Question 27 |

Consider the following pseudo-code:

IF ((A > B) AND (C > D)) THEN A = A + 1 B = B + 1 ENDIF

The cyclomatic complexity of the pseudo-code is

2 | |

3 | |

4 | |

5 |

V(G) = E – N + 2P

Where:

V(G) is the cyclomatic complexity.

E is the number of edges in the control flow graph.

N is the number of nodes in the control flow graph.

P is the number of connected components (usually 1).

In your pseudo code, there are two conditional statements (A > B and C > D), and an “ENDIF” which represents the end of the conditional block. This forms a basic control flow structure.

Let’s break it down into a control flow graph:

Start (Node 1)

Condition A > B (Node 2)

Condition C > D (Node 3)

A = A + 1 (Node 4)

B = B + 1 (Node 5)

EndIF (Node 6)

Now, count the number of edges (E) and nodes (N):

E = 7 (7 transitions between nodes)

N = 6 (6 nodes)

Since there is only one connected component (P = 1), we have:

V(G) = E – N + 2P = 7 – 6 + 2 * 1 = 3

So, the cyclomatic complexity of your pseudo code is 3.

V(G) = E – N + 2P

Where:

V(G) is the cyclomatic complexity.

E is the number of edges in the control flow graph.

N is the number of nodes in the control flow graph.

P is the number of connected components (usually 1).

In your pseudo code, there are two conditional statements (A > B and C > D), and an “ENDIF” which represents the end of the conditional block. This forms a basic control flow structure.

Let’s break it down into a control flow graph:

Start (Node 1)

Condition A > B (Node 2)

Condition C > D (Node 3)

A = A + 1 (Node 4)

B = B + 1 (Node 5)

EndIF (Node 6)

Now, count the number of edges (E) and nodes (N):

E = 7 (7 transitions between nodes)

N = 6 (6 nodes)

Since there is only one connected component (P = 1), we have:

V(G) = E – N + 2P = 7 – 6 + 2 * 1 = 3

So, the cyclomatic complexity of your pseudo code is 3.

Video link