Designing algorithms: flowcharts, pseudocode, trace tables, errors

10 questions52 marksabout 60 min

Answer on paper first, then reveal the mark scheme one mark at a time.

1Grade 6–75 marks

The flowchart shows an algorithm.

(a) Complete a trace table with columns n, count and output for the algorithm when the input is 6. [4]

(b) State the output when the input is 1. [1]

StartInput ncount = 0n > 1 ?NoYesn MOD 2 == 0 ?YesNon = n DIV 2n = n * 3 + 1count = count + 1Output countEnd
2Grade 4–55 marks

Look at the algorithm below.

nums = [4, 7, 2, 9, 5]
x = nums[0]
for i = 1 to 4
    if nums[i] > x then
        x = nums[i]
    endif
next i
print(x)

(a) Complete a trace table with columns i, x and output. [4]

(b) State the purpose of the algorithm. [1]

3Grade 6–75 marks

The algorithm below uses the MOD and DIV operators.

num = int(input("Enter a number"))
total = 0
while num > 0
    digit = num MOD 10
    total = total + digit
    num = num DIV 10
endwhile
print(total)

(a) Complete a trace table with columns num, digit, total and output when the input is 507. [4]

(b) Describe the purpose of the algorithm. [1]

Stuck on Designing algorithms: flowcharts, pseudocode, trace tables, errors?

Get it sorted in a free 30-minute session

We work through your weakest questions on this topic on Zoom. I reply the same day.

4Grade 1–34 marks

The diagram shows four flowchart symbols labelled A to D.

State what each symbol is used for. [4]

ABCD
5Grade 8–96 marks

A teacher wants a program that lets them enter test scores one at a time. Entering -1 stops the input. The program must then output the mean score and the highest score.

Write an algorithm for the program, using OCR Exam Reference Language or a high-level programming language. [6]

6Grade 1–35 marks

A vending machine program lets a customer insert coins, choose an item by typing its code and then receive the item and any change.

(a) Identify one input, one process and one output of this program. [3]

(b) The structure diagram below shows part of the design of the program. State a suitable label for the dashed box. [1]

(c) The program design is also drawn as a flowchart. State the name of the flowchart symbol that is used to show a call to a sub program. [1]

Vending machine programTake paymentSelect item?Check coins
7Grade 4–55 marks

A program should let the user enter five numbers and then output their average. The program contains errors.

01 count = 0
02 total = 0
03 while count < 5
04     num = int(input("Enter a number"))
05     total = total + num
06 endwhile
07 average = total / 6
08 print("Average is " + str(average)

(a) Line 08 contains a syntax error. Identify the error and write the corrected line. [2]

(b) Once the syntax error is fixed, the program never finishes running. Explain why, and state the line that must be added to fix it. [2]

(c) Line 07 contains a different error. State whether this is a syntax error or a logic error. [1]

8Grade 4–55 marks

The flowchart shows an algorithm that outputs the 5 times table from 1 × 5 up to 10 × 5.

(a) Complete the flowchart by writing the number of the correct statement from the table in each of the boxes A, B, C and D. Not all statements are used. [4]

1i = 0
2i = 1
3i < 10 ?
4i <= 10 ?
5Output i * 5
6i = i + 1

(b) State the number of times box C is carried out when the algorithm runs. [1]

StartABYesCDNoEnd
9Grade 6–76 marks

The algorithm below uses nested iteration.

total = 0
for i = 1 to 3
    j = i
    while j < 3
        total = total + j
        j = j + 1
    endwhile
next i
print(total)

(a) Complete a trace table with columns i, j, total and output for this algorithm. [4]

(b) State how many times the line total = total + j is executed. [1]

(c) Give one reason why the line j = j + 1 must not be removed from the algorithm. [1]

10Grade 8–96 marks

A locker uses a 4-digit PIN that is stored in the variable stored.

A program is needed that:

  • asks the user to enter a PIN
  • if the PIN entered is not exactly 4 characters long, outputs "PIN must be 4 digits"
  • otherwise compares it with the stored PIN and outputs "Wrong PIN" if it does not match
  • allows a maximum of 3 attempts (an entry of the wrong length counts as an attempt)
  • stops asking as soon as the correct PIN is entered
  • finally outputs "Unlocked" if the correct PIN was entered, otherwise "Locked out".

Write an algorithm for the program, using OCR Exam Reference Language or a high-level programming language. [6]

Stuck on this topic?

Book a free 30-minute session on WhatsApp and we'll find exactly which step is costing you the marks. Or build a timed paper on it.

Free 30-minute session