CS FundamentalsVery hardProduct company interview · GATE level
What is the cyclomatic complexity of this fragment? Count each case label other than default as one decision and each simple condition separately.
What is the cyclomatic complexity of this fragment? Count each case label other than default as one decision and each simple condition separately.
switch (x) {
case 1: a(); /* falls through */
case 2: b(); break;
case 3: c(); break;
default: d();
}
while (k > 0 && !done) {
k--;
if (k == 5) continue;
log(k);
}- A. 8
- B. 7
- C. 16
- D. 11
Correct answer: B. 7
The switch has 3 non-default case decisions (the fall-through adds an edge, not a decision), the loop condition 2 and the if 1: 6 decisions, V(G) = 7. Counting default too gives 8; 16 and 11 are the edge and node counts of the flow graph (16 − 11 + 2 = 7).
Practise more Software Engineering, Git and Cloud Basics questionsSoftware Engineering, Git and Cloud Basics: notes and key points
More Software Engineering, Git and Cloud Basics questions
- A loop body contains an if-else followed by an independent if (with no else), and nothing else that branches. The loop runs between 0 and…
- A function has 4 independent integer inputs, each with a closed valid range. How many test cases do robust boundary value analysis (min…
- A form has three inputs. Input A has 3 valid and 2 invalid equivalence classes, B has 4 valid and 1 invalid, and C has 2 valid and 2…
- What is the minimum number of test cases that achieves MC/DC (unique-cause modified condition/decision coverage: for every condition, two…
- A configuration test has four parameters: browser (4 values), OS (3 values), language (2 values) and network (2 values). What is the…
- The tests (x = 3, y = 4) and (x = -2, y = 7) are run on this function. What statement, branch (decision) and condition coverage do they…