OCR J277 GCSE Computer Science · 2.1 Algorithms

Stretch tasks Designing, Creating and Refining Algorithms

Task 1

Quiz Challenge

A quiz game against four computer players, then short and long written answers.

  1. Quiz Blitz12 questions against the clock
  2. Quick Fire4 short answers
  3. Big Think2 long answers

About 20 minutes

Task 2

This or That

Pixel the cat asks 8 questions. Each has two answers: pick the right one.

  • Two answers to every question
  • A fish treat for every right answer
  • Streaks win Pixel shades, then a party hat

About 4 minutes

Task 3

Memory Match

Flip the cards two at a time to match each item card to its meaning card.

  • 12 cards: each item has a meaning
  • One peek at every card
  • Combo points for pairs found in a row

6 pairs, about 4 minutes

Task 4

Sort It

Sort each statement into the right box, like the tick-box tables in the exam.

  • 11 cards to sort into 4 boxes
  • Drag a card, tap a box or press its number
  • Combo points for cards sorted in a row

11 cards, about 4 minutes

The games need JavaScript. Every question is below, with the answers at the end.

Read the lesson: Designing, Creating and Refining Algorithms

Designing, Creating and Refining Algorithms: the questions

Quiz Challenge, round 1: Quiz Blitz

  1. Which flowchart symbol shows a decision?

    • A rectangle
    • A parallelogram
    • A rounded rectangle
    • A diamond
  2. Which flowchart symbol is used for input or output?

    • A circle
    • A parallelogram
    • A diamond
    • A rectangle
  3. A function returns a value, but a procedure does not.

    • True
    • False
  4. What does this algorithm print?

    total = 0
    for i = 1 to 4
        total = total + i
    next i
    print(total)

  5. An array is declared as array scores[5]. What is its highest index?

    • 4
    • 5
    • 6
    • 0
  6. What does this print?

    name = "Computer"
    print(name.substring(0,4))

  7. How many times does for i = 0 to 10 run?

    • 9
    • 12
    • 11
    • 10
  8. Which TWO make an algorithm more efficient?

    Tick 2.

    • Printing every step
    • Stopping a search as soon as the item is found
    • Moving an unchanging calculation out of a loop
    • Adding more comments
    • Using longer variable names
  9. What is wrong with this algorithm?

    for i = 1 to 5
        total = total + i
    next i
    • i never changes
    • The loop should start at 0
    • total is used before it is given a value
    • The loop runs forever
  10. What is the name of a table that records each variable's value after every step?

  11. What does this print?

    x = 3
    while x < 20
        x = x * 2
    endwhile
    print(x)
    • 20
    • 48
    • 24
    • 12
  12. In a flowchart, both branches of a decision should be labelled.

    • True
    • False

Quiz Challenge, round 2: Quick Fire

  1. Explain the difference between a function and a procedure. [2 marks]

  2. Describe how to complete a trace table. [2 marks]

  3. This loop should print the whole numbers from one to ten. Identify the error and correct it. [2 marks]

    for i = 0 to 10
        print(i)
    next i

  4. Give two ways an algorithm could be made more efficient. [2 marks]

Quiz Challenge, round 3: Big Think

  1. Trace this algorithm, showing the value of each variable, then state what it prints. [4 marks]

    total = 0
    for i = 1 to 4
        total = total + i
        if total > 5 then
            print(total)
        endif
    next i

  2. Describe four common errors to check for when correcting an algorithm. [4 marks]

This or That: tick the right answer

  1. Which symbol starts and ends a flowchart?

    • A diamond
    • A rounded rectangle
  2. What does this print?

    print("Hello " + "Sam")
    • Hello + Sam
    • Hello Sam
  3. What is array board[3,3]?

    • A 2D array
    • An array of 33 items
  4. Which keyword ends a while loop in OCR's reference language?

    • endwhile
    • next
  5. A do...until loop always runs...

    • Zero or more times
    • At least once
  6. Why fill in every row of a trace table?

    • Marks are given for the table
    • It makes the program faster
  7. What does this print?

    x = 7
    if x > 5 then
        print("big")
    else
        print("small")
    endif
    • small
    • big
  8. Which loop suits repeating something exactly 10 times?

    • A while loop
    • A for loop

Memory Match: match each item to its meaning

ItemMeaning
A for i = 1 to 51 The number of characters in a string
B while x < 102 Sends a value back from a function
C name.length3 Flowchart symbol for input or output
D return4 A count-controlled loop
E Parallelogram5 Flowchart symbol for a decision
F Diamond6 A condition-controlled loop

Sort It: tick one box in each row

Which flowchart symbol does each step need?

StatementTerminalProcessInput/outputDecision
total = total + price
count = 0
Output a well done message
Display the total
Ask the user for their name
Is score > 50?
Calculate the average
Stop
Start
Has the user typed quit?
Is the list empty?
Answers

