Software Engineering · Question 27 · Hard

What is the cyclomatic complexity of this procedure?

procedure adjust(a, n)
    count = 0
    for i = 1 to n
        if a[i] > 0
            count = count + 1
        else if a[i] < 0
            count = count - 1
    while count > 10
        count = count - 2
    return count
  1. 4
  2. 6
  3. 3
  4. 5
Answer and explanation

Answer: D. 5

Explanation: The procedure has 4 simple decision points: the for loop, the if, the else if and the while loop. Cyclomatic complexity = number of decisions + 1 = 5.

Previous: A Scrum team completed 30, 34 and 26 story points in its last three sprints… · Next: Using Basic COCOMO in organic mode, Effort = 2.4 × (KLOC)^1.05 person-months…

Practise software engineering

Try a fresh set of software engineering questions with an explanation after every answer, free and without signing up: Software Engineering practice. Or sit a full placement mock test.

More software engineering questions

More technical & programming practice

Cloud & DevOps · GenAI Basics · Pseudo-code · C Programming · Java · Python · Data Structures · Algorithms

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge