scitools.com

← Metric catalog

Essential Complexity is one of the source-code metrics Understand computes across 17+ languages — browse them in the GUI, export and track them, or script them with the Python API.

Essential Complexity

API ID: Essential
Also Known As: ev(G)
Languages: Ada, Basic, C#, C++, Fortran, Java, Jovial, Pascal, Python, Rust, Web
Targets: Files, Functions, Modules, Packages, Subprograms

The number of decision points + 1 after control graph reduction.

Essential complexity is the cyclomatic complexity after iteratively replacing all well structured control structures with a single statement. Structures such as if-then-else and while loops are considered well structured. Understand calculates the essential complexity by removing all the structured subgraphs from the control graph and then calculating the complexity. A graph that has only the regular single entry/single exit loops or branches will be reducible to a graph with complexity one. Any branches into or out of a loop or decision will make the graph non-reducible and will have Essential Complexity > 2. (You never get 2 since a graph with complexity 2 is always reducible to a graph with complexity 1)

For example:


void knotsDemo() {
  while (1) {
    if (a)
      break;
    if (b || c) {
      if (d || e) {
      }
      else {
        if (i)
          dosomething();
        else if (j)
          dosomething();
        else if (k)
          dosomething();
        else {}
      }
    }
  }
}

The if (b || c) { ... } block (with its nested if/else if/else chain) is a single-entry, single-exit sequence: every path through it reconverges before the loop repeats, so it reduces away to a single placeholder statement. The outer while (1) { if (a) break; } doesn't reduce: break is a branch out of the loop that reaches the same exit as the loop's own condition check, so that exit has more than one way in. What's left after reduction is just while (1) { if (a) break; } — 2 decision points (while, if), for an Essential Complexity of 3.

See Sum, Max, and Average Essential Complexity for aggregated values, such as for an architecture or the project.

Also known as McCabe - ev(G).


Targets By Language: Configuration: