AQA 8525 GCSE Computer Science · 3.1 Fundamentals of Algorithms

Stretch tasks Representing 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 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

Task 4

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

  1. Which symbol does AQA pseudo-code use for assignment?

    • ==
    • :=
    • ←
    • =
  2. What is output?

    OUTPUT 17 DIV 5

  3. What is output?

    OUTPUT 17 MOD 5

  4. What is output?

    OUTPUT SUBSTRING(2, 4, 'computer')

  5. A WHILE loop always runs at least once.

    • True
    • False
  6. Which loop always runs its body at least once?

    • IF ... ENDIF
    • REPEAT ... UNTIL
    • WHILE ... ENDWHILE
    • FOR ... ENDFOR
  7. What is output?

    OUTPUT LEN('computer')

  8. What is output?

    OUTPUT POSITION('computer', 'm')

  9. Which flowchart symbol must contain a question with a Yes or No answer?

    • Rounded rectangle
    • Diamond
    • Rectangle
    • Parallelogram
  10. 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
  11. Trace this algorithm. What is output?

    a ← 12
    b ← 8
    WHILE b ≠ 0
        temp ← b
        b ← a MOD b
        a ← temp
    ENDWHILE
    OUTPUT a

  12. What does FOR i ← 1 TO 10 show?

    • Assignment only
    • Definite iteration
    • Indefinite iteration
    • Selection

Quiz Challenge, round 2: Quick Fire

  1. Explain the difference between a WHILE loop and a REPEAT ... UNTIL loop. [2 marks]

  2. Explain what SUBSTRING(2, 4, 'computer') returns, and why. [2 marks]

  3. State the rules for what goes inside a decision diamond in a flowchart. [2 marks]

  4. Explain why = must not be used for assignment in AQA pseudo-code. [2 marks]

Quiz Challenge, round 3: Big Think

  1. 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 a

  2. Compare pseudo-code and flowcharts as ways of representing an algorithm. [4 marks]

This or That: tick the right answer

  1. In AQA pseudo-code, what does = mean?

    • Is equal to
    • Store this value
  2. AQA arrays start at index...

    • 0
    • 1
  3. What is output?

    OUTPUT SUBSTRING(0, 2, 'coding')
    • cod
    • co
  4. Which keyword closes a REPEAT loop?

    • UNTIL
    • ENDREPEAT
  5. When should a trace table get a new row?

    • Every time a variable changes
    • Only at the very end
  6. A decision diamond contains just the word total. Is that right?

    • Yes: any variable will do
    • No: it needs a Yes or No question
  7. Which is indefinite iteration?

    • FOR i ← 1 TO 10
    • WHILE guess ≠ answer
  8. When should you work out what an algorithm is for?

    • Before tracing it
    • After tracing it

Memory Match: match each AQA to its meaning

AQAMeaning
A ←1 Integer division
B DIV2 Closes a selection block
C MOD3 Number of characters
D LEN(s)4 A loop that runs at least once
E REPEAT ... UNTIL5 Assignment
F ENDIF6 Remainder after division

Sort It: tick one box in each row

Definite iteration, indefinite iteration or selection?

StatementDefinite iterationIndefinite iterationSelection
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

  1. ← AQA never uses = for assignment, so = only ever means is equal to.
  2. 3 DIV is integer division: 5 goes into 17 three whole times.
  3. 2 MOD gives the remainder: 17 is 3 x 5 with 2 left over.
  4. mpu Indexes 2, 3 and 4, both ends included: m, p and u. The second number is a finish position, not a length.
  5. False A WHILE loop checks first, so it can run zero times. REPEAT always runs at least once.
  6. REPEAT ... UNTIL REPEAT checks its condition at the end.
  7. 8 LEN counts every character, including spaces.
  8. 2 c is index 0, o is 1, m is 2. AQA indexes from 0.
  9. Diamond A decision diamond has exactly two labelled exits, Yes and No.
  10. As an arrow going back up to an earlier decision A backward arrow is the only way to show iteration in a flowchart.
  11. 4 b goes 8, 4, 0 while a goes 12, 8, 4. When b is 0 the loop ends and 4 is output.
  12. 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 answer

    A 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 answer

    It 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 answer

    It 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 answer

    AQA 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 answer

    12 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 answer

    Pseudo-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

  1. Is equal to Assignment uses a left arrow, so = is only ever a comparison.
  2. 0 Arrays and strings are both indexed from 0.
  3. cod Indexes 0, 1 and 2 are all included.
  4. UNTIL Every AQA block closes with an END keyword, except REPEAT, which closes with UNTIL.
  5. Every time a variable changes The examiner marks the history of the values, not just the final state.
  6. 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.
  7. WHILE guess ≠ answer It repeats until a condition is met, so the number of repeats is unknown.
  8. 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

  1. Indefinite iteration Repeats until a condition is met That is indefinite iteration.
  2. Selection Chooses which block of code to run That is selection.
  3. Definite iteration FOR i ← 0 TO LEN(items) - 1 It runs once for each item, a known number of times.
  4. Definite iteration FOR i ← 1 TO 10 The number of repeats is fixed before the loop starts.
  5. Definite iteration Repeats a number of times known before it starts That is definite iteration.
  6. Indefinite iteration WHILE guess ≠ answer It repeats until a condition is met.
  7. Definite iteration Closed by ENDFOR FOR loops are definite iteration.
  8. Indefinite iteration Might not run at all A WHILE loop checks first, so it can run zero times.
  9. Indefinite iteration REPEAT ... UNTIL guess = answer REPEAT is indefinite: it stops when the condition is true.
  10. Selection Closed by ENDIF IF blocks are selection.
  11. Selection ELSE IF mark > 69 THEN ELSE IF is another branch of a selection.
  12. Selection IF mark > 79 THEN An IF chooses between paths.