SlideShare a Scribd company logo
Cyclomatic complexity
• Cyclomatic complexity of a code section is the quantitative measure
of the number of linearly independent paths in it.
• It is a software metric used to indicate the complexity of a program.
• It is computed using the Control Flow Graph of the program.
Control Flow Graph (CFG)
• A Control Flow Graph (CFG) is the graphical representation of control flow or
computation during the execution of programs or applications.
• Control flow graphs are mostly used in static analysis as well as compiler
applications, as they can accurately represent the flow inside of a program unit.
• The control flow graph was originally developed by Frances E. Allen.
Characteristics of Control Flow Graph
• Control flow graph is process oriented.
• Control flow graph shows all the paths that can be traversed during a program
execution.
• Control flow graph is a directed graph.
• Edges in CFG portray control flow paths and the nodes in CFG portray basic
blocks.
Control Flow Graph (CFG)
Control Flow Graph (CFG)
Control Flow Graph (CFG)
Control Flow Graph (CFG)
Control Flow Graph (CFG)
Advantages of Control Flow Graph (CFG)
• It can easily encapsulate the information per each basic block.
• It can easily locate inaccessible codes of a program and syntactic structures such
as loops are easy to find in a control flow graph.
Cyclomatic complexity
• The nodes in the graph indicate the smallest group of commands of a program,
and a directed edge in it connects the two nodes i.e. if second command might
immediately follow the first command.
• For example, if source code contains no control flow statement then its cyclomatic
complexity will be 1 and source code contains a single path in it.
• Similarly, if the source code contains one if condition then cyclomatic complexity
will be 2 because there will be two paths one for true and the other for false.
Cyclomatic complexity
• Cyclomatic complexity M would be defined as,
Steps to calculate Cyclomatic complexity
• Construction of graph with nodes and edges from code.
• Identification of independent paths.
• Cyclomatic Complexity Calculation
• Design of Test Cases
Steps to calculate Cyclomatic complexity
Steps to calculate Cyclomatic complexity
Use of Cyclomatic Complexity
• Risk associated with program can be evaluated.
• Determining the independent path executions thus proven to be very helpful for
Developers and Testers.
• It can make sure that every path have been tested at least once.
• Thus help to focus more on uncovered paths.
• Code coverage can be improved.
• These metrics being used earlier in the program helps in reducing the risks.
Advantages of Cyclomatic Complexity
• It can be used as a quality metric, gives relative complexity of various designs.
• It is able to compute faster than the Halstead’s metrics.
• It is used to measure the minimum effort and best areas of concentration for
testing.
• It is able to guide the testing process.
• It is easy to apply.
Exercise
Exercise
Exercise
Exercise
Exercise
Exercise
Exercise
Exercise
Exercise

More Related Content

PPT
cyclomatic complexity.ppt_software developement
PPTX
cyclomatic complecity.pptx
PPTX
Calculation of Cyclomatic complexity
PPTX
How to calculte Cyclomatic Complexity through various methods
PDF
Cyclomatic complexity
PPTX
Basis path testing
PPT
7-White Box Testing.ppt
PPTX
Basis path testing
cyclomatic complexity.ppt_software developement
cyclomatic complecity.pptx
Calculation of Cyclomatic complexity
How to calculte Cyclomatic Complexity through various methods
Cyclomatic complexity
Basis path testing
7-White Box Testing.ppt
Basis path testing

Similar to 3.Cyclomatic complexity abu dhabi uni.ppt (20)

PPTX
Unit3_Software-MDFJHGFUGJFSJDFMHGSAD,MFKJASDFH,ADSFGAKSIF,AWKJEHGF,Aetrics.pptx
PPTX
Control Flow Testing
PDF
Software Metrics Course chapter 6 at Bahir Dar University
PPTX
Cyclomatic and cognitive complexity
PPTX
Software engineering module 4 notes for btech and mca
PPT
Software Engineering (Testing techniques)
PPT
Software Engineering (Testing techniques)
PPTX
Cyclomatic complexity
PPT
11 whiteboxtesting
PDF
Your cyclomatic complexity is so 1.9,76
PDF
20100309 02 - Software testing (McCabe)
PPT
2. Lect 27 to 28 White box s/w testing.ppt
PDF
A WHITE BOX TESTING TECHNIQUE IN SOFTWARE TESTING : BASIS PATH TESTING
PDF
Software Engineering : Software testing
PPSX
White Box testing by Pankaj Thakur, NITTTR Chandigarh
PDF
Code quailty metrics demystified
PPT
white box testing.ppt
PDF
Software Metrics Software Metrics chapter 6.pdf
PDF
ST Module 3 vtu prescribed syllabus and scheme
PPT
Path testing, data flow testing
Unit3_Software-MDFJHGFUGJFSJDFMHGSAD,MFKJASDFH,ADSFGAKSIF,AWKJEHGF,Aetrics.pptx
Control Flow Testing
Software Metrics Course chapter 6 at Bahir Dar University
Cyclomatic and cognitive complexity
Software engineering module 4 notes for btech and mca
Software Engineering (Testing techniques)
Software Engineering (Testing techniques)
Cyclomatic complexity
11 whiteboxtesting
Your cyclomatic complexity is so 1.9,76
20100309 02 - Software testing (McCabe)
2. Lect 27 to 28 White box s/w testing.ppt
A WHITE BOX TESTING TECHNIQUE IN SOFTWARE TESTING : BASIS PATH TESTING
Software Engineering : Software testing
White Box testing by Pankaj Thakur, NITTTR Chandigarh
Code quailty metrics demystified
white box testing.ppt
Software Metrics Software Metrics chapter 6.pdf
ST Module 3 vtu prescribed syllabus and scheme
Path testing, data flow testing
Ad

