Skip to content
IGCSE·Tuition

Computer Science · Practice

Algorithm design: mixed practice with explanations

Practice is where design skills either settle in or show their gaps, and a worked answer shows you which.

These eleven questions cover decomposition, specifications, trace tables, selection with boundary cases and explaining algorithms. Work on paper, write your own trace tables, and open each answer only after you have a result. All code uses Cambridge-style pseudocode.

The module overview is algorithm design. Log wrong answers in the mistake log and use the pseudocode trace trainer to check traces.

Questions

Q1 (easy). A shop program reads the prices of three items and outputs the total after a 10% discount if the total is over RM50, otherwise the total unchanged. List the subproblems in order.

Show answer
  1. Input the three prices. 2. Add them to get Total. 3. If Total > 50, reduce it by 10%. 4. Output the final amount. Example: 20, 25, 10 gives Total 55, discount 5.5, output 49.5.

Q2 (easy). Write the inputs, outputs and constraints for converting a whole number of minutes into hours and minutes. Give the output for 135.

Show answer

Input: Minutes, whole number, 0 or more. Outputs: Hours and Mins, where Mins is from 0 to 59. Hours ← Minutes DIV 60 and Mins ← Minutes MOD 60. For 135: 60 × 2 = 120, so Hours = 2 and Mins = 15. Check: 2 × 60 + 15 = 135.

Q3 (easy). 95 sweets are packed into bags of 8. How many full bags and how many sweets are left?

Show answer

8 × 11 = 88, so 95 DIV 8 = 11. 95 − 88 = 7, so 95 MOD 8 = 7. Check: 11 × 8 + 7 = 95.

Q4 (medium). Trace this and give the output.

A ← 2
B ← 1
FOR I ← 1 TO 4
   B ← B * A
   A ← A + 1
NEXT I
OUTPUT B
Show answer
IBA
start12
123
264
3245
41206

Output 120. Check: 2 × 3 × 4 × 5 = 120.

Q5 (medium). Trace this and give the output.

N ← 27
Steps ← 0
WHILE N > 10 DO
   N ← N - 6
   Steps ← Steps + 1
ENDWHILE
OUTPUT N, Steps
Show answer

27 > 10: N = 21, Steps = 1. 21 > 10: N = 15, Steps = 2. 15 > 10: N = 9, Steps = 3. 9 > 10 is false. Output 9, 3.

Q6 (medium). A discount of 15% applies to orders of RM200 or more. Choose boundary test values (in ringgit and sen) and say what should happen.

Show answer

Test 199.99 (no discount), 200.00 (discount, because the rule says 200 or more) and 200.01 (discount). The key test is 200.00, which separates >= from >.

Q7 (medium). The rule is “pass if the mark is 40 or more”, but the code is IF Mark > 40 THEN. Which test finds the fault, and what is the fix?

Show answer

Test Mark = 40. The rule expects a pass, but 40 > 40 is false, so the code gives a fail. Fix: IF Mark >= 40 THEN.

Q8 (medium). Write pseudocode for a cinema price: under 5 free, 5 to 17 RM8, 18 and over RM15. Give the output for ages 4, 5, 17 and 18.

Show answer
INPUT Age
IF Age < 5 THEN
   Price ← 0
ELSE
   IF Age < 18 THEN
      Price ← 8
   ELSE
      Price ← 15
   ENDIF
ENDIF
OUTPUT Price

Outputs: 4 gives 0, 5 gives 8, 17 gives 8, 18 gives 15.

Q9 (harder). Rewrite this language-specific description as plain steps: “use a for loop with range(1, 6) and the sum function”.

Show answer

Set Total to 0. For each whole number from 1 to 5, add it to Total. Output Total. The result is 1 + 2 + 3 + 4 + 5 = 15.

Q10 (harder). Trace the smallest-value algorithm from the lesson on the data 8, 3, 5, 3. Why does it start with the first number?

Show answer

Smallest = 8. Next 3 < 8, so Smallest = 3. Then 5 < 3 is false. Then 3 < 3 is false. Output 3. It starts from the first real value, because a fixed start such as 0 could be smaller than every input.

Q11 (harder). Design an algorithm that reads four temperatures and outputs how many are above 30. State the constraints, write the pseudocode and trace 28, 31, 30, 35.

Show answer

Constraints: four temperatures entered as numbers; the output is a whole number from 0 to 4.

Count ← 0
FOR I ← 1 TO 4
   INPUT Temp
   IF Temp > 30 THEN
      Count ← Count + 1
   ENDIF
NEXT I
OUTPUT Count

Trace: 28 no, 31 yes (Count 1), 30 no (not above 30), 35 yes (Count 2). Output 2.

If you got these wrong

What went wrongGo to
Subproblems too vague or in the wrong order (Q1, Q9)Decompose a task
Missed DIV or MOD, or no constraints (Q2, Q3)Inputs, outputs and constraints
Trace rows missing or variables out of step (Q4, Q5, Q10)Trace a sequence
Wrong symbol at the edge, or untested boundary (Q6, Q7, Q8)Selection with boundary cases
Explanation tied to a language, or wrong starting value (Q9, Q10, Q11)Explain an algorithm

Several slips at once can mean a gap that is easier to fix with someone watching your working. Our online one-to-one Computer Science tuition is built around that kind of tracing and debugging, and the safe Python sandbox lets you check Q11 against a short program.

Questions people ask

How should I use this practice set?

Work on paper. Predict the answer, build any trace table, then open the worked answer and compare the working, not only the final line. Note which lesson each mistake belongs to and retry a similar question later.

Are these exam questions?

No. They are original questions written to practise the same skills. Use the Cambridge syllabus page and your teacher's materials to check the style and notation expected for your exam year.

What if I get most of them wrong?

Go back to the lesson named in the routing section, redo its worked example without looking, then retry the question. Use the mistake log to track patterns. Repeating the same error is useful information.

Updated:

Your next step

If the same kind of question keeps going wrong after you have read the working, a one-to-one teacher can look at your attempts and find the habit behind them.

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.

9,000+ students helped through our service