100% found this document useful (1 vote)
460 views3 pages

Halstead Complexity Measures

Halstead complexity metrics measure various aspects of a program's complexity directly from its source code, including program length, vocabulary size, volume, difficulty level, program level, effort required to implement, estimated length and time to implement. The metrics are based on counting the number of unique operators and operands in the code, and unique operators are used to estimate difficulty level and error-proneness while operands are used to measure vocabulary. Program volume is calculated as the product of program length and the logarithm of vocabulary size and indicates the program's implementation size.

Uploaded by

Fadwa Zed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
460 views3 pages

Halstead Complexity Measures

Halstead complexity metrics measure various aspects of a program's complexity directly from its source code, including program length, vocabulary size, volume, difficulty level, program level, effort required to implement, estimated length and time to implement. The metrics are based on counting the number of unique operators and operands in the code, and unique operators are used to estimate difficulty level and error-proneness while operands are used to measure vocabulary. Program volume is calculated as the product of program length and the logarithm of vocabulary size and indicates the program's implementation size.

Uploaded by

Fadwa Zed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Halstead Complexity measures

Halstead complexity metrics were developed by the late Maurice Halstead as a means of
determining a quantitative measure of complexity directly from the operators and operands in the
module to measure a program module's complexity directly from source code. Among the
earliest software metrics, they are strong indicators of code complexity. Halstead Science is an
estimation technique to find out size, time and effort of software.

Number of Operators and Operands:


Halsteads metrics is based on interpreting the source code as a sequence of tokens and
classifying each token to be an operator or an operand.
First we need to compute the following numbers, given the program:
n1 = the number of distinct operators
n2 = the number of distinct operands
N1 = the total number of operators
N2 = the total number of operands
The number of unique operators and operands (n1 and n2) as well as the total number of
operators and operands (N1 and N2) are calculated by collecting the frequencies of each operator
and operand token of the source program.
From these numbers, following measures can be calculated:

Program length (N):


The program length (N) is the sum of the total number of operators and operands in the program:
N = N1 + N2

Vocabulary size (n):


The vocabulary size (n) is the sum of the number of unique operators and operands:
n = n1 + n2

Program volume (V):


The program volume (V) is the information contents of the program, measured in mathematical
bits. It is calculated as the program length times the 2-base logarithm of thevocabulary size (n) :
V = N * log2(n)
Halstead's volume (V) describes the size of the implementation of an algorithm. The
computation of V is based on the number of operations performed and operands handled in the
algorithm. Therefore V is less sensitive to code layout than the lines-of-code measures.
The volume of a function should be at least 20 and at most 1000. The volume of a parameterless
one-line function that is not empty; is about 20. A volume greater than 1000 tells that the
function probably does too many things.
The volume of a file should be at least 100 and at most 8000. These limits are based on volumes
measured for files whose LOCpro and v(G) are near their recommended limits. The limits of
volume can be used for double-checking.
Difficulty level (D)

The difficulty level or error proneness (D) of the program is proportional to the number of
unique operators in the program.
D is also proportional to the ration between the total number of operands and the number of
unique operands (i.e. if the same operands are used many times in the program, it is more prone
to errors).
D = ( n1 / 2 ) * ( N2 / n2 )

Program level (L):


The program level (L) is the inverse of the error proneness of
I.e. a low level program is more prone to errors than a high level program.
L=1/D

the

program.

Effort to implement (E):


The effort to implement (E) or understand a program is proportional to the volume and to
the difficulty level of the program.
E=V*D

Estimated Program Length:


According to Halstead, The first hypothesis of software science is that the length of a well
Structured program is a function only of the number of unique operators and operands.
The estimated length is denoted by N^
N^= n1log2n1+n2log2n2

Potential Volume:
Amongst all the programs, the one that has minimal size is said to have the potential volume, V*.
Halstead argued that the minimal implementation of any algorithm was through a reference to a
procedure that had been previously written. The implementation of this algorithm would then
require nothing more than invoking the procedure and supplying the operands for its inputs and
output parameters.
V*= (2+n2*) log2( 2+n2*)

Estimated program Level/difficulty:


Halstead offered an alternate formula that estimates the program level.
L^ =2n2/n1N2
Hence, D =1 /L^

Effort:
Halstead hypothesized that the effort required to implement a program increases as the size of
the program increases. It takes more effort to implement a program at a lower level than the
higher level.
E= V/L^

Time to implement (T):


John stroud suggested that human mind is capable of making a limited number of elementary
discriminations per second. Stroud claims that (stroud number) ranges between 5 to 20. Since
Effort uses elementary discriminations as its unit of measure, the programming time would be:
T=E/
is normally set to 18 since this seemed to give best results in Halstead earliest experiments.

You might also like