1. def is_prime(n):
2. if n <= 1:
3. return False
4. if n == 2 or n == 3:
5. return True
6. if n % 2 == 0 or n % 3 == 0:
7. return False
8. i = 5
9. while i * i <= n:
10. if n % i == 0 or n % (i + 2) == 0:
11. return False
12. i += 6
13. return True
Calculating the cyclomatic complexity purely by the formula: M = Decision Nodes + 1
, one gets cyclomatic complexity as 6.
But, when I draw the control flow graph for the same and use the formula M = E - N + 2
, I get the answer as 5. Why is there discrepancy?
P.S.: The nodes represent the line numbers. Nodes followed by an alphabet (4a, 4b, etc.) depict the two logical conditions about logical OR.
New contributor
Arsenic is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.