Advanced Topic 42 of 50 Software Engineering
Cyclomatic Complexity
Count of independent paths through code.
How it works
Cyclomatic complexity, defined by Thomas McCabe, counts the number of linearly independent paths through a function's control-flow graph. It is computed as the number of decision points, such as if, loops, case labels and logical operators, plus one, or as edges minus nodes plus two. It indicates how many test cases are needed for path coverage and how hard the code is to understand. Values above about 10 are often considered a warning.
Where it is used
Linters and static analysis tools report it per function so that teams can find code to simplify and test thoroughly.
Common pitfall
High complexity correlates with defects, but the metric ignores nesting depth and data complexity and can be inflated by flat switch statements. Splitting a function merely to lower the number can hurt clarity. Use it as a signal to review, refactor with guard clauses, polymorphism or lookup tables, and make sure the complex code has tests.
Where it fits in the course
Cyclomatic Complexity is topic 42 of 50 in Software Engineering, rated Advanced. It follows Software Metrics. The next topic is Performance Profiling.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the Software Engineering quiz.
- Explore the Growth Rates (Big-O) visualizer: Chart O(1) to O(n!) as n grows.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the Software Engineering quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is Cyclomatic Complexity?
Where do people use Cyclomatic Complexity?
What is the most common mistake with Cyclomatic Complexity?
What should I learn before this topic?
How can I practice it?
Is Cyclomatic Complexity hard to learn?
How long does it take to learn Cyclomatic Complexity?
Which topics are related to Cyclomatic Complexity?
What should I study after Cyclomatic Complexity?
Related topics
- Software Metrics (Software Engineering)
- Performance Profiling (Software Engineering)
- GraphQL (Software Engineering)
- Formal Verification (Software Engineering)
- Time Complexity (Algorithms)
- Space Complexity (Algorithms)
- Complexity Classes (Theory & Discrete Math)