Why decomposition helps: easier to understand and solve

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Why decomposition helps: easier to understand and solve

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Why does decomposition make a hard problem easier?
A It makes the problem disappear so no code is needed
B It splits the problem into small sub-problems that are easier to understand
2. A student must write a program for a whole school timetable and feels overwhelmed. What should they do first?
A Break it into small sub-problems, such as rooms, teachers and classes
B Write all the code at once and hope it works
3. Which statement about a sub-problem is true?
A It is easier to understand and solve than the whole problem
B It is always harder to solve than the whole problem
4. A program with 500 lines gives the wrong answer. When it is split into 5 sub-problems, where is the mistake easier to find?
A Somewhere in all 500 lines, so every line must be checked
B In the one small sub-problem that gives the wrong result
5. Which approach follows 'solve one small part at a time'?
A Solve and test the sub-problem for the score, then move on to the next
B Try to solve every part of the problem at the same moment

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1sub-problem ABreaking a big problem into smaller sub-problems so that it becomes manageable
2decomposition BPROCEDURE CalculateAverage() Average ← Total / Count ENDPROCEDURE
3Solve one small part at a time instead of the whole problem at once CA small part of a bigger problem that is easier to understand and solve than the whole problem
4A mistake is easier to find because you only need to check one small sub-problem DCALL EnterScores() CALL CalculateAverage() CALL ShowResult()
5Write the whole 500-line program in one go and then test it EThis tries to solve the whole problem at once, which feels overwhelming and makes it hard to understand. It should be split into sub-problems and each part solved in turn.
6The program gives the wrong answer, so check every line of the whole program FWith one big block of code the error could be anywhere. With sub-problems you check each small part and find the faulty one quickly.

Definitions

sub-problem

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
____ GetMarks() CALL AddMarks() CALL ShowResult()
2.
PROCEDURE ShowResult() OUTPUT Total ____________
3.
FUNCTION AddMarks() _______ INTEGER RETURN Maths + English ENDFUNCTION
4.
_________ GetMarks() INPUT Maths ENDPROCEDURE
5.
CALL GetMarks() ______ Maths CALL AddMarks()

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A IF Mark >= 50 THEN
B OUTPUT "Pass"
C ELSE:
D OUTPUT "Fail"
E ENDIF
Question 2
A PROCEDURE GetMarks()
B INPUT Mark
C ENDFUNCTION
Question 3
A FUNCTION Avg() RETURN REAL
B RETURN Total / 3
C ENDFUNCTION
Question 4
A FOR Count ← 1 TO 3
B INPUT Mark
C Total ← Total + Mark
D ENDFOR
Question 5
A INPUT Mark
B Bonus = Mark DIV 10
C OUTPUT Bonus

Answer Key

Why decomposition helps: easier to understand and solve
Section A: Quick Questions
Q1
B — It splits the problem into small sub-problems that are easier to understand
Q2
A — Break it into small sub-problems, such as rooms, teachers and classes
Q3
A — It is easier to understand and solve than the whole problem
Q4
B — In the one small sub-problem that gives the wrong result
Q5
A — Solve and test the sub-problem for the score, then move on to the next
Section B: Match the Pairs
Q1
sub-problem → A small part of a bigger problem that is easier to understand and solve than the whole problem
Q2
decomposition → Breaking a big problem into smaller sub-problems so that it becomes manageable
Q3
Solve one small part at a time instead of the whole problem at once → CALL EnterScores() CALL CalculateAverage() CALL ShowResult()
Q4
A mistake is easier to find because you only need to check one small sub-problem → PROCEDURE CalculateAverage() Average ← Total / Count ENDPROCEDURE
Q5
Write the whole 500-line program in one go and then test it → This tries to solve the whole problem at once, which feels overwhelming and makes it hard to understand. It should be split into sub-problems and each part solved in turn.
Q6
The program gives the wrong answer, so check every line of the whole program → With one big block of code the error could be anywhere. With sub-problems you check each small part and find the faulty one quickly.
Section C: Definitions
Q1
sub-problem — A small part of a bigger problem. It is easier to understand and solve than the whole, so splitting a problem up makes it manageable and makes mistakes easier to find.
Section D: Fill in the Blanks
Q1
CALL GetMarks() CALL AddMarks() CALL ShowResult()
Q2
PROCEDURE ShowResult() OUTPUT Total ENDPROCEDURE
Q3
FUNCTION AddMarks() RETURNS INTEGER RETURN Maths + English ENDFUNCTION
Q4
PROCEDURE GetMarks() INPUT Maths ENDPROCEDURE
Q5
CALL GetMarks() OUTPUT Maths CALL AddMarks()
Section E: Spot the Error
Q1
C — In Cambridge pseudocode ELSE has no colon after it. The line should be just ELSE. Checking one small decision like this is easier than checking a whole program.
Q2
C — A PROCEDURE must be closed with ENDPROCEDURE, not ENDFUNCTION. Each small sub-problem is a short block, so a mismatch like this is easy to spot.
Q3
A — The function header needs the keyword RETURNS (with an S) before the data type. It should be FUNCTION Avg() RETURNS REAL.
Q4
D — A FOR loop in Cambridge pseudocode ends with NEXT and the counter name, so the line should be NEXT Count. ENDFOR is not a pseudocode keyword.
Q5
B — Assignment uses the arrow ←, not =. The = sign is used to compare values. The line should be Bonus ← Mark DIV 10.