ArticleslgStudy

computer science

Halstead complexity measures

Halstead complexity measures is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Halstead complexity measures rather than just read about it. In short: 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.

Key takeaways

  • Halstead complexity measures belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Halstead complexity measures to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Halstead complexity measures from memory before moving on to harder problems.

Reference excerpt

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 goal was to identify measurable properties of software, and the relations between them. This is similar to the identification of measurable properties of matter (like the volume, mass, and pressure of a gas) and the relationships between them (analogous to the gas equation). Thus his metrics are actually not just complexity metrics.

Calculation For a given problem, let:

η 1 {\displaystyle \,\eta _{1}} = the number of distinct operators

η 2 {\displaystyle \,\eta _{2}} = the number of distinct operands

N 1 {\displaystyle \,N_{1}} = the total number of operators

N 2 {\displaystyle \,N_{2}} = the total number of operands From these numbers, several measures can be calculated:

Program vocabulary: η = η 1 + η 2 {\displaystyle \eta =\eta _{1}+\eta _{2}\,}

Program length: N = N 1 + N 2 {\displaystyle N=N_{1}+N_{2}\,}

Calculated estimated program length: N ^ = η 1 log 2 ⁡ η 1 + η 2 log 2 ⁡ η 2 {\displaystyle {\hat {N}}=\eta _{1}\log _{2}\eta _{1}+\eta _{2}\log _{2}\eta _{2}}

Volume: V = N × log 2 ⁡ η {\displaystyle V=N\times \log _{2}\eta }

Difficulty : D = η 1 2 × N 2 η 2 {\displaystyle D={\eta _{1} \over 2}\times {N_{2} \over \eta _{2}}}

Effort: E = D × V {\displaystyle E=D\times V}

The difficulty measure is related to the difficulty of the program to write or understand, e.g. when doing code review. The effort measure translates into actual coding time using the following relation,

Time required to program: T = E 18 {\displaystyle T={E \over 18}} seconds Halstead's delivered bugs (B) is an estimate for the number of errors in the implementation.

Number of delivered bugs : B = E 2 3 3000 {\displaystyle B={E^{2 \over 3} \over 3000}} or, more recently, B = V 3000 {\displaystyle B={V \over 3000}} is accepted.

Example Consider the following C program:

The distinct operators ( η 1 {\displaystyle \,\eta _{1}} ) are: main, (), {}, int, scanf, &, =, +, /, printf, ,, ; The distinct operands ( η 2 {\displaystyle \,\eta _{2}} ) are: a, b, c, avg, "%d %d %d", 3, "avg = %d"

η 1 = 12 {\displaystyle \eta _{1}=12} , η 2 = 7 {\displaystyle \eta _{2}=7} , η = 19 {\displaystyle \eta =19}

N 1 = 27 {\displaystyle N_{1}=27} , N 2 = 15 {\displaystyle N_{2}=15} , N = 42 {\displaystyle N=42}

Calculated Estimated Program Length: N ^ = 12 × l o g 2 12 + 7 × l o g 2 7 = 62.67 {\displaystyle {\hat {N}}=12\times log_{2}12+7\times log_{2}7=62.67}

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Halstead complexity measures

Start with the simplest possible case. Write down what Halstead complexity measures claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Halstead complexity measures before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Halstead complexity measures ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Halstead complexity measures

In research
Halstead complexity measures appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Halstead complexity measures in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Halstead complexity measures is common in secondary-school and first-year university syllabi. It links to neighbouring topics Software metrics, so understanding it makes those chapters shorter.
In everyday life
Look for Halstead complexity measures outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Halstead complexity measures in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Halstead complexity measures means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Halstead complexity measures out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Halstead complexity measures in simple terms?

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 algorit…

Why does Halstead complexity measures matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Halstead complexity measures?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Halstead complexity measures.

Tags

  • Software metrics

Keep exploring