GateAI
Programming in C

GATE CSE 2015 Set 1 · Q42

NAT2 marksEasy

Time

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 _________.

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 5

Programming in C

Cyclomatic complexity V(G)V(G) of a control flow graph can be computed using the number of predicate (decision) conditions PP as:

V(G)=P+1V(G) = P + 1

Identifying the decision/predicate conditions in the given program segment:

  1. while(first <= last) — 1 predicate condition

  2. if (array[middle] < search) — 1 predicate condition

  3. else if (array[middle] == search) — 1 predicate condition

  4. if (first > last) — 1 predicate condition

Total number of predicate conditions:

P=4P = 4

Therefore, the cyclomatic complexity is:

V(G)=4+1=5V(G) = 4 + 1 = 5

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

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

Where do you stand for GATE?

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.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Programming in C in GATE CSE

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 C

More from GATE CSE 2015 Set 1

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2015 Set 1 · Q42 · NAT

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

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.