Skip to content
SPM Tuition
Problem solving and algorithms practice

Problem solving and algorithms practice

You have read the lessons and want new questions that test each skill separately.

These seven questions cover problem solving and algorithms in the order of the lessons. Attempt each on paper before opening the answer.

For exam pace, use the timed original practice session builder.

Questions

Question 1. A program should read the marks of four students and display the highest. List the tasks in terms of input, process and output.

Answer

In: four marks. Process: compare the marks and keep the largest seen so far. Out: the highest mark. A fuller split would also list “start with the first mark as the current highest” as its own task.

Question 2. Trace this and give the final values of a and b.

SET a = 2
SET b = 10
WHILE a < b
  SET b = b - 1
  SET a = a + 2
END WHILE
OUTPUT a, b
Answer

Start: a = 2, b = 10. Pass 1: b = 9, a = 4 (4 < 9 true). Pass 2: b = 8, a = 6 (6 < 8 true).

Pass 3: b = 7, a = 8 (8 < 7 false). The output is 8 and 7.

Question 3. A flowchart reads n and asks n MOD 2 = 0?. The Yes exit outputs “Even” and the No exit outputs “Odd”.

What is the output for n = 17, and for n = 0?

Answer

For 17, 17 MOD 2 = 1, so the answer is No and the output is Odd. For 0, 0 MOD 2 = 0, so the output is Even. Zero is an even number, which makes it a useful test input.

Question 4. Name the flowchart symbol for each step.

  • (a) Start
  • (b) INPUT price
  • (c) SET total = total + price
  • (d) total > 100?
Answer

(a) Oval. (b) Parallelogram. (c) Rectangle. (d) Diamond, with two labelled exits, Yes and No.

Question 5. A cinema booking allows 1 to 6 tickets per order. Choose six test inputs and label them normal, boundary or invalid.

Answer

Normal: 3. Boundary: 1 and 6 accepted, with 0 and 7 just outside and rejected. Invalid: “two” or 2.5, rejected. That gives seven inputs, which covers every category.

Question 6. What does this output?

SET sum = 0
FOR i = 1 TO 7
  IF i MOD 2 = 1 THEN
    SET sum = sum + i
  END IF
NEXT i
OUTPUT sum
Answer

The condition is true for the odd values of i: 1, 3, 5 and 7. The sum grows as 1, 4, 9 and 16. The output is 16.

Question 7. A shop gives a 10% discount when the bill is RM100 or more. The code says IF total > 100 THEN. Which input exposes the fault, and what should the output be?

Answer

The input RM100 exposes it. The rule says RM100 qualifies, so the amount to pay should be 100 − 10 = RM90. The code tests 100 > 100, which is false, so it charges RM100. Change > to >=.

If you got these wrong

Log the slips with the mistake log and paper-error review. For teacher support, see online one-to-one Computer Science tuition.

Common questions

In what order should I attempt the questions?

Go in order. The questions ramp from splitting a problem to tracing and then testing. If you get stuck, the list at the end points to the lesson that teaches the skill.

Should I write my trace tables on paper?

Yes. Drawing the table by hand is exactly what you will do in an exam, and it builds the habit of writing every row instead of skipping ahead.

Are these questions from past papers?

No. They are original questions written for this site, with every number checked by hand, and they do not reproduce any examination paper.

If the trace or flowchart questions took longer than you expected, a one-to-one Computer Science teacher can practise those two skills with you at your own pace.

  • 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.