Recently uploaded (20)

PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
PDF
Classroom Observation Tools for Teachers
PDF
Complications of Minimal Access Surgery at WLH
PPTX
UNIT III MENTAL HEALTH NURSING ASSESSMENT
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Weekly quiz Compilation Jan -July 25.pdf
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Cell Types and Its function , kingdom of life
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
IGGE1 Understanding the Self1234567891011
PPTX
Digestion and Absorption of Carbohydrates, Proteina and Fats
PDF
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PPTX
Introduction to Building Materials
PDF
advance database management system book.pdf
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
Classroom Observation Tools for Teachers
Complications of Minimal Access Surgery at WLH
UNIT III MENTAL HEALTH NURSING ASSESSMENT
Supply Chain Operations Speaking Notes -ICLT Program
Weekly quiz Compilation Jan -July 25.pdf
202450812 BayCHI UCSC-SV 20250812 v17.pptx
A systematic review of self-coping strategies used by university students to ...
Computing-Curriculum for Schools in Ghana
Cell Types and Its function , kingdom of life
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
IGGE1 Understanding the Self1234567891011
Digestion and Absorption of Carbohydrates, Proteina and Fats
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
LDMMIA Reiki Yoga Finals Review Spring Summer
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
Introduction to Building Materials
advance database management system book.pdf
Ad

3.Cyclomatic complexity abu dhabi uni.ppt

  • 1. Cyclomatic complexity • Cyclomatic complexity of a code section is the quantitative measure of the number of linearly independent paths in it. • It is a software metric used to indicate the complexity of a program. • It is computed using the Control Flow Graph of the program.
  • 2. Control Flow Graph (CFG) • A Control Flow Graph (CFG) is the graphical representation of control flow or computation during the execution of programs or applications. • Control flow graphs are mostly used in static analysis as well as compiler applications, as they can accurately represent the flow inside of a program unit. • The control flow graph was originally developed by Frances E. Allen.
  • 3. Characteristics of Control Flow Graph • Control flow graph is process oriented. • Control flow graph shows all the paths that can be traversed during a program execution. • Control flow graph is a directed graph. • Edges in CFG portray control flow paths and the nodes in CFG portray basic blocks.
  • 9. Advantages of Control Flow Graph (CFG) • It can easily encapsulate the information per each basic block. • It can easily locate inaccessible codes of a program and syntactic structures such as loops are easy to find in a control flow graph.
  • 10. Cyclomatic complexity • The nodes in the graph indicate the smallest group of commands of a program, and a directed edge in it connects the two nodes i.e. if second command might immediately follow the first command. • For example, if source code contains no control flow statement then its cyclomatic complexity will be 1 and source code contains a single path in it. • Similarly, if the source code contains one if condition then cyclomatic complexity will be 2 because there will be two paths one for true and the other for false.
  • 11. Cyclomatic complexity • Cyclomatic complexity M would be defined as,
  • 12. Steps to calculate Cyclomatic complexity • Construction of graph with nodes and edges from code. • Identification of independent paths. • Cyclomatic Complexity Calculation • Design of Test Cases
  • 13. Steps to calculate Cyclomatic complexity
  • 14. Steps to calculate Cyclomatic complexity
  • 15. Use of Cyclomatic Complexity • Risk associated with program can be evaluated. • Determining the independent path executions thus proven to be very helpful for Developers and Testers. • It can make sure that every path have been tested at least once. • Thus help to focus more on uncovered paths. • Code coverage can be improved. • These metrics being used earlier in the program helps in reducing the risks.
  • 16. Advantages of Cyclomatic Complexity • It can be used as a quality metric, gives relative complexity of various designs. • It is able to compute faster than the Halstead’s metrics. • It is used to measure the minimum effort and best areas of concentration for testing. • It is able to guide the testing process. • It is easy to apply.

Editor's Notes

  • #7: The top diamond is the first decision: A == 10 If false, it skips directly to the print statement. If true, it checks the second condition: B > C. The second diamond handles the nested if: If true, A = B If false, A = C Both branches then merge back at the end-if and go to print A, B, C. 💡 Teaching Point: This flowchart helps you visualize the decision points (conditions) and the branches that will become part of the control flow graph when calculating cyclomatic complexity.