Q29.Marks: +2.0UGC NET Paper 2: Computer Science 2nd January 2026 Shift 1
Given below are two statements: one is labelled as Assertion A and the other is labelled as Reason R Assertion A: Higher cyclomatic complexity indicates a more complex program. Reason R: It is calculated based on the number of independent execution path in the program.
In the light of the above statements, choose the most appropriate answer from the options given below
1.Both A and R are correct and R is the correct explanation of A✓ Correct
2.Both A and R are correct but R is NOT the correct explanation of A
3.A is correct but R is not correct
4.A is not correct but R is correct
Solution
The correct answer is Both A and R are correct and R is the correct explanation of A.
Key Points
Higher cyclomatic complexity indicates that a program has more independent execution paths, making it more complex to understand, test, and maintain.
Cyclomatic complexity is a quantitative measure of the number of linearly independent paths through a program’s source code.
It is calculated using the formula: V(G) = E - N + 2P, where:
E: Number of edges in the control flow graph
N: Number of nodes in the control flow graph
P: Number of connected components
This measure helps in identifying modules or functions that are likely to have higher risks of defects due to their complexity.
Programs with high cyclomatic complexity require more rigorous testing to ensure all paths are covered adequately.
Additional Information
Uses of Cyclomatic Complexity:
Helps in determining the minimum number of test cases required to achieve complete branch coverage.
Assists in identifying overly complex code that may require refactoring for better maintainability.
Used as a metric to predict the effort required for testing and maintaining the code.
Significance of Cyclomatic Complexity:
Lower cyclomatic complexity indicates simpler and more maintainable code.
Higher values may indicate overly complex code that is difficult to test and prone to errors.
Threshold values are often set (e.g., 10) to identify modules that need simplification.
Best Practices:
Keep cyclomatic complexity low by writing modular and well-structured code.
Refactor functions or methods with high complexity to improve readability and maintainability.
Regularly review and analyze cyclomatic complexity as part of the code quality assurance process.
Important Points:
Cyclomatic complexity is language-agnostic and can be applied to any programming language.
Tools such as SonarQube, PMD, and others can be used to calculate cyclomatic complexity automatically.
Ensuring optimal complexity levels contributes to better software quality and reduced defect rates.