KTU S1

Means-Ends Analysis

By the end you should be able to: Apply means-ends analysis to break a problem into sub-goals by repeatedly reducing the difference between the current state and the goal state, and explain why it suits problems with a clearly defined target.

Means-ends analysis is a strategy built on one repeated question:

What is the difference between where I am now and where I want to be — and what action reduces that difference?

You apply it over and over. Each action shrinks the gap. When the gap reaches zero, you're done.

The three ingredients

Every means-ends problem needs:

IngredientMeaning
Current stateWhere things are right now
Goal stateWhere you need them to be
OperatorsThe legal actions available to change the state

If you can't state all three clearly, you can't apply the strategy — and that's often the real difficulty. Writing them down is most of the work.

The procedure

  1. Describe the current state and the goal state.
  2. Identify the biggest difference between them.
  3. Find an operator that reduces that difference.
  4. If the operator can't be applied yet, make its precondition a new sub-goal and solve that first.
  5. Apply the operator. Repeat from step 2.

Step 4 is the one students skip, and it's where the power lies. When an action isn't yet available, you don't abandon it — you set up a smaller problem whose solution makes it available. This is what produces the nested, recursive feel of means-ends analysis.

Why it matters for programming

This is how a large program actually gets written. You don't type it start to finish. You state where the data is, state where it needs to be, and repeatedly ask which transformation closes the gap. Each answer becomes a function.

It's also the strategy behind the Tower of Hanoi, which appears in the KTU classroom exercises for this module.

The characteristic weakness

Means-ends analysis is greedy about differences: it attacks the biggest gap first. Sometimes closing the biggest gap makes a smaller one impossible to close later, and you get stuck.

Tower of Hanoi shows this — occasionally you must move a disc away from its final position to make progress. A student who only ever reduces the visible difference will get stuck there.