The Wayback Machine - https://web.archive.org/web/20240906045609/https://www.geeksforgeeks.org/complexity-metrics/
Open In App

Complexity Metrics

Last Updated : 18 Mar, 2021
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The productivity, if measured only in terms of lines of code per unit of time, can vary a lot depending on the complexity of the system to be developed. A programmer will produce a lesser amount of code for highly complex system programs, as compared to a simple application program. Similarly, complexity has a great impact on the cost of maintaining a program. To quantify complexity beyond the fuzzy notion of the ease with which a program can be constructed or comprehended, some metrics to measure the complexity of a program are needed.

A complexity measure is a cyclomatic complexity in which the complexity of a module is the number of independent cycles in the flow graph of the module. A number of metrics have been proposed for quantifying the complexity of a program, and studies have been done to correlate the complexity with maintenance effort. In this article, we will discuss a few complexity measures. Most of these have been proposed in the context of programs, but they can be applied or adapted for detailed design as well.

Size Measures: A complexity measure tries to capture the level of difficulty in understanding a module. In other words, it tries to quantify a cognitive aspect of a program. It is well known that, in general, the larger a module, the more difficult it is to comprehend. Hence, the size of a module can be taken as a simple measure of the complexity of the module. It can be seen that, on average, as the size of the module increases, the number of decisions in it is likely to increase. It means on average, as the size increases, the cyclomatic complexity also increases. Though it is clearly possible that two programs of the same size have substantially different complexities, in general, size is quite strongly related to some complexity measures.

Halstead’s Measure: Halstead also proposed a number of other measures based on his software science. Some of these can be considered complexity measures. A number of variables have been defined to explain this. These are n1 (number of unique operators), n2 (number of unique operands), N1 (total frequency of operators), and N2 (total frequency of operands). As any program must have at least two operators: one for function call and one for end of the statement—the ratio n1/2 can be considered the relative level of difficulty due to the larger number of operators in the program. The ratio N2/n2 represents the average number of times an operand is used. In a program in which variables are changed more frequently, this ratio will be larger. As such programs are harder to understand, ease of reading or writing is defined as:

D = \frac{n_{1}*N_{2}}{2*n_{2}}

Halstead’s Complexity Measure focused on the internal complexity of a module, as does McCabe’s complexity measure. Thus, the complexity of the module’s connection with its environment is not given much importance. In Halstead’s measure, a module’s connection with its environment is reflected in terms of operands and operators. A call to another module is considered an operator, and all the parameters are considered operands of this operator.

Live Variables: In a computer program, a typical assignment statement uses and modifies only a few variables. However, in general, the statements have a much larger context i.e., to construct or understand a statement, a programmer must keep track of a number of variables, other than those directly used in the statement. For a statement, such data items are called live variables. Intuitively, the more live variables for statements, the harder it will be to understand a program. Hence, the concept of live variables can be used as a metric for program complexity.

First, let us define live variables more precisely. A variable is considered live from its first to its last reference within a module, including all statements between the first and the last statement where the variable is referenced. Using this definition, the set of live variables for each statement can be computed easily by analysis of the module’s code. The procedure of determining the live variables can easily be automated.

For a statement, the number of live variables represents the degree of difficulty of the statement. This can be extended to the entire module by defining the average number of live variables. The average number of live variables is the sum of the count of live variables (for all executable statements) divided by the number of executable statements. This is a complexity measure for the module.

Live variables are defined from the point of view of data usage. The logic of a module is not explicitly included. The logic is used only to determine the first and last statement of reference for a variable. Hence, this concept of complexity is quite different from cyclomatic complexity, which is based entirely on the logic and considers data as secondary.

Another data usage-oriented concept is span, the number of statements between two successive uses of a variable. If a variable is referenced at N different places in a module, then for that variable there are (N – 1) spans. The average span size is the average number of executable statements between two successive references of a variable. A large span implies that the reader of the program has to remember a definition of a variable for a larger period of time (or for more statements). In other words, the span can be considered a complexity measure; the larger the span, the more complex the module.

Knot Count: A method for quantifying complexity based on the locations of the control transfers of the program has been proposed. It was designed largely for FORTRAN programs, where an explicit transfer of control is shown by the use of goto statements. A programmer, to understand a given program, typically draws arrows from the point of control transfer to its destination, helping to create a mental picture of the program and the control transfers in it. According to this metric, the more intertwined these arrows become, the more complex the program. This notion is captured in the concept of a knot.

A knot is essentially the intersection of two such control transfer arrows. If each statement in the program is written on a separate line, this notion can be formalized as follows. A jump from the line a to line b is represented by the pair(a, b). Two jumps (a, b) and (p, q) give rise to a knot if either min (a, b) < min (p, q) < max (a, b) and max (p, q) > max (a, b) or min (a, b) < max (p, qa) < max (a, b) and min (p, q) < min (a, b).

Problems can arise while determining the knot count of programs using structured constructs. One method is to convert such a program into one that explicitly shows control transfers and then compute the knot count. The basic scheme can be generalized to flow graphs, though with flow graphs only bounds can be obtained.

