EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

What is Cyclomatic Complexity?

By Priya PedamkarPriya Pedamkar

Home » Software Development » Software Development Tutorials » Software Testing Tutorial » What is Cyclomatic Complexity?

What is Cyclomatic Complexity?

Introduction to Cyclomatic Complexity

The Cyclomatic complexity is a measurement to calculate the code complexity and the errors present in the code using the graph methodology in which nodes of the graph represent source code and the arcs present in the graph represent the control flow in the program. The graph notation is used to find a number of ways for the given program and find the complexity of the program. The topological intricacy of the graph can be compared with computer program complexity.

What is Cyclomatic Complexity?

The measurement of efficiency of computer programs using the graphical representation method is known as Cyclomatic complexity. It is the software metric for finding complexity and errors present in the program. The complexity of source code can be easily measured by the Cyclomatic complexity. It was given by McCabe for finding the efficiency of a computer program. It uses the graphical representation in which the independent paths represent the number of ways in which the computer program can execute. This method uses the graph methodology to finding computer program complexity which can be easily applied for source files of the program, individual functions, and modules of the program. The flow of the graph is from top to bottom and the bottom node is used for representing the program end. The maximum value for the Cyclomatic complexity is given as ten. The use of Cyclomatic complexity can be done for software testing, finding the defects and the correlation among them and limiting the complexity of source code.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

It can be calculated by the given formula:

V(G) = E- N + 2*P

Here,

  • P =  Total connected components present in graph.
  • E = Total edge count in a graph.
  • N = Total nodes count in a graph.

For calculating the Cyclomatic complexity, the first graph is made from the assembly code. The assembly code is first to disassemble and then from that code graph is created in the following steps:

  • One node is created for one instruction.
  •  The nodes are internally connected to each other when the next instruction is related to previous instruction.
  •  The recursive call is considered as one functional call otherwise it will create a loop situation that will create a problem to calculate the Cyclomatic complexity for source program.

The Cyclomatic complexity is inversely proportional to code readability and easy to understand the code. It means when the Cyclomatic complexity is greater the code is not easy to understand and difficult to read and when the complexity is less the code is easy to read and easy to understand.

Properties of Cyclomatic Complexity

The Cyclomatic complexity uses a simple algorithm to calculate the program complexity. The Cyclomatic complexity has the formula V(G) = ‘E-N+2*P’ which is used for calculating the complexity of a computer program. For this methodology, it has certain properties that exist to calculate the Cyclomatic complexity. Some of them are mentioned below:

  1. E represents no. of edges present in the graph, M is McCabe’s complexity and N is nodes count.
  2. V(G) is an expression used for defining the number of the independent paths of the graph.
  3. The V(G) should be greater than 1.
  4. If the value of V(G) is equal to 1 then there is only one path in the graph which means there is only one solution to the computer program.
  5. The complexity should be less than 10.
  6. It is completely independent of source lines count in the computer program. The complexity does not depend on how many lines of code are there or how many branches are present in the graph.
  7. If the code is reformatted it does not affect the Cyclomatic complexity.
  8. The metric count gets linearly growth if the complexity of the function is increased. It means if the code contains a number of if-else statement it will directly increase the number of metric and the Cyclomatic complexity.
  9. This calculation is quite easy for a single function but when the number of function increases in the source program it increases the complexity calculation. The main reason for the increase in complexity is because of the function call which is not shown in the flow diagram.
  10. It is used for calculating the complexity of source code and not the complexity of data structures used in the source code.
  11. Greater the Cyclomatic complexity less efficient is the source code.

Advantages of Cyclomatic Complexity

It is used for calculating the code complexity and the errors present in the source code if any. Apart from these, there are several advantages, that need to be overlooked while using it for calculating the code complexity. Some of them are described below:

Popular Course in this category
Software Testing Training (9 Courses, 2 Projects)9 Online Courses | 2 Hands-on Projects | 60+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (4,892 ratings)
Course Price

View Course

Related Courses
Penetration Testing Training Program (2 Courses)TestNG Training (4 Courses, 2 Project)
  • As the Cyclomatic complexity calculates the independent paths for the source program, it gives the idea of a number of test cases for testing the source code. So when the number of independent path count is present it helps to test the code in that number of times. And by this, the whole code is covered for testing and solve the bugs if present.
  • By finding the code complexity the potential defect risk is also decreased which means the relative cost is reduced for finding the defects in source code.  By the Cyclomatic complexity calculation, the program maintenance cost is also reduced.
  • Based on the Cyclomatic complexity the project released can be shipped and the product can be on board in the organization.
  • It uses the graphical representation for representing the number of solutions for executing the same source code. And to calculate the Cyclomatic Complexity at that time became easier.

Conclusion

The Cyclomatic complexity uses the graphical representation to calculate the complexity of the source program. The graph uses the linear independent path which represents the individual solution for execution of source code. It is widely used for testing different software and finding defects in the source program.

Recommended Articles

This is a guide to the What is Cyclomatic Complexity?. Here we discuss the Introduction and the different Properties along with advantages. You can also go through our suggested articles to learn more –

  1. What is Automation Testing?
  2. Selenium Automation Testing
  3. Testing Methodologies
  4. Automation Testing Interview Questions

