Halstead’s Complexity Measures

In 1977, Mr. Maurice Howard Halstead introduced metrics to measure software complexity. Halstead’s metrics depends upon the actual implementation of program and its measures, which are computed directly from the operators and operands from source code, in static manner. It allows to evaluate testing time, vocabulary, size, difficulty, errors, and efforts for C/C++/Java source code.

According to Halstead, “A computer program is an implementation of an algorithm considered to be a collection of tokens which can be classified as either operators or operands”. Halstead metrics think a program as sequence of operators and their associated operands.

He defines various indicators to check complexity of module.

ParameterMeaning
n1Number of unique operators
n2Number of unique operands
N1Number of total occurrence of operators
N2Number of total occurrence of operands

When we select source file to view its complexity details in Metric Viewer, the following result is seen in Metric Report:

MetricMeaningMathematical Representation
nVocabularyn1 + n2
NSizeN1 + N2
VVolumeLength * Log2 Vocabulary
DDifficulty(n1/2) * (N1/n2)
EEffortsDifficulty * Volume
BErrorsVolume / 3000
TTesting timeTime = Efforts / S, where S=18 seconds.

 

Softecks Admin is a seasoned software engineer, tech enthusiast, and problem solver with a passion for modern software development. With years of hands-on experience in coding, system architecture, and emerging technologies, they break down complex concepts into practical, easy-to-follow insights. Through this blog, they share in-depth tutorials, best practices, and industry trends to help developers level up their skills and build scalable, efficient software solutions.