Home > Uncategorized > Cyclomatic complexity

Cyclomatic complexity

Cyclomatic complexity is a software metric (measurement) in computational complexity theory. It is used to measure the complexity of a program. It directly measures the number of linearly independent paths through a program’s source code. 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. This is done by counting the number of closed loops in the flow graph, and incrementing that number by one. i.e.
M = Number of closed loops + 1
where M = Cyclomatic number.
Let us see an example:
In the above example, the number of closed loops = 2. So Cyclomatic complexity=3.
In general, in order to fully test a module all execution paths through the module should be exercised. This implies a module with a high complexity number requires more testing effort than a module with a lower value since the higher complexity number indicates more pathways through the code. This also implies that a module with higher complexity is more difficult for a programmer to understand since the programmer must understand the different pathways and the results of those pathways.
Categories: Uncategorized
  1. No comments yet.
  1. October 7, 2011 at 12:37 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: