×

Halstead's Software Metrics

Halstead’s software science metrics

According to Halstead’s software metrics, a program is the implementation of an algorithm. These steps are considered as a number of tokens, and tokens are classified as operators and operands. All software science measures are functions of the counts of these tokens.

Token count

  1. Operator –Any symbol or keyword in a program that specifies an algorithm is considered an operator. For example, arithmetic symbols like (+. -. /,*), punctuation marks, common names (while, for, print f), special symbols (=, :) and function names.
  2. Operand– In an algorithm or program, a symbol is used to represent data, constants, variables, labels, etc. is considered as an operand.

For example:    

if (k< 2)
 {
k=3;
x=x*k;
  }
Halstead

Maurice Howard Halstead brought Halstead's software metrics concept in 1977 to measure the software metrics. Halstead's complexity measure is used to measure program module complexity directly from source code.

Two necessary measures of Halstead's software science are:

  • Size of vocabulary ղ ( known as Ita)

The size of the vocabulary of a program is defined as a number of unique tokens in a program used to build a program.

ղ =ղ1 + ղ2

where,

ղ = number of vocabulary in a program

ղ1 = number of unique operators

ղ2 = number of unique operands

By using this formula, we can find the total number of vocabulary in a given source code.

  • Length of program N

The total number of tokens in a program is termed as the Length of the program.

N = N1 + N2

Where,

N = Length of program

N1= Total occurrences of operators

N2 = Total occurrences of operators

Additional metrics are defined using these basic terms- the size of vocabulary and Length of the program. Another measure for the size of the program is known as:

  • Program Volume (V)

                                          V= N x log2ղ

Program volume is proportional to program size, represents the size of space necessary for sorting a program.

Unit of volume = Common unit of size “bits” {it is the actual size of the program if a uniform binary encoding for the vocabulary is used}

  • Potential Volume

                               V* = represents a program having a minimal size.

V* = (2+n2 *) log2(2+n2*)

  • Program Level

L = V* / V

Program level L = Ranges between 0 to 1

L =1 states that the program is written with minimum size.

Else if L=0 states program has a maximum size.

V* = potential volume {different or equivalent programs may implement an algorithm. Therefore program that is minimal in size will have potential volume}

Other different measures are:-

  • Program difficulty D

                                 D = ղ1/2 x N2 / ղ2

                                 D = 1/L

Difficulty measure is the difficulty of the program to read or write the program. If the program level decreases, difficulty to handle that program increases.

  • Effort –The amount of effort needed to translate an algorithm into implementation is specified programming language.

E = V/L = D x V

V = Volume of program

 L = Level of program

D =Program difficulty

V= Volume of program

  • Language Level λ

 λ = L* V* { L= V*/ V =>V*= LV}

                                      λ = L2 * V

  • Time required to program

T = E/ 18 sec

T = Time

E = Effort

  • Number of delivered bugs

B = E2/3/3000   {actually whole state delivered bugs is an estimated number of errors in the implementation}

Recently V/3000 is accepted for delivered bugs B.

  • Estimated program Length

The first hypothesis of software science is that the length of well structure software program is a function of number of unique operators and operands.

N =ղ1log2ղ1+ ղ2log2ղ2

ղ1 = number of unique operators

ղ2 = number of unique operands

  • Purity Ratio

                        P= N/N

Rules for finding the number of tokens in the C programming language

  • Comments, a function declared, identifier, and heading are not counted as tokens.
  • All the variables, constants, labels, and variable data are considered as operands.
  • The same variable used in the different functions is counted as a unique operator.
  • All looping statements, switch statements, case statements are considered as operators.
  • All the reserve words (default, sizeof, break, default, continue, return) and bracket, terminator, or commas are counted as a token(operators).
  • GOTO statement is the operator.
  • “Array name” and index are operands.
  • Hash derivatives are ignored.

Find the number of tokens using Halstead's metrics and find n, N, V, E, λ?

Example: 1

int sort (int x[ ], int n)
                    {
                    int i, j, save im1.
                 /* This function sorts an array*/
                      if (n<2) return 1;
                   for (i=2; i<=n, i=1)
                  { im 1= i-1;
                      for (i=1; j<= im1; j + i)
                           if (x[i]< x[j])
                          {save =x[j];
                            x [i] = x[j];
                           x [j] = save;
                            }}
                           return 0;
                           }
OperatorsOccurrencesOperandsOccurrences
int4SORT1
( )5x7
,4n3
[ ]7i8
if2j7
< 2save8
;11im 13
for223
=612
-103
<=2 1
++2  
return2  
{}3  
    
14531038

                      n= n1+n2

                         = 14 + 10 = 24

                    N = 53+38 = 91

                   V = N log2 n

                      = 91 log2 24

Example: 2

if (x>5)
                {
                 x= x + 2;
                 if (x < 7)
                {
                    x=0;
                  }
                }
N1 ( Operators)N2 ( Operands)
ifx
( )5
> x
{x
=2
;x
+7
Ifx
( )0
<  
{ 
= 
; 
} 
] 
  
