The Gateway to Computer Science Excellence
+8 votes
2.4k views

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)
    notpresent = TRUE;

The cyclomatic complexity of the program segment is_______________.

in IS&Software Engineering by Boss (30.8k points)
retagged by | 2.4k views
+1
Is this topic out of  syllabus now ??

3 Answers

+21 votes
Best answer
Number of predicates = 4, if, else if, while and if.

Cyclomatic complexity = No. of predicates + 1 = 5.
by Veteran (431k points)
+1
Why else is not considered as predicate??
+4
predicate nodes with has out degree more than 2. else has only one
0

Anu007 

Can you please explain "out degree more than 2" ? Also why last "if" is included?

0
I think it is a part of software engineering and it is now out of syllabus ?

Right ??
+1 vote

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.  

Source: http://en.wikipedia.org/wiki/Cyclomatic_complexity For a single program (or subroutine or method), P is always equal to 1. So a simpler formula for a single subroutine is

    M = E − N + 2 

For the given program, the control flow graph is:q100

 E = 13, N = 10.

Therefore, E - N + 2 = 5. 

by Loyal (9.9k points)
0

Regina Phalange

Can you please explain how you got this control flow graph?

0

I learnt from this- 

0
Thank you.

But Im not getting the graph as you got. Can you name the nodes with variables please?
0 votes
it's 5
by Active (1.4k points)
Answer:

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,292 answers
198,236 comments
104,919 users