×

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

                       N= 15 ,  N2 = 9

                      n= 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

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.

Software Metrics

Introduction Software metrics is the term used in software engineering. Software engineering is the detailed study of the step-by-step making of user-interactive software that fulfills users' needs. Let's discuss two terms...

4 minutes read.

RAD Model in Software Engineering

RAD Model is an incremental process model and was developed by IBM in the 1980s and described in the book of James Martin entitled Rapid Application Development. Hence, user involvement is essential from...

3 minutes read.

Software Configuration Management

Software Configuration Management The process of Software Configuration Management contains operations such as controlling, managing, and organizing the source-code, documents, and other essential components during the Software Development Life Cycle.SCM is essential for all project...

3 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.

Spiral Model

The problem with traditional software process models is that they do not adequately deal with uncertainty, which is inherent to software projects. Major software projects had failed because project risks were neglected, and...

3 minutes read.

Routing Requests through Load Balancers

Let us first understand what load balancers are Assume a system works with multiple machines or servers, and as the requests arrive, they need to be routed to any one of...

3 minutes read.

Project Management Tools

Project Management Tools Risk and uncertainty increase in the size of the project, even when the project is developed according to the prescribed methods. We use project management tools to manage project management systems properly...

3 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.

Dropbox - System Design

While trying to upload or share any file, whether images, pdfs or documents, you would have come across the dropbox file posting service. Dropbox keeps all your data secure and...

9 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.

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...

6 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.

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.

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.

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.

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.

Scope of software metrics

Scope, Benefit, and Cycle of Software Metrics Software metrics have tremendous scope in software development to understand and fulfill various aspects of the project process. Software metrics help in estimation of...

6 minutes read.

V-Model

The V-model is also known as the verification and validation model. The V-model is also known as the verification and validation model. In this, each phase of the SDLC must be completed before...

3 minutes read.

Software Engineering Tutorial

The software has become critical to advancement in almost all areas of human endeavor. The art of programming is no longer enough to construct large programs. There are serious problems with the...

8 minutes read.