Level:
Correct: 0
Incorrect: 0
Marks: 0/0
Exam Practice
Subject:
Topics:
Avg
score:
–
Topics
done:
0/32

Explaining the purpose of an algorithm

Practise 32 exam-style questions on Explaining the purpose of an algorithm for Cambridge IGCSE Computer Science (Paper 2). Write your answer as you would in the exam and get it marked in seconds against the mark scheme, point by point, with an AI tutor on hand if you get stuck.

  • 32 questions
  • 1–6 marks each
  • Instant marking
  • No sign-up needed
20 questions, marked as you go

Sample questions with model answers

Here are 4 of the questions in this topic, each with a model answer, an explanation of why it earns the marks and the mark scheme an examiner would use.

Question 1

1 mark

Look at this pseudocode:

INPUT Number
IF MOD(Number, 2) = 0
  THEN
    OUTPUT "Even"
  ELSE
    OUTPUT "Odd"
ENDIF

State the purpose of this algorithm.

Model answer

It outputs whether the number input is even or odd.

Explanation

MOD(Number, 2) gives the remainder after dividing by 2: 0 for an even number and 1 for an odd one. Recognising common uses of MOD helps you spot an algorithm's purpose quickly.

Mark scheme
  1. 1 mark

    To decide / output whether the number input is even or odd

Question 2

2 marks

The flowchart shows a simple algorithm about years.

State the purpose of this algorithm.

Flowchart, read from the top. START, then the input/output box "INPUT Year", then the decision box "MOD(Year, 4) = 0?" (if Yes, the input/output box 'OUTPUT "Leap year"'; if No, the input/output box 'OUTPUT "Not a leap year"'; the two paths then join). After the paths join: STOP.

Model answer

It checks whether the year that is input divides exactly by 4, and outputs whether or not it is a leap year.

Explanation

MOD(Year, 4) = 0 is true when there is no remainder after dividing by 4. This is a simplified leap year rule; the outputs tell you what the decision is used for.

Mark scheme
  1. 1 mark

    Checks whether the year input is exactly divisible by 4

    Accept 'checks the remainder when the year is divided by 4 is 0'

  2. 1 mark

    Outputs whether or not the year is a leap year

Question 3

3 marks

Look at this procedure:

PROCEDURE TimesTable(Number : INTEGER, Rows : INTEGER)
    FOR Count ← 1 TO Rows
        OUTPUT Count, " x ", Number, " = ", Count * Number
    NEXT Count
ENDPROCEDURE

State the purpose of the procedure and give the last line output by CALL TimesTable(7, 12).

Model answer

The procedure outputs the times table for the number given by its first parameter, with as many lines as its second parameter. The last line output by CALL TimesTable(7, 12) is: 12 x 7 = 84

Explanation

Parameters let one procedure do the same job with different values: TimesTable(7, 12) gives the 7 times table up to 12 x 7, while TimesTable(3, 5) would give the 3 times table up to 5 x 3.

Mark scheme
  1. 1 mark

    Outputs the times table for the number passed as the first parameter (Number)

  2. 1 mark

    The number of lines output is set by the second parameter (Rows)

  3. 1 mark

    Last line: 12 x 7 = 84

    Accept 12 × 7 = 84

Question 4

5 marks

The array Rain[1:12] has been declared to store the rainfall, in mm, for each month of a year. Look at this pseudocode:

Total ← 0
Wettest ← 1
FOR Month ← 1 TO 12
    INPUT Rain[Month]
    WHILE Rain[Month] < 0 OR Rain[Month] > 500 DO
        OUTPUT "Invalid - enter a value from 0 to 500"
        INPUT Rain[Month]
    ENDWHILE
    Total ← Total + Rain[Month]
    IF Rain[Month] > Rain[Wettest]
      THEN
        Wettest ← Month
    ENDIF
NEXT Month
OUTPUT "Total: ", Total
OUTPUT "Average: ", ROUND(Total / 12, 1)
OUTPUT "Wettest month: ", Wettest

Describe the processes involved in this algorithm.

Model answer

For each of the 12 months, the rainfall is input into the array Rain. Each value is validated: while it is below 0 or above 500, an error message is output and the value must be entered again. Each valid value is added to Total, and if it is higher than the rainfall of the wettest month so far, that month's number is stored in Wettest. After the loop, the total, the average rounded to 1 decimal place and the number of the wettest month are output.

Explanation

This one loop combines validation, totalling and finding a maximum. Wettest stores a position rather than a value, so it can be used both to compare (Rain[Wettest]) and to report which month it was.

Mark scheme
  1. 1 mark

    Inputs the rainfall for each of the 12 months and stores it in the array Rain

    max 5

  2. 1 mark

    Validates each value with a range check: a value below 0 or above 500 is rejected with an error message and must be input again

  3. 1 mark

    Adds each valid value to a running total

  4. 1 mark

    Keeps track of the month with the highest rainfall by storing its number (index) in Wettest

  5. 1 mark

    After the loop, outputs the total rainfall and the number of the wettest month

  6. 1 mark

    Calculates and outputs the average monthly rainfall rounded to 1 decimal place

Ready to try the rest? Every answer you write is marked against the mark scheme, so you can see exactly where the marks are.

AI Tutor Hints first, answers after you try

Hi! Stuck? Ask me for a hint and I’ll help you work it out. Once you’ve checked your answer I can explain exactly where the marks are.