Year 11 · Computer Science · Spring 1
Paper 2 practice: algorithms, programming, logic, databases · Lesson 3 of 5
The scenario question, planned and written
Exam practice7.9 Writing and amending algorithms8.2 Arrays
Year 11 · Computer Science · Paper 2 practice: algorithms, programming, logic, databases · Lesson 3 of 5
You will learn to
- Plan a scenario answer on paper: arrays, variables, loops, validation and outputs.
- Write the full solution from the plan, with comments.
- Test the solution with normal, boundary and abnormal data.
- Use the mark scheme to peer-mark another pupil's answer.
Year 11 · Computer Science · Paper 2 practice: algorithms, programming, logic, databases · Lesson 3 of 5
Success criteria
You have got it when you can say:
- I can turn the scenario into a checklist before I write any code.
- I can write a solution that meets every item on my checklist.
- I can mark a partner's answer and say which requirement they missed.
Year 11 · Computer Science · Paper 2 practice: algorithms, programming, logic, databases · Lesson 3 of 5
Retrieval starter
Questions from before. Write your answers, then show them.
- Last lesson
A diamond in a flowchart means…
A A decisionB Input or outputC A process
A. A decision
- Last unit
Which of these is lossy?
A ZIPB JPEGC PNG
B. JPEG
- Earlier this year
Which is a low-level language?
A Assembly languageB JavaC Python
A. Assembly language
Year 11 · Computer Science · Paper 2 practice: algorithms, programming, logic, databases · Lesson 3 of 5
Key words (1 of 4)
- Algorithm
- A precise, ordered set of steps that solves a problem.
- Program development life cycle
- The four stages of making a program: analysis, design, coding and testing.
- Structure diagram
- A top-down diagram that shows how a system is split into sub-systems.
- Pseudocode
- A structured, code-like way of writing an algorithm that is not tied to one language.
Year 11 · Computer Science · Paper 2 practice: algorithms, programming, logic, databases · Lesson 3 of 5
Key words (2 of 4)
- Totalling
- Keeping a running total by adding each value to a total variable.
- Counting
- Adding 1 to a counter variable each time something happens.
- Bubble sort
- Sorting by comparing neighbouring items and swapping them if they are in the wrong order, pass after pass.
Year 11 · Computer Science · Paper 2 practice: algorithms, programming, logic, databases · Lesson 3 of 5
Key words (3 of 4)
- Validation
- An automatic check that input data is reasonable and follows set rules.
- Check digit
- An extra digit calculated from the other digits, used to catch typing errors.
- Variable
- A named place in memory whose value can change while the program runs.
- Identifier
- The name given to a variable, constant, array or subroutine.
Year 11 · Computer Science · Paper 2 practice: algorithms, programming, logic, databases · Lesson 3 of 5
Key words (4 of 4)
- Data type
- The kind of value stored: INTEGER, REAL, CHAR, STRING or BOOLEAN.
- Selection
- Choosing which statements to run using a condition (IF or CASE).
- Iteration
- Repeating a block of statements in a loop.
- Array
- A data structure holding many values of the same data type under one name, each found by its index.
7.9 Writing and amending algorithms · The explanation · step 1 of 9 · part 1 of 5
Be precise, and amend with care
An algorithm must say exactly what to do. 'More than 50' is `> 50`. '50 or more' is `>= 50`. These give different results for 50.
Set every total, counter, highest and lowest to a start value before the loop. Use meaningful names like `PassCount`, not `x`, and `//` comments.
An amend question asks you to change a given algorithm. Find the line that controls the behaviour and change only that line.
7.9 Writing and amending algorithms · The explanation · step 1 of 9 · part 2 of 5
Be precise, and amend with care (continued)
Example: to make the bubble sort give descending order (largest first), change `>` to `<` in the comparison.
| Words in the question | Pseudocode |
|---|---|
| over 18 / more than 18 | `Age > 18` |
| 18 or over / at least 18 | `Age >= 18` |
| under 18 / less than 18 | `Age < 18` |
| between 1 and 21 inclusive | `Days >= 1 AND Days <= 21` |
| not equal to -1 | `Value <> -1` |
7.9 Writing and amending algorithms · The explanation · step 1 of 9 · part 3 of 5
Be precise, and amend with care (continued)
// Original: sorts into ascending order (smallest first) IF Numbers[Index] > Numbers[Index + 1] // Amended: sorts into descending order (largest first) IF Numbers[Index] < Numbers[Index + 1]
7.9 Writing and amending algorithms · The explanation · step 1 of 9 · part 4 of 5
Be precise, and amend with care (continued)
numbers = [7, 3, 9, 2, 5]
top = 5
swap = True
while swap == True and top > 1:
swap = False
for index in range(top - 1):
# amended: < instead of > gives descending order
if numbers[index] < numbers[index + 1]:
temp = numbers[index]
numbers[index] = numbers[index + 1]
numbers[index + 1] = temp
swap = True
top = top - 1
print(numbers)7.9 Writing and amending algorithms · The explanation · step 1 of 9 · part 5 of 5
Be precise, and amend with care (continued)
Rewriting the whole algorithm wastes time and can add new errors. The examiner is looking for the one or two key changes.
`Days >= 1 AND <= 21` is wrong. Write the variable on both sides: `Days >= 1 AND Days <= 21`.
7.9 Writing and amending algorithms · The explanation · step 2 of 9 · part 1 of 3
The 15-mark scenario question: plan first
The last question on Paper 2 is a scenario worth 15 marks. Allow about 30 minutes. You may answer in pseudocode, Python, Visual Basic or Java.
Read the scenario twice. Underline every task. Make a numbered checklist and tick each item as you code it.
Sample scenario: a teacher records three tests for each of 30 students. Each test is out of 50. Names are already in `StudentName[1:30]`.
7.9 Writing and amending algorithms · The explanation · step 2 of 9 · part 2 of 3
The 15-mark scenario question: plan first (continued)
7.9 Writing and amending algorithms · The explanation · step 2 of 9 · part 3 of 3
The 15-mark scenario question: plan first (continued)
Marks are given for meeting each requirement. A checklist stops you forgetting one, which is the most common way to lose marks here.
7.9 Writing and amending algorithms · The explanation · step 4 of 9 · part 1 of 4
How the 15 marks are awarded
Recent mark schemes use levels, not one mark per line. AO2 (applying techniques and data structures) gives up to 9 marks. AO3 (comments, identifiers, logic and accuracy) gives up to 6 marks.
The examiner reads the whole answer and picks the band that fits best. Minor syntax errors are ignored if the logic is clear.
7.9 Writing and amending algorithms · The explanation · step 4 of 9 · part 2 of 4
How the 15 marks are awarded (continued)
| Band | AO2: techniques and data structures (9) | AO3: comments, names, accuracy (6) |
|---|---|---|
| Top | 7–9: all tasks covered with the right techniques; arrays store all the data | 5–6: fully commented, meaningful names, logical and accurate, meets all requirements |
| Middle | 4–6: some techniques suit the problem; some data stored correctly | 3–4: some comments, most names sensible, most requirements attempted |
| Low | 1–3: at least one technique used; some data stored, not well | 1–2: no useful comments, some sensible names, at least one requirement attempted |
7.9 Writing and amending algorithms · The explanation · step 4 of 9 · part 3 of 4
How the 15 marks are awarded (continued)
7.9 Writing and amending algorithms · The explanation · step 4 of 9 · part 4 of 4
How the 15 marks are awarded (continued)
Because marks come in bands, a working answer to every task beats a perfect answer to half of them. Attempt every requirement, even if one part is rough.
The explanation · 6 more steps
More on the lesson page
The lesson page has the rest of the explanation, step by step:
- Model answer in pseudocode and Python
- What an array is
- Using a variable as the index
- 2D arrays: rows and columns
- Nested loops to visit every element
- Initialising a 2D array
Year 11 · Computer Science · Paper 2 practice: algorithms, programming, logic, databases · Lesson 3 of 5
Quick quiz · 1 of 3
A function differs from a procedure because it…
- A Has a name
- B Can have parameters
- C Returns a value
C. Returns a value
Both have names and parameters. Only a function gives a value back.
Year 11 · Computer Science · Paper 2 practice: algorithms, programming, logic, databases · Lesson 3 of 5
Quick quiz · 2 of 3
A local variable…
- A Exists only inside its subroutine
- B Can be used anywhere
- C Never changes
A. Exists only inside its subroutine
It is created when the subroutine starts and gone when it ends.
Year 11 · Computer Science · Paper 2 practice: algorithms, programming, logic, databases · Lesson 3 of 5
Quick quiz · 3 of 3
DECLARE Marks : ARRAY[1:30] OF INTEGER makes…
- A One number
- B 30 whole-number slots, numbered 1 to 30
- C 30 strings
B. 30 whole-number slots, numbered 1 to 30
Cambridge arrays start at 1 unless the question says otherwise.
Year 11 · Computer Science · Paper 2 practice: algorithms, programming, logic, databases · Lesson 3 of 5
Exit ticket
Answer on paper before you go. Then check.
SUBSTRING("Computer", 1, 3) gives…
A ompB ComputerC Com
C. Com Start at position 1, take 3 characters. Cambridge strings start at 1.
A record is…
A The whole tableB One columnC One row: everything about one thing
C. One row: everything about one thing A field is a column; a record is a row.