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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Jeanne Boyarsky
• Ron McLeod
• Paul Clapham
• Liutauras Vilda
Sheriffs:
• paul wheaton
• Rob Spoor
• Devaka Cooray
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Carey Brown
• Frits Walraven
• Tim Moores
Bartenders:
• Mikalai Zaikin

# Cyclomatic Complexity

Ranch Hand
Posts: 186
1
• Number of slices to send:
Optional 'thank-you' note:
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: 79469
379
• Number of slices to send:
Optional 'thank-you' note:
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
• Number of slices to send:
Optional 'thank-you' note:
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.

 Don't get me started about those stupid light bulbs.