Topological Complexity:
A complexity measure that is sensitive to the nesting of structures has been proposed. Like cyclomatic complexity, it is based on the flow graph of a module or program. The complexity of a program is considered it’s maximal intersect number min.

To compute the maximal intersect, a flow graph is converted into a strongly connected graph (by drawing an arrow from the terminal node to the initial node). A strongly connected graph divides the graph into a finite number of regions. The number of regions is (edges – nodes + 2). If we draw a line that enters each region exactly once, then the number of times this line intersects the arcs in the graph is the maximal intersect min, which is taken to be the complexity of the program.  



Similar Reads

People Metrics and Process Metrics in Software Engineering
People Metrics and Process Metrics, both play important roles in software development. People Metrics helps in quantifying the useful attributes whereas Process Metrics creates the body of the software. People metrics focus on how well team members work together and their overall satisfaction, while process metrics measure how smoothly tasks are co
8 min read
Time Complexity and Space Complexity
Generally, there is always more than one way to solve a problem in computer science with different algorithms. Therefore, it is highly required to use a method to compare the solutions in order to judge which one is more optimal. The method must be: Independent of the machine and its configuration, on which the algorithm is running on.Shows a direc
14 min read
Extended Function Point (EFP) Metrics
Function Point (FP) measure was inadequate for many engineering and embedded systems. To overcome this, A number of extensions to the basic function point measure have been proposed. These are as follows: Feature Points: Feature Points are computed by counting the information domain values. It can be used in those areas where there is a level of co
3 min read
Measuring Software Quality using Quality Metrics
In Software Engineering, Software Measurement is done based on some Software Metrics where these software metrics are referred to as the measure of various characteristics of a Software. In Software engineering Software Quality Assurance (SAQ) assures the quality of the software. A set of activities in SAQ is continuously applied throughout the sof
3 min read
Object Oriented Metrics in Software Engineering
These are used to determine success or failure of a person also to quantify the improvements in the software throughout its process. These metrics can be used to reinforce good OO programming technique which lead to more reliable code. Object-oriented software engineering metrics are units of measurement that are used to characterize: object-orient
3 min read
Introduction Of People Metrics in Software Engineering
The concept of people metrics originated in the area of HR management. It provides a quantifiable measure of people's activity. These metrics are helpful to provide evidence of performance against things like objectives and goals. People's metrics have become important for Balanced Scorecards and other performance measurement systems. The reason is
8 min read
Short Note on Size-Oriented Metrics
Size-oriented metrics play a fundamental role in software development by measuring and comparing software project sizes based on various factors. This article explores the concept of size-oriented metrics, their advantages, and disadvantages, and provides an example of how they are applied in software organizations. What is Size Oriented Metrics?Si
3 min read
Most Important People Metrics in Software Engineering
Several important people metrics in software engineering can help measure the performance and effectiveness of a software development team. These metrics include: Productivity: This metric measures the amount of work that a team can complete within a given period. It can be measured by the number of lines of code written, the number of bugs fixed,
6 min read
Identifying Software Development Metrics - Software Engineering
Companies invest a fair proportion of their resources in the expensive staff that drive the development of technology on which an organization runs. It is therefore imperative to explore and quantitatively measure the performance of such investments by empowering teams with the ability to track their efficiency. This task is delegated to a designat
4 min read
Inspection Metrics in Software Engineering
Inspection metrics in software engineering measure the effectiveness of code reviews, design reviews, and other forms of inspections in identifying and resolving faults in the software. These metrics can help measure the efficiency and quality of the inspection process and provide insights into areas for improvement. Some common inspection metrics
6 min read
Software Measurement and Metrics
Software Measurement: A measurement is a manifestation of the size, quantity, amount, or dimension of a particular attribute of a product or process. Software measurement is a titrate impute of a characteristic of a software product or the software process. Table of Content Software Measurement PrinciplesNeed for Software MeasurementClassification
4 min read
Product Metrics in Software Engineering
In software engineering, product metrics are quantitative measures used to assess the characteristics of software products. These metrics help in evaluating various aspects such as quality, performance, maintainability, and complexity of the software. By providing objective data, product metrics enable developers and managers to make informed decis
8 min read
Halstead’s Software Metrics - Software Engineering
Halstead's Software metrics are a set of measures proposed by Maurice Halstead to evaluate the complexity of a software program. These metrics are based on the number of distinct operators and operands in the program and are used to estimate the effort required to develop and maintain the program. These metrics provide a quantitative assessment of
11 min read
Core Metrics to Manage Modern Process
Project management metrics are very necessary and essential for implementing practical and sustainable project management practices and processes in an organization. These metrics enable us to improve our understanding by simply removing uncertainty so that we can form well-informed decisions. These metrics are key to improving how projects are man
5 min read
Metrics for the Design Model of the Product
Metrics measures quantitative assessment that focuses on countable values most commonly used for comparing and tracking the performance of a system. Metrics are used in different scenarios like analyzing models, designing models, source code, testing, and maintenance. This article focuses on discussing metrics for the design model of the product. T
12 min read
Short Note on Function-Oriented Metrics
Function-oriented metrics are used to measure software characteristics based on the functionality provided to the user. These metrics focus on the functional aspects of software systems rather than on the implementation details or the code itself. This article focuses on discussing function-oriented metrics in detail. Table of Content What are Func
8 min read
What does 'Space Complexity' mean?
Space Complexity: The term Space Complexity is misused for Auxiliary Space at many places. Following are the correct definitions of Auxiliary Space and Space Complexity. Auxiliary Space is the extra space or temporary space used by an algorithm. The space Complexity of an algorithm is the total space taken by the algorithm with respect to the input
2 min read
Complexity of different operations in Binary tree, Binary Search Tree and AVL tree
In this article, we will discuss the complexity of different operations in binary trees including BST and AVL trees. Before understanding this article, you should have a basic idea about Binary Tree, Binary Search Tree, and AVL Tree. The main operations in a binary tree are: search, insert and delete. We will see the worst-case time complexity of t
4 min read
Comparison of an Array and Hash table in terms of Storage structure and Access time complexity
Arrays and Hash Tables are two of the most widely used data structures in computer science, both serving as efficient solutions for storing and accessing data in Java. They have different storage structures and time complexities, making them suitable for different use cases. In this article, we will explore the differences between arrays and hash t
3 min read
Time Complexity Analysis | Tower Of Hanoi (Recursion)
Tower of Hanoi is a mathematical puzzle where we have three rods and n disks. The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules: 1) Only one disk can be moved at a time. 2) Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack i.e. a disk ca
2 min read
Queries of nCr%p in O(1) time complexity
Given Q queries and P where P is a prime number, each query has two numbers N and R and the task is to calculate nCr mod p. Constraints: N &lt;= 106 R &lt;= 106 p is a prime number Examples: Input: Q = 2 p = 1000000007 1st query: N = 15, R = 4 2nd query: N = 20, R = 3 Output: 1st query: 1365 2nd query: 1140 15!/(4!*(15-4)!)%1000000007 = 1365 20!/(2
9 min read
Python Code for time Complexity plot of Heap Sort
Prerequisite : HeapSort Heap sort is a comparison based sorting technique based on Binary Heap data structure. It is similar to selection sort where we first find the maximum element and place the maximum element at the end. We repeat the same process for remaining element. We implement Heap Sort here, call it for different sized random lists, meas
3 min read
How is the time complexity of Sieve of Eratosthenes is n*log(log(n))?
Pre-requisite: Sieve of Eratosthenes What is Sieve of Eratosthenes algorithm? In order to analyze it, let's take a number n and the task is to print the prime numbers less than n. Therefore, by definition of Sieve of Eratosthenes, for every prime number, it has to check the multiples of the prime and mark it as composite. This process continues unt
3 min read
Complexity analysis of various operations of Binary Min Heap
A Min Heap is a Complete Binary Tree in which the children nodes have a higher value (lesser priority) than the parent nodes, i.e., any path from the root to the leaf nodes, has an ascending order of elements. In the case of a binary tree, the root is considered to be at height 0, its children nodes are considered to be at height 1, and so on. Each
3 min read
Time Complexity of Euclidean Algorithm
In this article, we will discuss the time complexity of the Euclidean Algorithm which is O(log(min(a, b)) and it is achieved. Euclid's Algorithm: It is an efficient method for finding the GCD(Greatest Common Divisor) of two integers. The time complexity of this algorithm is O(log(min(a, b)). Recursively it can be expressed as: gcd(a, b) = gcd(b, a%
4 min read
Constant & Linear Space Complexity in Algorithms
Being a programmer, you might have solved a lot of programming challenges. In programming space and time complexity matters a lot when we need to execute a program. Our algorithm should be efficient, and it should take less time. Whenever you're writing a solution to a program, some memory is required to complete, and it is important for our progra
5 min read
Miscellaneous Problems of Time Complexity
Prerequisite : Asymptotic Notations Time Complexity :Time complexity is the time needed by an algorithm expressed as a function of the size of a problem. It can also be defined as the amount of computer time it needs to run a program to completion. When we solve a problem of time complexity then this definition help the most - "It is the number of
15+ min read
Computational Complexity v/s Chomsky Hierarchy
1. Computational complexity :Computational complexity, a measure of the number of computing resources(time and space) that a particular algorithm consumes when it runs. The time complexity of a Turing machine is given by the function T(n), where T(n) = Maximum number of moves made by the TM to process a string of length n. The space complexity of t
4 min read
Logarithmic vs Double Logarithmic Time Complexity
Time complexity is the computational complexity that describes the amount of time it takes to run an algorithm.” Now, we know that there can be multiple ways we can solve any particular problem. But, knowing how we can solve the problem in the most efficient way is important in real-life applications. To find the efficiency of any algorithm or prob
3 min read
Can Run Time Complexity of a comparison-based sorting algorithm be less than N logN?
Sorting algorithms are the means to sort a given set of data in an order according to the requirement of the user. They are primarily used to sort data in an increasing or decreasing manner. There are two types of sorting algorithms: Comparison-based sorting algorithmsNon-comparison-based sorting algorithms Comparison-based sorting algorithms: The
3 min read