SlideShare a Scribd company logo
HALSTEAD
COMPLEXITY
FAIZ UL HAQUE ZEYA
ORIGIN
• Halstead complexity measures are software metrics introduced by Maurice
Howard Halstead in 1977 as part of his treatise on establishing an empirical
science of software development. Halstead made the observation that metrics of
the software should reflect the implementation or expression of algorithms in
different languages, but be independent of their execution on a specific platform.
These metrics are therefore computed statically from the code.
HALSTEAD’S SOFTWARE SCIENCE
• Size-based metric
• Uses number of operators and operands in a piece of software
• n1 is the number of unique operators
• n2 is the number of unique operands
• N1 is the total number of occurrences of operators
• N2 is the total number of occurrences of operands
• Halstead derives various entities
• Size ofVocabulary: n = n1+n2
• Program Length: N = N1+N2
• ProgramVolume:V = Nlog2n
• Visualized as the number of bits it would take to encode the program being measured
HALSTEAD’S SOFTWARE SCIENCE
• PotentialVolume: V* = (2+n2)log(2+n2)
• V* is the volume for the most compact representation for the algorithm, assuming only two
operators: the name of the function and a grouping operator. n2 is minimal number of operands.
• Program Level: L =V*/V
• Programming Effort: E =V/L
• Programming Time in Seconds: T = E/18
• Numbers derived empirically, also based on speed human memory processes sensory input
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 #
procedure 1
sort() 1
var 2
: 3
array 1
; 6
integer 2
, 2
begin…end 2
for..do 2
if…then 1
:= 5
< 1
[] 6
n1=14 N1=35
Operand #
x 7
n 2
i 6
j 5
save 3
2 1
1 1
n2=7 N2=25
Size of vocabulary: 21
Program length: 60
Program volume: 264
Program level: 0.04
Programming effort: 6000
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.
1. Comments are not considered.
2. The identifier and function declarations are not considered
3. All the variables and constants are considered operands.
4. Global variables used in different modules of the same program are counted as multiple occurrences of the same variable.
5. Local variables with the same name in different functions are counted as unique operands.
6. Functions calls are considered operators.
7. All looping statements e.g., do {…} while ( ), while ( ) {…}, for ( ) {…}, all control statements e.g., if ( ) {…}, if ( ) {…} else {…},
etc. are considered as operators.
8. In control construct switch ( ) {case:…}, switch as well as all the case statements are considered as operators.
9. The reserve words like return, default, continue, break, size, etc., are considered operators.
10.All the brackets, commas, and terminators are considered operators.
11.GOTO is counted as an operator and the label is counted as an operand.
12.The unary and binary occurrences of “+” and “-” are dealt with separately. Similarly “*” (multiplication operator)
is dealt with separately.
13.In the array variables such as “array-name [index]” “array-name” and “index” are considered as operands and [
] is considered as operator.
14.In the structure variables such as “struct-name, member-name” or “struct-name -> member-name”, struct-
name, and member-name are taken as operands, and ‘.’, ‘->’ are taken as operators. Some names of member
elements in different structure variables are counted as unique operands.
15.All the hash directives are ignored.

More Related Content

PPTX
Halsted’s Software Science-An analytical technique
PDF
Halstead's software science - ananalytical technique
PDF
Software Metrics Course chapter 5 at Bahir Dar University
PPTX
Unit3_Software-MDFJHGFUGJFSJDFMHGSAD,MFKJASDFH,ADSFGAKSIF,AWKJEHGF,Aetrics.pptx
PPT
5. HALSTEAD SOFTWARE SCIENCE.ppt software engineering
PPTX
source code metrics and other maintenance tools and techniques
PDF
Software code metrics
DOCX
Techniques & applications of Compiler
Halsted’s Software Science-An analytical technique
Halstead's software science - ananalytical technique
Software Metrics Course chapter 5 at Bahir Dar University
Unit3_Software-MDFJHGFUGJFSJDFMHGSAD,MFKJASDFH,ADSFGAKSIF,AWKJEHGF,Aetrics.pptx
5. HALSTEAD SOFTWARE SCIENCE.ppt software engineering
source code metrics and other maintenance tools and techniques
Software code metrics
Techniques & applications of Compiler

