Does recursive method increase cyclometric complexity

I do not have programs designed to measure the complexity of the cyclometric code at the moment. But I wonder if a recursive method increases complexity?

eg.

// just a simple C# example to recursively find an int[] // within a pile of string[] private int[] extractInts(string[] s) { foreach (string s1 in s) { if (s1.ints.length < 0) { extractInts(s1); } else { return ints; } } } 

Thanks.

+6
complexity-theory recursion
source share
2 answers

As far as I understand, no. In your example, there is only one linearly independent path to the recursive method, so it will not increase cyclomatic complexity.

+4
source share
  • Cycles increase cyclomatic complexity.
  • A loop can often be overwritten using recursion plus a protection condition.

Even if the recursive call itself is not considered strictly as an increment, this is a protection condition. This makes a loop and recursion + guard on steam.

+1
source share

All Articles