...
Software-Engineering
October 5, 2023
Software-Engineering
October 5, 2023
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

A
2
B
3
C
4
D
5
Question 27 Explanation: 
The cyclomatic complexity of a program can be calculated using the formula:

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.

Correct Answer: B
Question 27 Explanation: 
The cyclomatic complexity of a program can be calculated using the formula:

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.

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments

Video link

0
Would love your thoughts, please comment.x
()
x
error: Alert: Content selection is disabled!!