159

                       N1  = 15 ,  N2 = 9

                      n1  = 9 ,  n2 = 5          

Total Length (N)

          N = N1 + N2  = 15 + 9 = 24

Vocabulary (n)

                 n = n1 + n2 = 9 + 5 = 14

N/ N

N = n1 log2 n1 + n2   log2 n2

     = 9 log2 9 + 5 log2 5

   = 9 log10 9 / 0.3010 + 5 log10 5 / 0.3010

   = 9 x (3.17) + 5 x (2.32)

   = 28.53 + 116

   = 40.13

Estimated Length = N/N = 40.13/ 24 = 1.67

Volume =  N log2 n

              = 24 log2 14

              = 24 x log10 14 / 0.3010

             = 24 x 3.807 = 91.36

      D = N1/ 2 x N2 / n2

   =  9/2 x 9/5 = 81 /10 = 8.1

Effort = V *D

          = 91.36 x 8.1 = 740.016


Related Topics

Metrics for testing

There are different types of metrics used in software testing to measure different parameters. So, for different purposes, different metrics are used by the developer. For example: The type of metrics...

3 minutes read.

Structured Analysis and Design (SA/SD)

When the software systems keep getting bigger and more complex, you need a way to represent the model systematically. Structured Design and Structured Analysis, often referred to as SA/SD, is...

4 minutes read.

Constructive Cost Model (COCOMO)

The constructive cost model (COCOMO) is one of the most widely used software cost estimation models. This model is developed by B.W.Boehm in 1981. COCOMO model is based on LOC, i.e., the number...

5 minutes read.

Project management activities

Project management activities Software project management involves many activities, including project planning, software product scope, cost estimation in various terms, scheduling of tasks and events, and resource management. Project management activities may include: Project PlanningScope ManagementProject...

2 minutes read.

Data Structure Metrics

In the size metric, we have learned to measure/ determine the size of a program by various software metrics such as line of code, Function count, and Token Count. A program...

6 minutes read.

Incremental Model in Software Engineering

Incremental Model is a software development process where requirements are divided into several stand-alone software development modules. In this example, each module passes through the requirement, design, development, implementation, and testing phases. That subsequent...

2 minutes read.

Overall Equipment Effectiveness

Overall Equipment Effectiveness (OEE) Overall equipment effectiveness is a software development metric used to diagnose a product or machinery's manufacturing productivity and effeteness. The term OEE was introduced by Seiichi Nakajima San...

4 minutes read.

Big-Bang Model in Software Engineering

In the Big-Bang Model, developers do not adopt any specific process. Development begins only with the necessary funds and efforts as input, and output is developed software that may or may not be...

1 minute read.

Prototype Model in Software Engineering

The prototype creation model is a method of developing the software in which a prototype of software or app is constructed, tested, and then reworked as needed until an acceptable result is obtained...

4 minutes read.

Load Balancer – System Design

As software engineering students or IT enthusiasts, most of us have wondered how these huge IT applications handle the millions of simultaneous requests on their servers. The sheer hard work...

9 minutes read.

Iterative Model in Software Engineering

This model consists of the same phases as the waterfall model, but with fewer restrictions. Generally, the phases occur in the same order as in the waterfall model, but these may be conducted...

2 minutes read.

Information Flow Metrics

This metric is purely based on information. Information flow metric is different from size metric, and data structure metric as size metric is based on the final size of program...

4 minutes read.

Project Monitoring and Control

Project Monitoring and Control Project monitoring and control process includes procedures which are performed to observe project performance so that potential problems are identified, and appropriate action can be taken to meet the desired performance...

3 minutes read.

Netflix - System Design

System design questions are common in many technical rounds for huge tech companies like Amazon, Google Flipkart. Candidates get confused about how they should answer the system doesn't question in...

12 minutes read.

Online Library Management System ER Diagram in Software Engineering

Description of an ER Diagram The relationship between entity sets that are kept in a database is depicted in a diagram known as an entity relationship diagram, or ER Diagram. Alternatively,...

10 minutes read.

Software Project Planning

Project planning is a management process that focuses on the activities required to complete a project successfully. Project planning helps to prevent problems that occur during the project development, such as a...

2 minutes read.

Twitter - System Design

You might have heard of Twitter, a widely used social media platform. Everybody tends to check it every few minutes. Imagine what you would do if you were asked to...

8 minutes read.

Object Oriented Metrices in Software Engineering

Metrics are used to measure the quality of software on different parameters. It provides acomputed accurate estimation of projects that help in developing software with minimal fault. “Metric is a set...

7 minutes read.

Some Important Quality Metrics

Important Quality Metrics The best quality of software has to pass through various software quality measures to attain standard in quality. The quality executive should consider these metrics to monitor the...

5 minutes read.

Project Management

Project Management What is a software project? The project is a set of tasks that need to be completed to reach a clear result. The project is also defined as the set of inputs...

2 minutes read.