OCR J277 GCSE Computer Science · 2.1 Algorithms
Stretch tasks Designing, Creating and Refining Algorithms
Quiz Challenge
A quiz game against four computer players, then short and long written answers.
- Quiz Blitz12 questions against the clock
- Quick Fire4 short answers
- Big Think2 long answers
About 20 minutes
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
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
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
Which flowchart symbol shows a decision?
- A rectangle
- A parallelogram
- A rounded rectangle
- A diamond
Which flowchart symbol is used for input or output?
- A circle
- A parallelogram
- A diamond
- A rectangle
A function returns a value, but a procedure does not.
- True
- False
What does this algorithm print?
total = 0 for i = 1 to 4 total = total + i next i print(total)An array is declared as array scores[5]. What is its highest index?
- 4
- 5
- 6
- 0
What does this print?
name = "Computer" print(name.substring(0,4))How many times does for i = 0 to 10 run?
- 9
- 12
- 11
- 10
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
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
What is the name of a table that records each variable's value after every step?
What does this print?
x = 3 while x < 20 x = x * 2 endwhile print(x)- 20
- 48
- 24
- 12
In a flowchart, both branches of a decision should be labelled.
- True
- False
Quiz Challenge, round 2: Quick Fire
Explain the difference between a function and a procedure. [2 marks]
Describe how to complete a trace table. [2 marks]
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 iGive two ways an algorithm could be made more efficient. [2 marks]
Quiz Challenge, round 3: Big Think
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 iDescribe four common errors to check for when correcting an algorithm. [4 marks]
This or That: tick the right answer
Which symbol starts and ends a flowchart?
- A diamond
- A rounded rectangle
What does this print?
print("Hello " + "Sam")- Hello + Sam
- Hello Sam
What is array board[3,3]?
- A 2D array
- An array of 33 items
Which keyword ends a while loop in OCR's reference language?
- endwhile
- next
A do...until loop always runs...
- Zero or more times
- At least once
Why fill in every row of a trace table?
- Marks are given for the table
- It makes the program faster
What does this print?
x = 7 if x > 5 then print("big") else print("small") endif- small
- big
Which loop suits repeating something exactly 10 times?
- A while loop
- A for loop
Memory Match: match each item to its meaning
| Item | Meaning |
|---|---|
A for i = 1 to 5 | 1 The number of characters in a string |
B while x < 10 | 2 Sends a value back from a function |
C name.length | 3 Flowchart symbol for input or output |
D return | 4 A count-controlled loop |
| E Parallelogram | 5 Flowchart symbol for a decision |
| F Diamond | 6 A condition-controlled loop |
Sort It: tick one box in each row
Which flowchart symbol does each step need?
| Statement | Terminal | Process | Input/output | Decision |
|---|---|---|---|---|
| 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
- A diamond A diamond has exactly two ways out, which must be labelled yes and no.
- A parallelogram Rectangles are processes, diamonds are decisions, rounded rectangles start and stop.
- True That distinction is examined regularly.
- 10 1 + 2 + 3 + 4 = 10. The loop includes 4.
- 4 Five elements have indexes 0, 1, 2, 3 and 4. There is no index 5.
- Comp substring(0,4) starts at index 0 and takes 4 characters: Comp.
- 11 0 to 10 includes both ends: that is 11 values. Off by one errors start here.
- 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.
- total is used before it is given a value total must be initialised, for example total = 0, before the loop adds to it.
- trace table A trace table shows what an algorithm actually does, not what you assume it does.
- 24 x goes 3, 6, 12, 24. At 24 the condition x < 20 is false, so the loop stops.
- 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 answerA 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 answerDraw 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 answerThe 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 answerStop 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 answeri = 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 answerCheck 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
- A rounded rectangle Terminals are rounded rectangles. Diamonds are decisions.
- Hello Sam + joins two strings together, so the result is one string.
- A 2D array Two sizes means two dimensions: 3 rows by 3 columns.
- endwhile next ends a for loop. endwhile ends a while loop.
- At least once The condition is checked at the end, so the body runs before it is ever tested.
- Marks are given for the table A full table can earn marks even with one slip. A lone final answer cannot.
- big 7 is greater than 5, so the first branch runs.
- 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
- Process total = total + price A calculation or assignment is a process: a rectangle.
- Process count = 0 Setting a variable is a process.
- Input/output Output a well done message Showing a message is output.
- Input/output Display the total Output goes in a parallelogram too.
- Input/output Ask the user for their name Reading input goes in a parallelogram.
- Decision Is score > 50? A yes or no question goes in a diamond.
- Process Calculate the average Calculations go in process boxes.
- Terminal Stop Every flowchart ends with a terminal.
- Terminal Start Start and stop go in rounded rectangles: terminals.
- Decision Has the user typed quit? A question with two branches is a decision.
- Decision Is the list empty? A decision diamond needs yes and no labels.