#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
⚡ FREE · STEP BY STEP

Cyclomatic Complexity Calculator: V(G) From Code or a Flow Graph

Paste code or a flow graph to get V(G) and the number of basis paths to test.

  • 💻 C, Java, JS or Python code
  • 🕸️ Edge list with two methods
  • 🧪 Basis path count

How to use the Cyclomatic Complexity Calculator

  1. 1. Choose inputPaste a function, list flow-graph edges, enter E, N and P, or the number of decisions.
  2. 2. CalculateThe tool counts decisions or graph parts and applies McCabe's formula.
  3. 3. Use V(G)See V(G), how it was worked out, and the risk band. V(G) is the number of basis paths to test.

Three ways to calculate V(G)

McCabe's cyclomatic complexity counts the linearly independent paths through a program. It is also the least number of test cases needed for basis path testing. For a control flow graph:

  • V(G) = E − N + 2P, where E is edges, N is nodes and P is connected parts (1 for a single function).
  • V(G) = number of predicate (decision) nodes + 1, counting each binary decision once.
  • V(G) = number of regions in a planar flow graph, including the outside region.

In code, each if, else if, for, while, case, catch and each extra condition joined by && or || adds one decision. The ternary ?: also adds one.

Worked example

The default C function has: if (att < 75); if (m >= 90 && att >= 90), which counts as 2 (the if plus the &&); else if (m >= 75); one for loop; one while loop; and one ?: operator. That is 7 decisions, so V(G) = 7 + 1 = 8.

For the default flow graph (edges 1–2, 1–3, 2–4, 3–4, 4–5, 4–6, 5–7, 6–7) there are 8 edges, 7 nodes and 1 part. V(G) = 8 − 7 + 2 = 3. Nodes 1 and 4 each have two exits, so 2 decisions + 1 = 3 as well. You need 3 test cases to cover every basis path.

What the number means

McCabe's guide: 1–10 is simple and low risk, 11–20 is moderate, 21–50 is complex, and above 50 is very hard to test. Many teams refactor functions above 10. Tools differ slightly. Some do not count && and || (this gives the plain McCabe number), and some count each case label. Follow your syllabus. For test planning, see the test coverage calculator.

Frequently asked questions

Why does && count as a decision?

Short-circuit evaluation makes a && b two separate branches in the compiled code. Each extra condition adds a path. This is the extended McCabe count.

What if E − N + 2P and the predicate count differ?

The graph is probably not a proper flow graph. Check for unreachable nodes, missing edges or more than one exit node.

Does it handle several functions at once?

Code mode adds up all decisions and adds 1, which treats the code as one function. Paste one function at a time for per-function values.

How is V(G) used in testing?

It gives the number of independent paths. Basis path testing writes at least that many test cases so that every path is run once.

More free tools

See all free tools