Interviews Questions and Answers



What is cyclomatic complexity and why is it important?

Posted by: Teena
On 23 Sep 2011 | Views: 1891 | Categories: C#
Interview Answers(2)

 On 24 Sep 2011 07:05:00 AM
Cyclomatic complexity is a computer science metric developed by Thomas McCabe for generally measure the complexity of a program. It directly measures the number of linearly independent paths through a programs of the source code.

The concept, although not the method, is somewhat similar to that of general text complexity measured by the Flesch-Kincaid Readability Test.

Cyclomatic complexity is computed using a graph that describes the control flow of the program. The nodes of the graph correspond to the commands of a program. A directed edge connects two nodes, if the second command might be executed immediately after the first command. By definition,

CC = E - N + P


CC = cyclomatic complexity
E = the number of edges of the graph
N = the number of nodes of the graph
P = the number of connected components
 On 24 Sep 2011 07:49:32 AM
Cyclomatic complexity of a piece of code is the number of different paths available in the execution of the program.

If there is no branching (if-else or switch statement) and looping (do-while, while, and for loop), then the statements will execute linearly in the function. Hence Cyclomatic complexity =1;

A branching breaks thee linear flow of execution in two parts increasing the cyclomaticc complexity of the program. Same goes for thee looping statements.
Hence the more level of indentation we have in our program the more will be thee cyclomatic compexity

Post your Answers


Other lins

.Net Techies
Other lins