Consider the following code segments.
Segment 1:
If a > b then setc = 12
elseif c >7 set c = 5
endif
Segment 2: setc= 12 for n = 1 to c
display c
endfor
Segment 3:
If (a > b) or (c < d) then
set c = 12
else
set c = 5
endlf
Segment 4:
set y = 4
call (segments)
segments:
start
for I = 1 to y
print y
endfor
end
Which segment would receive the highest cyclomatic complexity value?
Correct Answer: C
Cyclomatic complexity is a measure of the number of linearly independent paths through a program's source code. Segment 3 has two conditions: if (a > b) or (c < d) and the associated else. This structure introduces multiple decision points, thereby increasing the number of potential execution paths. Comparatively, the other segments have fewer conditions and straightforward loops, which contribute to a lower cyclomatic complexity.
Segment 3, with its compound condition and branching logic, likely has the highest cyclomatic complexity.