programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Liutauras Vilda
• Tim Cooke
• Jeanne Boyarsky
• Bear Bibeault
Sheriffs:
• Knute Snortum
• paul wheaton
• Devaka Cooray
Saloon Keepers:
• Tim Moores
• Stephan van Hulst
• Ron McLeod
• Piet Souris
• Ganesh Patekar
Bartenders:
• Tim Holloway
• Carey Brown
• salvin francis

# Cyclomatic Complexity

Ranch Hand
Posts: 186
1
Hello, I am attempting to find the cyclomatic complexity for a method in code. I have numbered the lines to represent nodes, although I'm not sure if it's 100% correct:

Here is a flow graph, again, I would like to get some feedback about whether I am correct or incorrect. Thanks!

if the img html tag does not work, here is my flow graph: https://1drv.ms/u/s!AvALpeZvjVx7geByBUjQVgZEZs2Lag

Marshal
Posts: 65474
249
Thankyou for the effort you put into that question

I looked up cyclomatic complexity on Wikipedia and it gives a formula for calculating it. Which formula did you use? I am presuming your diagram is correct and haven't verified it.

Greenhorn
Posts: 4
Hi Naziru,

From a psychological view, complexity varies in terms of nodes, as different analyst interprets nodes differently (some consider two sequences as one node while other treat them separately) but the underlying principle remains the same.

Using the P+1 formulae will tell you whether you're right or wrong if you're calculating from a given piece of code. P = Predicate. A predicate is where you have branches in your code. Eg.

From your code, I can see three predicates; Therefore 3P + 1 = 4 Regions and your answer shows only three regions.

You might want to look at it again.

 I'm still in control here. LOOK at this tiny ad! create, convert, edit or print DOC and DOCX in Java https://products.aspose.com/words/java