2

As the title say: I don't know the meaning of "complexity"

When I visit a web page of sonar result I would very much want to know how to calculate it.

Lheart
  • 59
  • 4
  • 1
    As this is tagged with sonar, I guess "complexity" is their definition at http://docs.codehaus.org/display/SONAR/Metrics+-+Complexity , and _not_ Big O notation for complexity. – nos Nov 14 '13 at 09:13
  • I don't think this question belongs on stackoverflow, unless you mean code-complexity which has nothing to do with sonar. – Tobberoth Nov 14 '13 at 10:07

1 Answers1

0

Definition of complexity on wikipedia here.

Complexity basically means how many actions your program performs proportional to the input. Usually it's calculated from your loops or the depth of your recursive functions.

Examples:

This has a complexity of O(n) because the actions in the for-loop are executed n times.

for (int i = 0 ; i < n ; ++i)

This has a complexity of O(n^2)

 for (int i = 0 ; i < n ; ++i)
      for (int j = 0 ; j < n ; ++j)

This also has a complexity of O(n):

 void recursion (int level, int n) {
      if (level < n)
          recursion(level + 1, n);
 }

Update:

Reading your comment, I think you're referring to Cyclomatic complexity, you can read about it here.There's a fairly good explanation in the Description section, but to be honest, I've never used / heard of this kind of complexity.

Lord Zsolt
  • 6,492
  • 9
  • 46
  • 76
  • 3
    Complexity is an asymptotical measure. It doesn't tell you the number of action your program performs.. it tells you how many more actions it'll perform if N grows bigger. – Benjamin Gruenbaum Nov 14 '13 at 08:11
  • So fast ^_^ But I'm not sure this is the answer , In the sonar web page , it show that the commplexity data like this : 2.5/function 17.2/class 19.9/file – Lheart Nov 14 '13 at 08:15
  • It tells you the number of actions performed, proportional to N. Sorry I didn't explain it adequately, but English isn't my native language. – Lord Zsolt Nov 14 '13 at 08:16
  • Are you referring to the Big O notation as complexity? If you're not sure, then you probably are ;) – Lord Zsolt Nov 14 '13 at 08:23
  • I find the artical: http://docs.codehaus.org/display/SONAR/Metrics+-+Complexity ^_^ – Lheart Nov 14 '13 at 09:36