1) The document discusses software metrics and Halstead's software science measures including program length, vocabulary, volume, difficulty, and effort. It provides the formulas to calculate these measures and an example calculation for a C function.
2) Guidelines are provided for identifying operands and operators when applying Halstead's measures to source code. Various program elements like variables, functions, and statements are classified.
3) The document also discusses other software metrics like lines of code (LOC) and function points which can be used to measure size and complexity. It provides a sample calculation of LOC and function points for a simple program.
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
Software Metrics and Halstead's Software Science
1. Software Engineering (KCS-601)
Unit-3 (Second Part): Software Metrics
Dr. Radhey Shyam
Professor
Department of Computer Science and Engineering
SRMCEM Lucknow
(Affiliated to Dr. A.P.J. Abdul Kalam Technical University, Lucknow)
Unit-3 (Second part) have been compiled/prepared by Dr. Radhey Shyam, with grateful acknowledgment
who made their course contents freely available or (Contributed directly or indirectly). Feel free to use this
study material for your own academic purposes. For any query, the communication can be made through
this mail shyam0058@gmail.com.
April 18, 2022
2. Soktwahe Moi
LAtuanr Meic o a
e L
ChaadTe ietis wi a guaru
Cautalle
Cturan
m
u u a d i i b l e
tale Mtsics ane wpetat o n a n
acens nelmdin
Penomanee, lamm n w lomo M
pmdutliwit, a mam tha uCea,
Meacun n
7Maio ahe an imotant Coen
ualt acsuramu Manasemot debus
iming e ano
mami
a valnalle tr bth devlAare a
denel mot am lendars,
e n a dieren setw MaT
O RLad sAtwane MDit eyelmdlic
Cala funlow Poinh and LoC
matrics, Cnebv
3. FP and Loc bas
elatinel
LOT a g.nelia of Colo
Course Name: M. Tech Halto AAsae sei C
A
aetaralt rdiclod wa
t o u n
Semester: 2nd Logk N, t N
Paper Name: Object Oriented Software Engineering (MTCS-203B) 7
Topic: Halstead's Software Science. ocahulay7,f n
wlam N
Halstead's SoftwareScience
Halstead's Software Science
Halstead's complexity measurement was developed to measure a program module's complexiny
directly from source code, with emphasis on
computational complexity.
The Halstead's measures are based on four scalar number derived directly from a program s
source code:
n 1S number of distinct operators.
n2 is number of distinct operands.
eurYante v
Ni is total number of/distinct operators.
N is total number ofdistinct operands
From these numbers, five measures are derived:
Measure Symbol Formula
Program length N N=NI +Na
Programvocabulary N n=nitn2
Volume V=N* (log2 n)
Difficulty D D (n1/2)*(N2/2)
Effort E E=D*V
4. iaistead's uses certain measures such as program length, program vocabulary, v
difficulty, and effort for the given algorithm. By this Halstead's is trying to show that une
program length can be caleulated, volume of algorithm can be estimated. The above given table
shows how actually these measure can be obtained.
The Halstead's measures are applicable to operational system and to development eforts once
the code has been written. Thus using Halstead's measurement experimental verification can be
performed in software science.
Program length:
The length of a program is total usage of operators and operands in the program.
Length (N) =Ni+N2
Program vocabulary:
The Program vocabulary is the number of unique operators and operands used in the program.
Vocabulary (n) = ni t n2
Program Volume:
The Program Volume can be defined as minimum number of bits needed to encode the program.
Volume (V) = N loga n
Length estimation:
N=ni log2 ni t n2 log2 n2
Guideline for caleulating operands and operators:
1. All the variables and constants are considered as operands.
2. Local variables with same name, if occurring in different functions are counted as unique
operand.
3. Function calls are considered as operators.
5. 4 The looping statements, do... while, while, for, are operators. The statements i, i
else, are operators. The switch . . .
case statements are considered as operators.
5. The reserve worlds, returns, default, continue, break, sizeof are all operators.
6. The brackets, commas, semicolons, are operators.
7. The unary and binary operators are considered as operators. The & is considered
as
operator.
8. In arrays, array name and index are considered as operands and [ ] is considered
as
operator.
9. All hash directives can be ignored.
10. Comments are not considered.
11. In Goto statement, goto is considered as operatorand label as operand.
Example: Obtain Halstead's length and volume measure for following C function.
)
(CtinatashengtE
Void swap (int a[ ], int i)
uelwme N n
int temp;
Fr Comptalia H a l s a r e l ' s
m e
bistineF eporators ) {Fi
ne efperards; K 2 3
= -N=)
Temp ali
ail ali+1];:
afi+1]=temp; legti N) =
N,tNa=lct
17
pLabulayln)= n,#n2 = 8t4=12
N=10
We first find out the operands and operators from above function along with their occurrences.
Operands Occurrences Operators Occurrences
swap
5
void
temp
int 3
6. 4
3
2
N-21
Na
Caledali HaltEmdnpluma lo
w
# GCD lopuldio
n geel (,1)
n2=9
N 16
n=5
N=Ni+N:
=
16+21 =37
rtile(= t)
N=37
n =nitn2
=
5 +9 =
14
d
-T-
n= 14
Estimated length =
n1 log ni + n2 log n2
=
5 iog 5 +9 log 93 . 1 1
= 5*2.32 +9*2.19 =31.37
GrpeTands eumemeas oralnd |aelunen
Estimated length =
31.37
whde
VolumeN * log n
Y
M
37 *
log (14) d de
381
elu
37*2.63=97.64
3
Volume (V) =
97.64
3
33
13 2
n
n,+) 3t13 - I6 2
NI =
14.Na 20
Estima longt =
, t73
N=
N+ N,= l4+20 = 3
Rume z
34x 6)
34x 136
3 3+ 13up13
3(1.58S)+ 13(3-))
=S2
7. t le uaattalne
Opelemalt lopleyi
MeaswR t t mumos "k uneavy imdelouda
Pacte e Cole. 'maidy u t e y a l u a t e
Compay oa p
ase ase mt ho Coployy
Cn be lomleitad tngly f+low
V(G)=e -n+2f He 'oth m
t mo. des, and p
T R
na,
6 Cewwnaitd Comaemanb.
4) Hene
Po e mo. TdCa
o d e ,
(11 v(4)= No. agions
&. Copul yelemue Cerkae us floin
CL=
e -
nt2
= 8
1 0
CoReee e
VG)=lo - 8+2
umda
2+2
4
e l c e
(vC) 7.
1 V(G Monr aA
me lemfpla
(
8. E a - l P
i0
wtlCicn-1)d
i+1:
wil(i4 n) do
Ai) 4A(1)
Surp (ACi) AU
i+1
e d.
Compute eyelsnaiu abeue lnsrapy
CLat v¢) o abe 9s.
9. U N C T I O N POINT
ystv la. mlboms, ap2,
wobuts
olusaluen
m a m u m m
ond
m u n m u n ,
MLbucs a ptouclsup
khimolio
u a n s l i t
Th peg.2el. soblesn and
d l e r e l a f l A h b r B c l u c l
MloLLLALL
o u t a n d p o p u l e r 4
l u e r i m l l y
b l u n g u L L d
pund
)Euncluafa peuul
lo2einaleBge
otes_LoC)
Ladis
a v a i l a k L _
t e L l h m a L L
Thu
m i l u c
L a & L L k e R
The
TLpuettc_by
c e u M l u s
A
M M A N A =
SeLLAcLImLLlucluennlUn Ahe
a l l
/ m e l u c i s
d u a l o k n c d h e a s u a n
W h u l l C
c o i n L u s n g
hl Ma
imsluuciera, luaps_nedat_communluny
th
cOd AMd
hindur/_lnsaKLA9mg/u
Aoc hastkellewas)sherlcennin8
OC
Loc
a l u m l e u c a l
ualue (e
oc
Jeblom
e h a t saM May
wrdily
May wdaly
dlfaluesmt
ithindudkcal
codin STyle.0
dfaUnen
preisammusay wiÍAeAcOtelI.n
dhfewnl wayllsFA Lg Om seavW
paLeawm
10. Reutal Bowmce mklnuub
MnRAwhuak amathpp
Lng M3uln
a-
LAMg{
acluos8
oC Aunlal kles
aclun mLas _ol h codn
900d alsnl Om Th/ Dthn honmd,
O 900d bupblum
BheullK
e
DAUL COMMaleu Akplal llplmincdhd
LA MUal L
LLL9M CAde lhtll,Elc_am
LoC hewluue ocuL
Lh
LAdng0clwly alrn
CAAmLpAulus
MUoky
hs
imalpiugMa_n
ce lais_haoly lh
Ahe aualils_amd liotmcys//EhL
MIsauily( wnply kati auabtu
highi ndy
u lamalunes
kurel Aannjual
hughi
L E N L L y _
heha th_doc coundwll
Thsuweudd AhuA8a
L m a l l p r R a M M A
asglo2us8AuL_hr doCceu as
measulee
h lal pul un
dllueml/deselghalus,_thy weula.
a
C o d e l u s e b l d u r l e
b dis Vceunagm
Page2-
11. wUuy dllucull nal o p
Alumali Jod/U Che
accutal p.
Che buob lemn
A0Ccoul ca
specAlca)
OMA
Cempuld 0nly
bcemJullyfdevn Le
mama9.eLS
dusun hsotr.cl la
amy hvelol, 4
e l CUMU-be/øm
aclurty
h a l s L l a s i l j d
6199.c8L
th ZoC 0nelile
h o t l c o r
em he
M A m a e b e n s p i C l u V
peml melbuic
Mluc
houlceminIS
umcEM.
Funche boiint
maMy
m.gliuc LSuncids
late 1970 'S uNcZien
nta Aehulalpiy
ueposkd_by ALbuchM
h
isnportamt aduamlojA3 Lt
mcluen peun AMTLUc/ Au
lhalt CaM
LLnatl hiiac walp
LeducZ
LLclLcalue
diuctly am he Vpuebi
ncpiuo Lcaobihna
ABCLCiy
Page3 6
12. A
dapundemt
Lu JumcluoLS gt
h
Asetwant oduct Supporlin
lanfe
.
aluslksLwolLd
S Lhama bsoclucl
Lialuste
ia ads some
lasle
Cdaumly
tvnlh Qess no
whna
Lach
dala amd Uan
Siommsd LO he coHespondm? _eutpul
mclon
dala
PumdernemtMetuc
parammmlesus
No f
Ne
uspil/s
Na Na
nalliius ales
No:1-
ntnlaces
FP
UFP * TCF
Umoduslaol
EumclueM
Pomls
Lechancal
Compleaiy
Facle
TCF 0 65 0:01 X DL
degLe
imlluhace
Dbndent M14paranmelsuswtuch
A8gmid walue
13. Lathocie )No S49milnul
Imodlnla
Moduroti
OL N psLl No nm
5LStMgInlluim
4 Na Abuls
ach data lum mpul by
2 No lpu
Lach_Ldala lem
eilput by hs p
SNo LAAQLLIHILL
No lduimcd intiuaclue quLrLLs hch
caM
4No
A Lhal (l Aapluus a ueup AoLucally
uldltid
5-lo
h JAtindad MAIl lenchaWge
L malueA h Ahn &yilnns.
MAdL
Udolakogucal llsuinclucll(Aala such
phypical ils
Fals Snapl Aa2Cemslo
6
NoInpuI 3
5
Outpub 1
3 6
10 15
Fl13
5
Wgnt Chart
14. D I
No awpuls
Dulpuls
S2
11
Lalomal
(unlreacrs
91
Atuat
Sinple =21 7
Cowola aFumeiow PoiT value a
d e m a i n h r a s l e n u c o
NCo - UCe inau : 3 2
No u bab= to
Lo ue 'imqiYi=24
NO laa ales tales = 2
e nal
Assma
Wat Compleriq asaton
aln Page6
Me
15. FP UEPx TCf then. FP
funelion loint UFP v ugte
a a uasjuttod fanaaon pbintE
amTfCbat+eebnicalCapisqG
ata a Di io do
inl e n r
h c e banameark a Copatad a
EP4x 37+hox54xto424Y+Yrz
UFP= 4*32 + o*5+2-4 * + 8* 1ot 7*2
TeF= o.65+O:DI *DI
DT= 4*3= y2
618 1 o)
= 661.2
n O S - T T . C
16. References
1. Roger S. Pressman, Software Engineering a Practitioner Approach, 3rd
Edition, TMH, 2005.
2. Rajib Mall, Fundamantal of Software Engineering, 3rd
Edition,PHI Publication, 2007.
3. Deepak Jain, Software Engineering for Practitioners, Ist
Edition, Oxford, 2012.
4. K K Agarwal and Yogesh Singh, Software Engineering, 3rd
Edition,Oxford, 2012.
********************
16