GATE / CS ARCHIVE

GATE CSE 2015 SET 3 / QUESTION 58

GATE CSE 2015 Set 3 Q58

Engineering Mathematics & Other Topics · Software Engineering · Full GATE CSE 2015 Set 3 paper

GATE 2015 Set 3, Q58 2 marks · MCQ
Not in GATE 2027 syllabusReport issue

Software Engineering

Question 58, GATE 2015: Find McCabe cyclomatic complexities of X,Y,Z in that order. Program X:
sumcal(int maxint,int value) {
 int result=0,i=0;
 if(value<0) { value=-value; }
 while((i<value) AND (result<=maxint)) { i=i+1; result=result+1; }
 if(result<=maxint) { printf(result); } else { printf("large"); }
 printf("end of program");
}
The shown control-flow graph Y has eight vertically ordered nodes v1,...,v8, edges vi→v(i+1) for i=1,...,7, and back edges v3→v1, v6→v4, v8→v1. Graph Z is serial composition of the graph of X followed by the graph of Y. Options: (A) 4,4,7; (B) 3,4,7; (C) 4,4,8; (D) 4,3,8. State the convention for counting the compound while condition.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

1. Treat each compound source-level condition as one decision: X has its first if, the while, and the final if, so complexity 4.

2. The shown Y graph has 8 vertices and 10 edges, giving E−N+2=4. Serial composition adds complexities minus 1, so Z=4+4−1=7. Thus A. Expanding the short-circuit AND into separate predicate nodes would increase X to 5 and Z to 8; the official answer uses source-statement predicate counting rather than that expanded control-flow model.

Original paper, page 76 · Answer key