AQA 8525 GCSE Computer Science · 3.1 Fundamentals of Algorithms
Stretch tasks Representing 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 AQA card to its meaning card.
- 12 cards: each AQA 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.
- 12 cards to sort into 3 boxes
- Drag a card, tap a box or press its number
- Combo points for cards sorted in a row
12 cards, about 4 minutes
The games need JavaScript. Every question is below, with the answers at the end.
Read the lesson: Representing Algorithms
Representing Algorithms: the questions
Quiz Challenge, round 1: Quiz Blitz
Which symbol does AQA pseudo-code use for assignment?
- ==
- :=
- ←
- =
What is output?
OUTPUT 17 DIV 5What is output?
OUTPUT 17 MOD 5What is output?
OUTPUT SUBSTRING(2, 4, 'computer')A WHILE loop always runs at least once.
- True
- False
Which loop always runs its body at least once?
- IF ... ENDIF
- REPEAT ... UNTIL
- WHILE ... ENDWHILE
- FOR ... ENDFOR
What is output?
OUTPUT LEN('computer')What is output?
OUTPUT POSITION('computer', 'm')Which flowchart symbol must contain a question with a Yes or No answer?
- Rounded rectangle
- Diamond
- Rectangle
- Parallelogram
How does a loop appear in a flowchart?
- As a dotted line
- As an arrow going back up to an earlier decision
- As a circle around the steps
- As two Stop symbols
Trace this algorithm. What is output?
a ← 12 b ← 8 WHILE b ≠ 0 temp ← b b ← a MOD b a ← temp ENDWHILE OUTPUT aWhat does FOR i ← 1 TO 10 show?
- Assignment only
- Definite iteration
- Indefinite iteration
- Selection
Quiz Challenge, round 2: Quick Fire
Explain the difference between a WHILE loop and a REPEAT ... UNTIL loop. [2 marks]
Explain what SUBSTRING(2, 4, 'computer') returns, and why. [2 marks]
State the rules for what goes inside a decision diamond in a flowchart. [2 marks]
Explain why = must not be used for assignment in AQA pseudo-code. [2 marks]
Quiz Challenge, round 3: Big Think
Trace this algorithm, then state its output and its purpose. [4 marks]
a ← 12 b ← 8 WHILE b ≠ 0 temp ← b b ← a MOD b a ← temp ENDWHILE OUTPUT aCompare pseudo-code and flowcharts as ways of representing an algorithm. [4 marks]
This or That: tick the right answer
In AQA pseudo-code, what does = mean?
- Is equal to
- Store this value
AQA arrays start at index...
- 0
- 1
What is output?
OUTPUT SUBSTRING(0, 2, 'coding')- cod
- co
Which keyword closes a REPEAT loop?
- UNTIL
- ENDREPEAT
When should a trace table get a new row?
- Every time a variable changes
- Only at the very end
A decision diamond contains just the word total. Is that right?
- Yes: any variable will do
- No: it needs a Yes or No question
Which is indefinite iteration?
- FOR i ← 1 TO 10
- WHILE guess ≠ answer
When should you work out what an algorithm is for?
- Before tracing it
- After tracing it
Memory Match: match each AQA to its meaning
| AQA | Meaning |
|---|---|
A ← | 1 Integer division |
B DIV | 2 Closes a selection block |
C MOD | 3 Number of characters |
D LEN(s) | 4 A loop that runs at least once |
E REPEAT ... UNTIL | 5 Assignment |
F ENDIF | 6 Remainder after division |
Sort It: tick one box in each row
Definite iteration, indefinite iteration or selection?
| Statement | Definite iteration | Indefinite iteration | Selection |
|---|---|---|---|
| Repeats until a condition is met | |||
| Chooses which block of code to run | |||
FOR i ← 0 TO LEN(items) - 1 | |||
FOR i ← 1 TO 10 | |||
| Repeats a number of times known before it starts | |||
WHILE guess ≠ answer | |||
Closed by ENDFOR | |||
| Might not run at all | |||
REPEAT ... UNTIL guess = answer | |||
Closed by ENDIF | |||
ELSE IF mark > 69 THEN | |||
IF mark > 79 THEN |
Answers
Round 1: Quiz Blitz
- ← AQA never uses = for assignment, so = only ever means is equal to.
- 3 DIV is integer division: 5 goes into 17 three whole times.
- 2 MOD gives the remainder: 17 is 3 x 5 with 2 left over.
- mpu Indexes 2, 3 and 4, both ends included: m, p and u. The second number is a finish position, not a length.
- False A WHILE loop checks first, so it can run zero times. REPEAT always runs at least once.
- REPEAT ... UNTIL REPEAT checks its condition at the end.
- 8 LEN counts every character, including spaces.
- 2 c is index 0, o is 1, m is 2. AQA indexes from 0.
- Diamond A decision diamond has exactly two labelled exits, Yes and No.
- As an arrow going back up to an earlier decision A backward arrow is the only way to show iteration in a flowchart.
- 4 b goes 8, 4, 0 while a goes 12, 8, 4. When b is 0 the loop ends and 4 is output.
- Definite iteration The number of repeats is known before the loop starts.
Round 2: Quick Fire
- WHILE checks its condition first, so it may run zero times
- REPEAT checks at the end, so it always runs at least once
Model answerA WHILE loop checks its condition before the body runs, so it may run zero times. A REPEAT loop checks its condition at the end, so it always runs at least once.
- It returns mpu
- Both index positions are included, counting from 0
Model answerIt returns mpu. Indexing starts at 0, and both index 2 and index 4 are included, so it takes the characters at 2, 3 and 4.
- A question or condition with only a Yes or No answer
- Both exits must be labelled
Model answerIt must contain a question or condition that can only be answered Yes or No, and both of its exits must be labelled.
- AQA uses a left arrow for assignment
- = only ever means is equal to, a comparison
Model answerAQA pseudo-code uses a left arrow for assignment, because = only ever means is equal to, which is a comparison.
Round 3: Big Think
- 12 MOD 8 is 4, so b becomes 4 and a becomes 8
- 8 MOD 4 is 0, so b becomes 0 and a becomes 4
- The loop ends and 4 is output
- It finds the highest common factor
Model answer12 MOD 8 is 4, so b becomes 4 and a becomes 8. Then 8 MOD 4 is 0, so b becomes 0 and a becomes 4. The condition is now false, so the loop ends and 4 is output. The algorithm finds the highest common factor of 12 and 8.
- Pseudo-code has the structure of a program without strict syntax
- So it is easy to turn into real code
- A flowchart is a diagram using standard symbols
- Flowcharts show the flow visually, but large ones get messy
Model answerPseudo-code has the structure of a program without the strict syntax of any real language, so it is quick to write and easy to turn into real code. A flowchart is a diagram using standard symbols joined by arrows, so the flow of the algorithm can be followed visually, but a flowchart for a large algorithm becomes messy and hard to read.
This or That
- Is equal to Assignment uses a left arrow, so = is only ever a comparison.
- 0 Arrays and strings are both indexed from 0.
- cod Indexes 0, 1 and 2 are all included.
- UNTIL Every AQA block closes with an END keyword, except REPEAT, which closes with UNTIL.
- Every time a variable changes The examiner marks the history of the values, not just the final state.
- No: it needs a Yes or No question A diamond needs a condition, such as total > 100, so its exits can be labelled Yes and No.
- WHILE guess ≠ answer It repeats until a condition is met, so the number of repeats is unknown.
- After tracing it Trace it mechanically, then read the output column to see its purpose.
Memory Match
- A 5
←: Assignment - B 1
DIV: Integer division - C 6
MOD: Remainder after division - D 3
LEN(s): Number of characters - E 4
REPEAT ... UNTIL: A loop that runs at least once - F 2
ENDIF: Closes a selection block
Sort It
- Indefinite iteration Repeats until a condition is met That is indefinite iteration.
- Selection Chooses which block of code to run That is selection.
- Definite iteration
FOR i ← 0 TO LEN(items) - 1It runs once for each item, a known number of times. - Definite iteration
FOR i ← 1 TO 10The number of repeats is fixed before the loop starts. - Definite iteration Repeats a number of times known before it starts That is definite iteration.
- Indefinite iteration
WHILE guess ≠ answerIt repeats until a condition is met. - Definite iteration Closed by
ENDFORFOR loops are definite iteration. - Indefinite iteration Might not run at all A WHILE loop checks first, so it can run zero times.
- Indefinite iteration
REPEAT ... UNTIL guess = answerREPEAT is indefinite: it stops when the condition is true. - Selection Closed by
ENDIFIF blocks are selection. - Selection
ELSE IF mark > 69 THENELSE IF is another branch of a selection. - Selection
IF mark > 79 THENAn IF chooses between paths.