Round 1: Quiz Blitz

  1. A diamond A diamond has exactly two ways out, which must be labelled yes and no.
  2. A parallelogram Rectangles are processes, diamonds are decisions, rounded rectangles start and stop.
  3. True That distinction is examined regularly.
  4. 10 1 + 2 + 3 + 4 = 10. The loop includes 4.
  5. 4 Five elements have indexes 0, 1, 2, 3 and 4. There is no index 5.
  6. Comp substring(0,4) starts at index 0 and takes 4 characters: Comp.
  7. 11 0 to 10 includes both ends: that is 11 values. Off by one errors start here.
  8. Stopping a search as soon as the item is found; Moving an unchanging calculation out of a loop Efficiency means the same output with fewer steps or less memory.
  9. total is used before it is given a value total must be initialised, for example total = 0, before the loop adds to it.
  10. trace table A trace table shows what an algorithm actually does, not what you assume it does.
  11. 24 x goes 3, 6, 12, 24. At 24 the condition x < 20 is false, so the loop stops.
  12. True An unlabelled diamond is ambiguous, and in the exam it loses the mark.

Round 2: Quick Fire

    • A function returns a value
    • A procedure carries out a task but does not return a value
    Model answer

    A function returns a value to the code that called it. A procedure carries out a task but does not return a value.

    • Draw a column for every variable and for any output
    • Work through one line at a time, adding a row whenever a value changes
    Model answer

    Draw a column for every variable and one for any output. Then work through the algorithm one line at a time, writing a new row whenever a value changes, without skipping any iterations.

    • The loop starts at 0, so it runs 11 times
    • It should be for i = 1 to 10
    Model answer

    The loop starts at 0, so it runs 11 times and prints 0 as well. It should be for i = 1 to 10.

    • Stop searching as soon as the item is found
    • Move calculations that never change out of a loop
    • Replace repeated code with a loop or subroutine
    • Use a more efficient algorithm, such as binary search
    Model answer

    Stop searching as soon as the item is found instead of checking the rest of the list, and move any calculation that never changes outside the loop.

Round 3: Big Think

    • i = 1 and 2: total becomes 1, then 3
    • i = 3: total becomes 6
    • i = 4: total becomes 10
    • It prints 6, then 10
    Model answer

    i = 1, total = 1. i = 2, total = 3. i = 3, total = 6, which is more than 5, so it prints 6. i = 4, total = 10, so it prints 10. The output is 6 and 10.

    • Off by one errors in loops
    • Array indexes out of range
    • Assignment used instead of comparison
    • The wrong comparison operator at a boundary
    • A variable used before it is initialised
    • An infinite loop
    • The wrong data type
    • Steps in the wrong order
    Model answer

    Check for off by one errors, where a loop runs one too many or one too few times, and fix the start or end value. Check every array index is in range: an array of 5 items has indexes 0 to 4. Check that each variable is initialised before it is used, for example setting a total to 0 before adding to it. Check for infinite loops, where the condition can never become false, and make sure the loop variable changes inside the loop.

This or That

  1. A rounded rectangle Terminals are rounded rectangles. Diamonds are decisions.
  2. Hello Sam + joins two strings together, so the result is one string.
  3. A 2D array Two sizes means two dimensions: 3 rows by 3 columns.
  4. endwhile next ends a for loop. endwhile ends a while loop.
  5. At least once The condition is checked at the end, so the body runs before it is ever tested.
  6. Marks are given for the table A full table can earn marks even with one slip. A lone final answer cannot.
  7. big 7 is greater than 5, so the first branch runs.
  8. A for loop A for loop is count-controlled. A while loop repeats until a condition changes.

Memory Match

  • A 4 for i = 1 to 5: A count-controlled loop
  • B 6 while x < 10: A condition-controlled loop
  • C 1 name.length: The number of characters in a string
  • D 2 return: Sends a value back from a function
  • E 3 Parallelogram: Flowchart symbol for input or output
  • F 5 Diamond: Flowchart symbol for a decision

Sort It

  1. Process total = total + price A calculation or assignment is a process: a rectangle.
  2. Process count = 0 Setting a variable is a process.
  3. Input/output Output a well done message Showing a message is output.
  4. Input/output Display the total Output goes in a parallelogram too.
  5. Input/output Ask the user for their name Reading input goes in a parallelogram.
  6. Decision Is score > 50? A yes or no question goes in a diamond.
  7. Process Calculate the average Calculations go in process boxes.
  8. Terminal Stop Every flowchart ends with a terminal.
  9. Terminal Start Start and stop go in rounded rectangles: terminals.
  10. Decision Has the user typed quit? A question with two branches is a decision.
  11. Decision Is the list empty? A decision diamond needs yes and no labels.