Similar to HALSTEAD COMPLEXITY-SOFTWARE METRICS AND ESTIMATION (20)

PDF
A benchmark based approach to determine language verbosity - Hans Kuijpers - ...
PPTX
System Programming Overview
PPTX
C Course material
PDF
structured programming Introduction to c fundamentals
DOC
Implementation of halstead
PDF
A Performance Comparison Of C# 2013, Delphi Xe6, And Python 3.4 Languages
PPTX
PCCF UNIT 1.pptx
PDF
lec00-Introduction.pdf
PPT
programming language(C++) chapter-one contd.ppt
PDF
Introduction to computer programming language
PDF
Programming concepts By ZAK
PPTX
Mcs lec2
PPT
Agile development with Ruby
PPT
Chap 1-language processor
PPTX
Compiler an overview
PPTX
Programming _Language of Logic_ PPT.pptx
PPTX
Introduction to C Programming fjhjhjh.pptx
PPTX
Introduction_to_Programming.pptx
PPTX
DMA113 Chap1
PDF
Introduction to programming language (basic)
A benchmark based approach to determine language verbosity - Hans Kuijpers - ...
System Programming Overview
C Course material
structured programming Introduction to c fundamentals
Implementation of halstead
A Performance Comparison Of C# 2013, Delphi Xe6, And Python 3.4 Languages
PCCF UNIT 1.pptx
lec00-Introduction.pdf
programming language(C++) chapter-one contd.ppt
Introduction to computer programming language
Programming concepts By ZAK
Mcs lec2
Agile development with Ruby
Chap 1-language processor
Compiler an overview
Programming _Language of Logic_ PPT.pptx
Introduction to C Programming fjhjhjh.pptx
Introduction_to_Programming.pptx
DMA113 Chap1
Introduction to programming language (basic)
Ad

More from Faiz Zeya (17)

PPTX
FUNCTIONAL SIZE MEASURE AND ESTIMATES. SOFTWARE METRICS COURSE
PPTX
Line of code metrics. Software metrics and estimation
PPTX
Software metrics lecture 4 Usability metrics
PPTX
Lecture 2 software metrics and estimation.
PPTX
Software metrics and estimation lecture 1
PPTX
Reinforcement learning through human feedback
PPTX
Artificial Intelligence- lecture 1 BUKC lecture
PPT
Structure of Z Formal methods Lecture
PPTX
Elements of Z. Formal methods lecture
PPTX
Text editor in Z
PPTX
First order logic
PPTX
Word2vec Lecture. NLP BUKC lecture.
PPTX
Code completion using OpenAI APIs.pptx
PPTX
Types of machine learning.pptx
PPTX
Linear algebraweek2
PPTX
Query expansion for search improvement by faizulhaque
PPTX
Big data introduction
FUNCTIONAL SIZE MEASURE AND ESTIMATES. SOFTWARE METRICS COURSE
Line of code metrics. Software metrics and estimation
Software metrics lecture 4 Usability metrics
Lecture 2 software metrics and estimation.
Software metrics and estimation lecture 1
Reinforcement learning through human feedback
Artificial Intelligence- lecture 1 BUKC lecture
Structure of Z Formal methods Lecture
Elements of Z. Formal methods lecture
Text editor in Z
First order logic
Word2vec Lecture. NLP BUKC lecture.
Code completion using OpenAI APIs.pptx
Types of machine learning.pptx
Linear algebraweek2
Query expansion for search improvement by faizulhaque
Big data introduction
Ad

Recently uploaded (20)

PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
System and Network Administraation Chapter 3
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
history of c programming in notes for students .pptx
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
ISO 45001 Occupational Health and Safety Management System
PDF
Nekopoi APK 2025 free lastest update
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
medical staffing services at VALiNTRY
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Understanding Forklifts - TECH EHS Solution
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Design an Analysis of Algorithms I-SECS-1021-03
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
System and Network Administraation Chapter 3
How to Migrate SBCGlobal Email to Yahoo Easily
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PTS Company Brochure 2025 (1).pdf.......
history of c programming in notes for students .pptx
Wondershare Filmora 15 Crack With Activation Key [2025
Odoo Companies in India – Driving Business Transformation.pdf
Navsoft: AI-Powered Business Solutions & Custom Software Development
VVF-Customer-Presentation2025-Ver1.9.pptx
ISO 45001 Occupational Health and Safety Management System
Nekopoi APK 2025 free lastest update
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
medical staffing services at VALiNTRY
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Understanding Forklifts - TECH EHS Solution

HALSTEAD COMPLEXITY-SOFTWARE METRICS AND ESTIMATION

  • 2. ORIGIN • Halstead complexity measures are software metrics introduced by Maurice Howard Halstead in 1977 as part of his treatise on establishing an empirical science of software development. Halstead made the observation that metrics of the software should reflect the implementation or expression of algorithms in different languages, but be independent of their execution on a specific platform. These metrics are therefore computed statically from the code.
  • 3. HALSTEAD’S SOFTWARE SCIENCE • Size-based metric • Uses number of operators and operands in a piece of software • n1 is the number of unique operators • n2 is the number of unique operands • N1 is the total number of occurrences of operators • N2 is the total number of occurrences of operands • Halstead derives various entities • Size ofVocabulary: n = n1+n2 • Program Length: N = N1+N2 • ProgramVolume:V = Nlog2n • Visualized as the number of bits it would take to encode the program being measured
  • 4. HALSTEAD’S SOFTWARE SCIENCE • PotentialVolume: V* = (2+n2)log(2+n2) • V* is the volume for the most compact representation for the algorithm, assuming only two operators: the name of the function and a grouping operator. n2 is minimal number of operands. • Program Level: L =V*/V • Programming Effort: E =V/L • Programming Time in Seconds: T = E/18 • Numbers derived empirically, also based on speed human memory processes sensory input Halstead metrics really only measures the lexical complexity, rather than structural complexity of source code.
  • 5. 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
  • 6. SOFTWARE SCIENCE EXAMPLE Operator # procedure 1 sort() 1 var 2 : 3 array 1 ; 6 integer 2 , 2 begin…end 2 for..do 2 if…then 1 := 5 < 1 [] 6 n1=14 N1=35 Operand # x 7 n 2 i 6 j 5 save 3 2 1 1 1 n2=7 N2=25 Size of vocabulary: 21 Program length: 60 Program volume: 264 Program level: 0.04 Programming effort: 6000 Estimated time: 333 seconds
  • 7. 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
  • 8. HALSTEAD VOCABULARY: • The total number of unique operators and unique operand occurrences. n = n1 + n2
  • 9. • 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
  • 10. • 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
  • 11. • 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)
  • 12. • 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.
  • 13. • 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
  • 14. • 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
  • 15. • 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
  • 16. C LANGUAGE RULES. 1. Comments are not considered. 2. The identifier and function declarations are not considered 3. All the variables and constants are considered operands. 4. Global variables used in different modules of the same program are counted as multiple occurrences of the same variable. 5. Local variables with the same name in different functions are counted as unique operands. 6. Functions calls are considered operators. 7. All looping statements e.g., do {…} while ( ), while ( ) {…}, for ( ) {…}, all control statements e.g., if ( ) {…}, if ( ) {…} else {…}, etc. are considered as operators. 8. In control construct switch ( ) {case:…}, switch as well as all the case statements are considered as operators.
  • 17. 9. The reserve words like return, default, continue, break, size, etc., are considered operators. 10.All the brackets, commas, and terminators are considered operators. 11.GOTO is counted as an operator and the label is counted as an operand. 12.The unary and binary occurrences of “+” and “-” are dealt with separately. Similarly “*” (multiplication operator) is dealt with separately. 13.In the array variables such as “array-name [index]” “array-name” and “index” are considered as operands and [ ] is considered as operator. 14.In the structure variables such as “struct-name, member-name” or “struct-name -> member-name”, struct- name, and member-name are taken as operands, and ‘.’, ‘->’ are taken as operators. Some names of member elements in different structure variables are counted as unique operands. 15.All the hash directives are ignored.