Software Testing Training (9 Courses, 2 Projects)

9 Online Courses

2 Hands-on Projects

60+ Hours

Verifiable Certificate of Completion

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
Software Testing Tutorial
  • Advance
    • Cyclomatic Complexity
    • Decision Table Testing
    • Decision Tree Algorithm
    • What is Continuous Integration
    • Mantis Bug Tracker
    • Equivalence Partitioning
    • Gantt Chart Software
    • Install TestNG
    • Install Unity
    • Defect Management Process
    • Test Plan Template
    • Testing Interview Questions
    • Testing of Mobile application
    • What is Test Automation Frameworks
    • Application of Automation
    • What is Cucumber?
    • 15 Best Popular Bug Reporting Tools
    • What is Automated Testing?
    • Software Maintenance Types
    • Software Reliability
    • Best Gantt Chart Software
    • Code Coverage
    • Branch Coverage
    • Decision Coverage
    • Statement Coverage
    • What is Test Case
    • Types of Test Case
    • What is Test Scenario
    • Formal Review
    • Alpha Beta Pruning
    • What is Cyclomatic Complexity?
    • Test Coverage
    • How to Write Test Case
    • Testing Documentation
    • Performance Testing Life Cycle
    • What is Xpath
    • Test Harness
    • Test Strategy
    • Software Incident Management
    • What is Debugging
    • What is Defect?
    • Listeners in TestNG
  • Basics
    • What is Software Testing
    • Careers in Software Testing
    • Defect Life Cycle in Software Testing
    • Levels of Software Testing
    • Software Testing Life Cycle
    • Software Tester Work
    • Software Testing Principles
    • Testing Methodologies
    • Grey Box Testing
    • Types of Software Testing
    • What is a Bug in Software Testing
    • Benefits of Automation Testing
    • What is Automation Testing?
    • Types of Automation
    • Automation Testing Process
    • Mobile Automation Testing
    • Automation Testing Life Cycle
    • Software Quality Assurance
    • Software Quality Assurance
    • What is Test Environment?
    • Verification and Validation Testing
  • Types of Testing
    • Adhoc Testing
    • Agile Testing
    • What is Agile Testing
    • Alpha and Beta Testing
    • Application Testing
    • Automation Testing
    • Benchmark Testing
    • Black Box Testing
    • Domain Testing
    • Dynamic Testing
    • Ecommerce Testing
    • Fuzz Testing
    • Gray Box Testing
    • GUI Testing
    • Installation Testing
    • Interface Testing
    • Interoperability Testing
    • Mainframe Testing
    • Manual Testing
    • Mutation Testing
    • Monkey Testing
    • Negative Testing
    • Penetration Testing
    • Protocol Testing
    • Recovery Testing
    • Regression Testing
    • Accessibility Testing
    • Sanity Testing
    • Scalability Testing
    • Security Testing
    • Spike Testing
    • Stability Testing
    • State Transition Testing
    • Static Testing
    • Gatling Load Testing
    • System Integration Testing
    • Structural Testing
    • Locust Load Testing
    • System Testing
    • Control Flow Testing
    • Unit Testing
    • Volume Testing
    • Web Testing Application
    • What is Exploratory Testing
    • What is Stress Testing
    • What is Usability Testing
    • White Box Testing
    • Types of White Box Testing
    • Compatibility Testing 
    • Use Case Testing
    • Beta Testing
    • Integration Testing
    • Non Functional Testing
    • What is Functional Testing
    • Cookie Testing
    • Alpha Testing
    • Boundary Value Testing
    • Equivalence Class Testing
    • Glass Box Testing
    • SOA Testing
    • Smoke Testing
    • Visual Testing
    • Visual Paradigm
    • Model-Based Testing
  • Testing techniques
    • Software Testing Methodologies
    • Black Box Testing Techniques
    • Static Testing Techniques
    • Test Case Design Techniques
    • What is Static Analysis
  • Testing tools
    • Automation Testing Tools
    • Functional Testing Tools
    • GUI Testing Tools
    • Penetration Testing Tools
    • Performance Testing Tools
    • SOA Testing Tools
    • Accessibility Testing Tools
    • What is QTP
    • Regression Testing Tools
    • Security Testing Tools
    • Test Management Tools
    • Code Coverage Tools
    • Test Coverage Tools
    • Defect Tracking Tools
    • Continuous Integration Tools
    • Install Bugzilla
    • Test data generation tool
    • Unit Testing Tools
    • Web Testing Tools
    • Stress Testing Tools
    • Performance Monitoring Tools
    • Mobile Testing Tools
    • Responsive Testing Tool
    • Cross Browser Testing Tools
    • Risk Based Testing
    • Database Testing Tools
    • WinRunner
    • What is Squish?
    • CubicTest
    • What is WinRM?
    • Bugzilla Tool
  • Inteview Questions
    • Automation Testing Interview Questions
    • Manual Testing Interview Questions
    • ISTQB Interview Questions
    • Cucumber Interview Questions
    • Software Testing Interview Questions
    • Penetration Testing Interview Questions

Related Courses

Software Testing Course

Penetration Training Course

TestNG Training Course

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

© 2020 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA Login

Forgot Password?

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

Special Offer - Software Testing Training (9 Courses, 2 Projects) Learn More