Understanding Cyclomatic Complexity
Cyclomatic complexity is a software metric used to measure the complexity of a program’s control flow. It provides an indication of the number of linearly independent paths through the code, which correlates to the number of decision points, such as if statements and loops, in the code.
Exam Question
Cyclomatic complexity is a metric for:
(choose the best answer)
A. Determining the number of unit tests required to ensure correctness.
B. Measuring branching structures and nesting levels in code.
C. Assessing if code is written in as few lines as possible.
D. Demonstrating code is well structured and cleanly implemented.
Correct Answer
B. Measuring branching structures and nesting levels in code.
Explanation
Correct Answer
B. Measuring branching structures and nesting levels in code:
Cyclomatic complexity is specifically designed to measure the complexity of a program by counting the number of independent paths through the code’s control flow graph. This metric is directly related to the number of decision points, such as if, else, switch, for, while, and case statements, and helps developers understand how complicated the code is in terms of branching and nesting. Higher cyclomatic complexity can indicate more complex code that might be harder to test and maintain.
Why the Other Options Are Less Appropriate
A. Determining the number of unit tests required to ensure correctness:
While cyclomatic complexity can help identify the minimum number of test cases needed to cover all paths through the code, it does not directly determine the exact number of unit tests required. The metric is more about measuring the control flow complexity than defining test coverage.
C. Assessing if code is written in as few lines as possible:
Cyclomatic complexity does not measure the length of the code but rather the complexity of its control flow. Code can be short but still have high cyclomatic complexity if it contains many branching statements.
D. Demonstrating code is well structured and cleanly implemented:
While lower cyclomatic complexity can indicate simpler and potentially better-structured code, the metric itself does not directly assess the overall quality or cleanliness of the implementation. Other factors, such as readability, modularity, and adherence to design principles, also contribute to well-structured code.
Relevance to the PSD Exam
Understanding cyclomatic complexity is crucial for the PSD exam, as it highlights an important aspect of code quality and maintainability. It helps developers gauge the complexity of their code, which can impact testing, debugging, and long-term maintenance.
Key Takeaways
- Cyclomatic complexity measures the complexity of a program’s control flow by counting the number of independent paths.
- It is directly related to the number of branching structures and nesting levels in the code.
- Higher cyclomatic complexity can indicate more complex and potentially harder-to-maintain code.
Conclusion
Cyclomatic complexity is a metric used to measure the branching structures and nesting levels in code, helping developers assess the complexity of their programs.

Get ready for the official PSD exam
127 PSD practice questions, each with an in-depth explanation like the one above.
- Practice Mode: study at your own pace and choose the test length.
- Mock Exam Mode: 80 random questions in 60 minutes, like the real exam.
$29 is ScrumPrep's one-time price. The official PSD exam fee ($200) is paid separately to Scrum.org.
More PSD exam questions
- What does a test written in Test-Driven Development represent?
- Why might Developers choose to do pair programming?
- At Sprint Planning, the Scrum Team has NO clear standard to meet for releasable software. What should the Scrum Team do?
- When are individuals with testing and quality expertise included in the software development effort?
- What are some disadvantages of code coverage as a measurement for how well a system or product is tested?
