Skip to content
SPM Tuition
Computer Science · Problem solving and algorithms

Breaking a problem into smaller tasks

The question is a full paragraph of requirements and you do not know where to begin.

Decomposition means splitting a problem into smaller tasks, each simple enough to solve on its own. Do this before you write a single line of pseudocode.

This lesson opens problem solving and algorithms. The next lesson, tracing pseudocode step by step, shows how to check what your steps really do.

How do you start on a long problem?

Ask three questions in order.

  1. What must go in? List every piece of data the program needs.
  2. What must happen to it? List each calculation or decision as its own task.
  3. What must come out? State exactly what the user sees.

Only after these three lists exist should you think about loops or IF statements.

Worked example: a canteen bill

A school canteen wants a program. The user enters the price of three items. If the total is RM20 or more, a 10% discount is applied. The program shows the total, the discount and the amount to pay.

Question Answer from the problem
In Three item prices
Process Add the three prices; check whether total is at least RM20; calculate 10% discount if so; subtract it
Out Total, discount, amount to pay

The process row splits into four small tasks: add, test the condition, calculate the discount, subtract. Each one fits in one or two lines.

Does it work on real numbers?

Test the split with prices RM8.50, RM7.00 and RM6.50. The total is 8.50 + 7.00 + 6.50 = RM22.00. Since 22.00 is at least 20, the discount is 10% of 22.00 = RM2.20, and the amount to pay is 22.00 − 2.20 = RM19.80.

Every number above came from one of the small tasks. Without the condition test, a RM15.00 bill would wrongly get a discount too.

The mistake to avoid

The common mistake is to treat the whole paragraph as one block and start writing code immediately. The student then forgets a requirement, such as the condition or the last output.

Habit Result
Write code from the first sentence Discount applied to every bill
List tasks first, then tick each against the paragraph Every requirement covered

A quick check is to tick off each noun and verb in the problem statement against your task list. Anything unticked is a missing task.

Check yourself

A teacher wants a program that reads the number of days a student was present and the total school days, then shows the attendance percentage. If it is below 80%, it also prints a warning. List the tasks.

Answer

In: days present and total school days. Process: divide days present by total days and multiply by 100; test whether the result is below 80. Out: the percentage, and the warning when the test is true.

For 36 days present out of 50, the percentage is 36 ÷ 50 × 100 = 72, which is below 80, so the warning prints.

What to study next

Next, put tasks in order and check them using tracing pseudocode step by step, then turn them into a diagram with designing a flowchart. Test yourself with the section practice set.

If you want a teacher to work through paragraph-style problems with you, see online one-to-one Computer Science tuition.

Common questions

What does decomposition mean in Computer Science?

It means breaking a large problem into smaller tasks that are each easy to solve. You solve the small parts, then join them in the correct order. The skill is used before writing pseudocode or drawing a flowchart.

How small should each task be?

Small enough that you can describe it in one short sentence and imagine one or two lines of pseudocode for it. If a task still contains the word 'and', it probably hides two tasks.

Is this the same as writing the algorithm?

No. Decomposition comes first and only lists what must happen. The algorithm puts those tasks in order, adds decisions and loops, and shows the exact steps.

Can two different students split the same problem differently?

Yes. There is more than one sensible split. What matters is that every task is clear, nothing in the problem is left out, and the tasks join up in a workable order.

If long problem statements freeze you before the first line, a one-to-one Computer Science teacher can practise the splitting step on your own questions until it becomes routine.

  • Online one-to-one lessons for your child with an experienced teacher.
  • Your first class is a one-hour trial, from RM50. The fee is agreed before you book.
  • Happy with the teacher? Continue with lessons of about 1.5 hours. If not, ask for another teacher.