Edexcel GCSE Computer Science June 2022 Paper 1, Question 5: computational thinking

Pearson Edexcel 1CP2/01 June 2022, Question 5: why a passed flag makes a search of a sorted array efficient, the strawberry box trace table for inputs 404, 393, 395 and 405, and a flowchart that says which of two numbers is greater. Worked through, with the programs to run.

Past paper questionPearson 1CP2/01June 2022 Paper 118 marksTrace table

Question 5 of the Pearson Edexcel GCSE Computer Science Paper 1 from the June 2022 series (1CP2/01, Principles of Computer Science) is the computational thinking question: 18 marks, and the only place on the written paper where you read and trace code. This page works through parts (b), (c) and (d).

We do not copy the paper here. Open it beside this page: Edexcel June 2022 Paper 1 question paper (PDF). When you have finished, check the mark scheme too.

Part (b): why the passed flag helps (2 marks)

A search of a sorted array runs while the index is inside the array, the target has not been found, and it has not been passed. Inside, if the item is greater than the target, passed is set to True.

The answer is a linked pair: if the item at the current index is greater than the target, the target cannot be further on in a sorted array, so the loop ends without checking the rest. The mark scheme wants "the value at the index", not just "the index".

Part (c): the strawberry trace table (6 marks)

Four boxes are weighed. A box under 395 or over 405 is rejected. Otherwise it is accepted. At the end the program displays the two counts.

The inputs are 404, 393, 395, 405. Test each against both limits: 404 is inside; 393 is under 395, rejected; 395 is not under 395, accepted; 405 is not over 405, accepted.

count accept reject weight Display
0 0 0 0
1 1 404
2 1 393
3 2 395
4 3 405 3 1

One mark a row. The mark scheme accepts the final "3 1" on its own row or on the last one, and blanks may be filled with the previous value.

Part (d): the flowchart (6 marks)

Two numbers are entered. The flowchart says which is greater, or that they are equal.

  1. Start.
  2. Input the first number. Input the second (the same box is allowed).
  3. Decision: is the first equal to the second? Yes: output "equal". No: on to the next decision.
  4. Decision: is the first greater than the second? Yes: output "first is greater". No: output "second is greater".
  5. All three outputs lead to Stop.

The six marks: both terminators; two inputs; one decision testing equal, greater or less; a different test in a second decision; Yes and No on every decision; and the logic reaching three valid outputs.

Where the marks are lost

  • 395 rejected. "Less than 395" does not include 395. Boundary values are why the inputs were chosen.
  • The display on every row. The program only prints once, after the loop.
  • One decision box with three exits. A decision has exactly two.
  • Describing passed as "makes the loop stop" with no reason. Say what condition sets it and why that means the target is not there.

Run it

The strawberry program with the paper's inputs, printing a trace row each time. Then the greater-or-equal check on two numbers you type.

The trace ends with 3 accepted and 1 rejected. Then enter two numbers: it says which is greater, or that they are equal.
The program
from bugbot import *
connect()

count = 0
weight = 0
accept = 0
reject = 0
inputs = [404, 393, 395, 405]
print("count accept reject weight")
while count < 4:
    weight = inputs[count]
    count = count + 1
    if weight < 395 or weight > 405:
        reject = reject + 1
    else:
        accept = accept + 1
    print(count, accept, reject, weight)
print(accept, reject)

first = int(input("First number: "))
second = int(input("Second number: "))
if first == second:
    print("The numbers are equal")
elif first > second:
    print("The first number is greater")
else:
    print("The second number is greater")
Put this demo on your own site

Paste it into a school website, Moodle, Google Sites or a blog. More options on the embed page.

Questions

What is the answer to Edexcel 2022 Paper 1 Question 5(c)?

count goes 1, 2, 3, 4. accept goes 1, then 2, then 3. reject becomes 1 on the second box. The weights are 404, 393, 395, 405 and the display is 3 1.

Why does a passed flag make a search more efficient?

In a sorted array, once an item greater than the target is reached the target cannot appear later, so the search can stop instead of checking every remaining item.

How many exits does a flowchart decision have?

Exactly two, labelled Yes and No or True and False. To choose between three outcomes you need two decisions.

Every Edexcel 1CP2 question we have worked · Guide: Linear search and binary search explained

Learn it step by step

  1. F5.4 Trace tables Algorithms
  2. F5.2 Flowcharts Algorithms
  3. F5.5 Linear search Algorithms
Open the lessons

This is our own explanation of a published exam question. It is not written or endorsed by Pearson, and the question paper and mark scheme remain Pearson's copyright. Read them on Pearson's site with the links on this page.