Consider the following C program segment. while(first last) notPresent = TRUE; The cyclomatic complexity of the program segment is …
Topic-wise GATE CS PYQs with verified steps
GATE CSE 2015 Set 1 · Q42
Time
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 _________.Your answerNumerical answer
Solution
Official answer: 5
Programming in CCyclomatic complexity of a control flow graph can be computed using the number of predicate (decision) conditions as:
Identifying the decision/predicate conditions in the given program segment:
while(first <= last) — 1 predicate condition
if (array[middle] < search) — 1 predicate condition
else if (array[middle] == search) — 1 predicate condition
if (first > last) — 1 predicate condition
Total number of predicate conditions:
Therefore, the cyclomatic complexity is:
Try the question first, then check your work.
Examiner trap
Cyclomatic complexity of a program can be determined as , where is the total count of decision/conditional statements.
This Programming in C previous year question is Q42 of the GATE CSE 2015 Set 1 paper. Find more GATE CSE PYQs on Programming in C in Programming and Data Structures, or browse all GATE CSE PYQs.
Free diagnostic
Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Programming in C PYQs now with no account.
An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.
Programming in C has 74 GATE CSE PYQs across 25 papers from 2011 to 2026. 17 of them are 2-mark NAT questions like this one, and GATE CSE 2015 Set 1 has 4.
How GATE tests Programming in CIndependent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.