Halstead Complexity 24032024 070911am
Halstead Complexity 24032024 070911am
Halstead metrics really only measures the lexical complexity, rather than structural
complexity of source code.
Software Science Example
1. procedure sort(var x:array; n: integer)
2. var i,j,save:integer;
3. begin
4. for i:=2 to n do
5. for j:=1 to i do
6. if x[i]<x[j] then
7. begin save:=x[i];
8. x[i]:=x[j];
9. x[j]:=save
10. end
11. end
Software Science Example
Operator # Operand #
1
procedure x 7
sort() 1 n 2
var 2 i 6
: 3 j 5
array 1 save 3
; 6 2 1
integer 2 1 1
, 2 n2=7 N2=25
begin…end 2
for..do 2 Size of vocabulary: 21
if…then 1 Program length: 60
:= 5 Program volume: 264
< 1 Program level: 0.04
[] 6 Programming effort: 6000
n1=14 N1=35 Estimated time: 333 seconds
Halstead Program Length:
• The total number of operator occurrences and the total
number of operand occurrences.
N = N1 + N2
And estimated program length is, N^ = n1log2n1 +
n2log2n2
The following alternate expressions have been
published to estimate program length:
• NJ = log2(n1!) + log2(n2!)
• NB = n1 * log2n2 + n2 * log2n1
• NC = n1 * sqrt(n1) + n2 * sqrt(n2)
• NS = (n * log2n) / 2
Halstead Vocabulary:
• The total number of unique operators and unique
operand occurrences.
n = n1 + n2
• Program Volume: Proportional to program size,
represents the size, in bits, of space necessary for
storing the program. This parameter is dependent on
specific algorithm implementation. The properties V, N,
and the number of lines in the code are shown to be
linearly connected and equally valid for measuring
relative program size.
V = Size * (log2 vocabulary) = N * log2(n)
The unit of measurement of volume is the common unit
for size “bits”. It is the actual size of a program if a
uniform binary encoding for the vocabulary is used. And
error = Volume / 3000
• Potential Minimum Volume: The potential minimum
volume V* is defined as the volume of the most succinct
program in which a problem can be coded.
V* = (2 + n2*) * log2(2 + n2*)
Here, n2* is the count of unique input and output
parameters
• Program Level: To rank the programming languages,
the level of abstraction provided by the programming
language, Program Level (L) is considered. The higher
the level of a language, the less effort it takes to
develop a program using that language.
L = V* / V OR IN ANOTHER FORM L=1/D
• he value of L ranges between zero and one, with L=1
representing a program written at the highest possible
level (i.e., with minimum size).
And estimated program level is L^ =2 * (n2) / (n1)(N2)
• Program Difficulty: This parameter shows how
difficult to handle the program is.
D = (n1 / 2) * (N2 / n2)
D=1/L
As the volume of the implementation of a program
increases, the program level decreases and the
difficulty increases. Thus, programming practices such
as redundant usage of operands, or the failure to use
higher-level control constructs will tend to increase the
volume as well as the difficulty.
• Programming Effort: Measures the amount of mental
activity needed to translate the existing algorithm into
implementation in the specified program language.
E = V / L = D * V = Difficulty * Volume
• Language Level: Shows the algorithm implementation
program language level. The same algorithm demands
additional effort if it is written in a
low-level program language. For example, it is easier to
program in Pascal than in Assembler.
L’ = V / D / D
lambda = L * V* = L2 * V
• Intelligence Content: Determines the amount of
intelligence presented (stated) in the program This
parameter provides a measurement of program
complexity, independently of the programming
language in which it was implemented.
I=V/D
C LANGUAGE RULES.