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
- 4
- 6
- 3
- 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
- You have uncommitted changes but must switch branches quickly to fix an urgent…
- A bad commit has already been pushed to a shared main branch that teammates…
- A Scrum team completed 30, 34 and 26 story points in its last three sprints…
- Using Basic COCOMO in organic mode, Effort = 2.4 × (KLOC)^1.05 person-months…
- In mutation testing, 50 mutants are generated. 5 of them are equivalent…
- Why should you avoid rebasing commits that have already been pushed to a…
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