Skip to content
IGCSE·Tuition
Computer Science · Lessons

Decompose a task into subproblems

A long question can look like one giant job until you see that it is really four small ones in a row.

On this page
  1. How do you split a task into parts?
  2. Worked example
  3. The mistake to watch for
  4. Check yourself
  5. Where this leads next

To decompose a task, list the separate jobs it contains, give each one a single clear purpose, then put them in an order where each job has what it needs. Questions that begin “Design an algorithm that…” reward this habit before any pseudocode appears.

It is the first step of algorithm design, and the next lesson, defining inputs, outputs and constraints, makes each part precise.

How do you split a task into parts?

Read the task and underline every verb: collect, add, compare, output. Each verb usually points to a subproblem. Then ask three questions of each part.

  • What does it need before it can start?
  • What does it hand to the next part?
  • Can I test it on its own?

If you cannot answer the third question, the part is too big or too vague.

Worked example

A teacher enters five quiz marks, each out of 20. The program must output PASS if the average mark is at least 10, otherwise FAIL.

Step 1, underline the jobs: collect five marks, add them up, find the average, compare with 10, output a word.

Step 2, name each subproblem with its input and output:

SubproblemNeedsProduces
Collect and add the marksfive marksTotal
Find the averageTotalAverage
Decide pass or failAveragethe word PASS or FAIL
Outputthe wordtext on screen

Step 3, order them. Each row needs the one above it, so the order is fixed.

Step 4, write each part as pseudocode:

Total ← 0
FOR Count ← 1 TO 5
   INPUT Mark
   Total ← Total + Mark
NEXT Count
Average ← Total / 5
IF Average >= 10 THEN
   OUTPUT "PASS"
ELSE
   OUTPUT "FAIL"
ENDIF

Step 5, test with the marks 12, 15, 9, 18, 16. Total after each mark: 12, 27, 36, 54, 70. Average = 70 / 5 = 14. Since 14 >= 10, the output is PASS. Adding the marks again by hand gives 70, which agrees.

The mistake to watch for

A common slip is a subproblem that simply restates the task.

Mistaken plan: 1. Get the marks. 2. Work out the result. 3. Output it.

“Work out the result” hides the total, the average and the comparison, so there is nothing you can test.

The correction is to keep splitting until each line has a clear input and output, as in the table above. A second slip is putting Total ← 0 inside the loop. Then the total restarts at every mark and the final average uses only the last mark.

Check yourself

1. A library program must read a book’s days overdue and output the fine at RM0.20 per day. List the subproblems.

Show answer

Read the days overdue. Multiply by 0.20 to get the fine. Output the fine. For 15 days the fine is 15 × 0.20 = RM3.00.

2. The plan below is out of order. Put it right: output the average, add the numbers, divide the total by the count, input the numbers.

Show answer

Input the numbers, add the numbers, divide the total by the count, output the average. Each step needs the result of the one before it.

3. In the quiz example, what would the average be if Total ← 0 were inside the loop and the marks were 12, 15, 9, 18, 16?

Show answer

The total is reset at every mark, so after the last mark Total = 16. The average is 16 / 5 = 3.2, which wrongly gives FAIL.

Where this leads next

Next, learn to define inputs, outputs and constraints for each part. The pseudocode trace trainer lets you step through algorithms like this one.

If breaking a task down is the point where you stall, our teachers can work on that with you in online one-to-one Computer Science tuition, and the practice set gives you more tasks to split.

Questions people ask

What does decomposition mean in Computer Science?

Decomposition means breaking a larger problem into smaller parts that are easier to understand, solve and test. Each part has one clear job. When all the parts are solved and joined in the right order, the whole problem is solved.

How small should a subproblem be?

Small enough that you can state its input and output in one line and write or trace it without further splitting. If a part still contains words like and, then or also, it probably holds more than one job.

Is decomposition the same as writing the steps in order?

They are related but not identical. Decomposition first identifies the separate jobs. Ordering them comes next, and it matters because the output of one part is often the input of another.

Updated:

Your next step

If a design question still feels like too much to start, a one-to-one teacher can sit with your first attempt and help you find where the task naturally splits.

Paid one-hour trial at your assigned teacher’s confirmed rate, starting from RM80. Other fees, schedules and ongoing arrangements are confirmed directly with your teacher after the trial class.

Tuition is arranged with a parent or guardian. Send them this page on WhatsApp and they can enquire for you.

Parent or guardian? Enquire here

9,000+ students helped through our service