Consider the following C program segment.

while (first <= last)

{

if (array [middle] < search)

first = middle + 1;

else if (array [middle] == search)

found = True;

else last = middle - 1;

middle = (first + last) / 2;

}

if (first < last) not Present = True;

The cyclomatic complexity of the program segment is __________.

This question was previously asked in

NIELIT Scientific Assistant A Official Paper 2020

Option 3 : 5

Probability and Statistics

2165

20 Questions
20 Marks
30 Mins

Concepts:

Predicates are if, else if, else, and if

Data:

Number of predicates = n = 4

Cyclomatic complexity = No. of predicates + 1

Formula:

Cyclomatic complexity = 4 + 1 = 5

**The cyclomatic complexity of the program segment is 5**

__Additional Information__

The cyclomatic complexity of a structured program[a] is defined with reference to the control flow graph of the program, a directed graph containing the basic blocks of the program, with an edge between two basic blocks if control may pass from the first to the second. The complexity M is then defined as

M = E − N + 2P,

where

E = the number of edges of the graph.

N = the number of nodes of the graph.

P = the number of connected components.