CS FundamentalsVery hardProduct company interview · GATE level
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 3 times, depending on the input. How many distinct execution paths exist through the code, and what is its cyclomatic complexity?
- A. 85 paths; cyclomatic complexity 3
- B. 64 paths; cyclomatic complexity 4
- C. 85 paths; cyclomatic complexity 4
- D. 21 paths; cyclomatic complexity 4
Correct answer: C. 85 paths; cyclomatic complexity 4
One pass through the body can take 2 x 2 = 4 routes. With 0, 1, 2 or 3 iterations the number of paths is 1 + 4 + 16 + 64 = 85. Cyclomatic complexity counts decisions, not paths: the loop test, the if-else and the if give 3 decisions, so V(G) = 4. It is the number of linearly independent (basis) paths, which is why basis path testing needs only 4 tests although 85 paths exist. 64 counts only the three-iteration paths; 21 stops at two iterations.
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 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…
- Basic COCOMO for a semi-detached project uses Effort = 3.0 x KLOC^1.12 person-months and Development time = 2.5 x Effort^0.35 months. For…