Syllabus coverage
- Understand the program development life cycle, limited to analysis, design, coding and testing, and the tasks carried out at each stage
- Understand that every computer system is made up of sub-systems, which are made up of further sub-systems, and how a problem can be decomposed into its component parts
- Use different methods to design and construct a solution to a problem, including structure diagrams, flowcharts and pseudocode
- Explain the purpose of a given algorithm by stating its purpose and describing the processes involved, including its inputs, processes, outputs and storage
- Understand standard methods of solution, limited to linear search, bubble sort, totalling, counting and finding maximum, minimum and average values
- Understand the need for validation checks on input data: range, length, type, presence, format and check digit
- Understand the need for verification checks on input data: visual check and double entry check
- Suggest and apply suitable test data, limited to normal, abnormal, extreme and boundary data
- Complete a trace table to document a dry run of an algorithm
- Identify errors in given algorithms and suggest ways of correcting them
- Write and amend algorithms for given problems or scenarios using pseudocode, program code and flowcharts, with precision at each step
Part of the O Level Computer Science syllabus 2210.
What an algorithm is, and what explaining its purpose involves
An algorithm is a set of steps that solves a problem. The steps are in a fixed order, each step can mean only one thing, and the set of steps must come to an end. A recipe, the instructions on a ticket machine and the routine a teacher follows to put a class list into alphabetical order are all algorithms, even though none of them is a computer program.
Every algorithm can be broken into four parts: the inputs it is given, the processes it carries out, the outputs it produces and the storage it needs while it is running. A program that prints the average mark of a class takes each mark as input, adds the marks together and divides by how many there are as processes, prints the average as output, and holds Total and Count as storage while the marks are being read.
When a question asks you to explain the purpose of a given algorithm, it wants two different things. Stating the purpose is a single sentence about the job as a whole, such as 'it finds the largest value in the list'. Describing the processes means walking through the algorithm in order and saying what each part does, naming the variables as you go: 'it sets Maximum to the first value, then compares every other value with Maximum and replaces Maximum whenever it meets a larger one'.
Precision is what earns the marks. Cambridge requires decisions to be written as expressions, so x > y is acceptable and x is greater than y is not. The same holds inside a flowchart's decision box: write the condition, not a sentence about it. Use the syllabus keywords in upper case, the assignment arrow ←, and indentation for every line that sits inside another statement.
- State the purpose in one sentence; spend the remaining marks describing the processes in the order they happen.
- Name the variables, the outputs and the points where the user is prompted for input.
- Write every condition as an expression such as Mark >= 50, never as English.
| Part of an algorithm | What it means | Example from a canteen till program |
|---|---|---|
| Inputs | The data the algorithm is given to work with | The price of each item in the customer's order |
| Processes | The calculations and comparisons the algorithm makes | Adding each price to a running total and working out the change due |
| Outputs | The results the algorithm produces | The total to pay and the change, printed on the receipt |
| Storage | The values held while the algorithm is running | The running total and the number of items scanned |
The program development life cycle: four stages and the tasks at each one
The program development life cycle describes how a program is produced. For 2210 it is limited to four stages: analysis, design, coding and testing. They are taught in that order because each one depends on the one before, but the cycle can be entered again: if testing shows that the design itself is wrong, the team goes back to the design stage rather than patching the code.
In analysis the team works out what the problem actually is. The tasks are abstraction (stripping out the detail that does not affect the solution), decomposition of the problem into parts, and identification of the problem and its requirements: what must go in, what must come out, what must be stored and what the program must do in between. A requirement written down badly here is expensive, because every later stage is built on it.
In design the team decides how the solution will work, without writing the finished program. Decomposition continues, and the design is recorded as structure diagrams, flowcharts or pseudocode. In coding the design is turned into program code, and each part is tested as soon as it is written; this is iterative testing, and it is the reason a programmer rarely writes two hundred lines before running anything.
In testing the finished program is run with planned test data, and what it produces is compared with what was expected. Testing is a search for errors, not a demonstration that the program works: good test data is chosen to make the program fail, and a test that passes is only useful if it could have failed.
| Stage | Tasks carried out | What the stage produces |
|---|---|---|
| Analysis | Abstraction, decomposition, identification of the problem and its requirements | A statement of what the program must do, with its inputs, outputs, storage and the processing needed |
| Design | Further decomposition, then structure diagrams, flowcharts and pseudocode | A design that can be handed to a programmer and turned into code |
| Coding | Writing the program code and testing each part as it is written (iterative testing) | Working, commented program code |
| Testing | Running the program with normal, abnormal, extreme and boundary data and comparing actual results with expected results | A record of the tests, the data used and the results |
Sub-systems, decomposition and structure diagrams
Every computer system is made up of sub-systems, and each sub-system is made up of further sub-systems. A school's system has sub-systems for admissions, timetabling and reporting; the reporting sub-system has its own sub-systems for collecting marks, calculating grades and printing reports. Each level does one job and passes its result to the level above, which is what makes a large system possible to build at all.
Decomposition is the act of breaking a problem into its component parts until each part is small enough to solve, test and understand on its own. It pays for itself three times: each part can be designed separately, each part can be tested separately, and different programmers can work on different parts at the same time without waiting for each other.
Decomposition and abstraction are used together in the analysis stage. Decomposition splits the problem up; abstraction then decides what each part needs to know and throws the rest away. A program that calculates a pupil's average mark needs the marks and the number of marks, and has no use for the pupil's address, tutor group or date of birth.
A structure diagram records the decomposition on one page. The whole problem sits at the top, its main sub-problems sit underneath, and each of those is broken down again as far as is useful. Reading downwards shows what the program is made of; reading across shows the parts that can be built in parallel. Each box is a natural candidate for a procedure or a function later on.
- The top of the diagram is the whole system, never one of its parts.
- Every box except the top one has exactly one box above it.
- A box at the bottom of a branch is a part small enough to code on its own.
Three ways to design a solution: structure diagrams, flowcharts and pseudocode
A structure diagram is the design tool for showing decomposition. It answers the question 'what is this program made of?' and is at its best when the problem is large and the team needs to divide the work.
A flowchart answers the question 'in what order does this happen?'. Shapes are joined by arrows: a rounded terminator for Start and Stop, a parallelogram for input and output, a rectangle for a process, a rectangle with double lines down its sides for a call to a subroutine, a diamond for a decision with one exit labelled Yes and the other No, and a plain arrow as the flow line. A loop appears as an arrow that carries control back to an earlier shape, which is why a flowchart shows iteration so clearly.
Pseudocode answers the question 'what exactly does each step do?'. It is written with the syllabus keywords (DECLARE, INPUT, OUTPUT, IF, THEN, ELSE, ENDIF, CASE, FOR, NEXT, WHILE, REPEAT, UNTIL) and the assignment arrow ←, and it is indented so that the structure is visible. Because it is closer to program code than the other two, it is the design method you can turn into a working program most directly.
In an exam you may be asked to complete any of the three. Completing a flowchart means adding the missing shape in the right place with the right exit labelled; completing pseudocode means adding the missing statement with the right keywords and indentation. Precision matters in both: Total ← Total + 1 is a statement, 'add one to the total' is not.
| Design method | What it shows best | Where it is used |
|---|---|---|
| Structure diagram | The parts of the solution and how they sit inside one another | Planning the overall shape of a large program and dividing the work |
| Flowchart | The order of steps, with decisions and loops drawn as shapes and arrows | Explaining a process to someone else, or checking the logic of a decision |
| Pseudocode | The exact statements and the structure of the code | Working out the detail of a solution before it is written in a programming language |
Standard methods of solution
2210 limits the standard methods of solution to linear search, bubble sort, totalling, counting and finding maximum, minimum and average values. You are expected to recognise each one from its pseudocode, to complete one that has been left half-written, and to say what a given one does.
Totalling keeps a running total: Total ← 0 before the loop, then Total ← Total + Value inside it. Counting keeps a running count of how many items have been dealt with: Count ← 0 before the loop, then Count ← Count + 1 inside it. Set either of them inside the loop and the running value is wiped out on every pass, which is the single most common error in this topic.
A linear search starts at the first item and checks each one in turn until the item is found or the list runs out. It works whether or not the list is in order, but on a long list it is slow, because on average half the items are checked. Written in pseudocode it is a loop with a condition, a comparison and a flag such as Found ← TRUE.
A bubble sort puts a list into order by comparing neighbouring pairs and swapping them whenever they are the wrong way round. One pass through the list moves the largest remaining value to the end, so the next pass can stop one place earlier. The passes repeat until a complete pass makes no swaps, which is the signal that the list is in order. A swap needs a temporary variable: Temp ← List[Index], then List[Index] ← List[Index + 1], then List[Index + 1] ← Temp.
Finding the maximum sets Maximum to the first value in the list and then compares each remaining value with it, replacing Maximum whenever a larger value appears. Finding the minimum is the same with the comparison reversed. The average is then Total / Count, computed after the loop has finished and not inside it.
| Method | What it does | The line that does the work |
|---|---|---|
| Totalling | Adds every value to give a running total | Total ← Total + Value, with Total ← 0 set before the loop |
| Counting | Counts how many items have been processed | Count ← Count + 1, with Count ← 0 set before the loop |
| Maximum | Finds the largest value in a list | IF Value > Maximum THEN Maximum ← Value, with Maximum set to the first value |
| Minimum | Finds the smallest value in a list | IF Value < Minimum THEN Minimum ← Value, with Minimum set to the first value |
| Average | Divides the total by how many values there were | Average ← Total / Count, after the loop |
| Linear search | Checks each item in turn until the item is found or the list ends | IF List[Index] = SearchItem THEN Found ← TRUE |
| Bubble sort | Swaps neighbouring items that are in the wrong order until a full pass makes no swaps | IF List[Index] > List[Index + 1] THEN swap using a temporary variable |
Validation: six checks that keep unreasonable data out
Validation is a check made by the program as data is entered, to decide whether the data is sensible and allowed. It cannot decide whether the data is true: a date of birth of 12/04/2009 passes every check as a date, and is still wrong for a pupil in Year 11. Validation keeps obvious rubbish out of the system; it does not guarantee accuracy.
2210 limits the validation checks to six. A range check accepts only values between a lowest and a highest, such as a mark from 0 to 100. A length check accepts only data with the right number of characters, such as a membership number of exactly eight digits. A type check accepts only data of the expected type, so a word is rejected where a number is required.
A presence check refuses to accept a field that has been left empty, which is what stops a form being submitted with no surname. A format check insists on a pattern, such as two digits, a slash, two digits, a slash and four digits for a date, or an @ and a dot in an email address. A check digit is an extra digit calculated from all the others and stuck on the end of a long number such as a barcode or an ISBN, so that a single digit typed wrongly or misread makes the calculated value disagree with the digit stored.
The checks are usually combined. A bank card number is length-checked, format-checked (digits only) and check-digit-checked, and the amount requested at a cash machine is range-checked against the daily limit. Each check catches a different kind of mistake, which is why one check on its own is rarely enough.
| Check | What it tests | Example |
|---|---|---|
| Range check | That a value lies between a lowest and a highest acceptable value | A month number must be from 1 to 12 |
| Length check | That the data contains the right number of characters | A membership number must be exactly eight characters |
| Type check | That the data is of the expected data type | A quantity ordered must be an integer, not a word |
| Presence check | That a field has not been left empty | A surname field must contain at least one character |
| Format check | That the data follows a required pattern | A date must be entered as dd/mm/yyyy |
| Check digit | That the digits of a long number have been copied or read correctly | The final digit of a barcode is calculated from the others and compared |
Verification, and choosing test data that is worth running
Verification is a check that the data has been copied accurately and has not been changed on the way in. It is about transcription, not about sense. The two methods in the syllabus are the visual check, where a person reads the data back from the screen and compares it with the source document, and the double entry check, where the same data is typed in twice and the program compares the two versions and accepts the data only if they match exactly.
Double entry is used where a mistake would be expensive and the data is short: a new password, an email address, a bank account number. A visual check is used where a person is checking a printed form or a screen against a paper source, and it depends on the person actually looking, which is its weakness.
Test data is chosen before the program is run, and each item is chosen for a reason. Normal data is the kind of value a sensible user would enter, and the program should accept it. Abnormal data is a value the program should reject, such as a word where a number is expected or a mark of 150. Extreme data is the largest or smallest acceptable value. Boundary data is the largest or smallest acceptable value together with the corresponding smallest or largest rejected value, so it tests both sides of the limit.
For a program that accepts a month number from 1 to 12, normal data is 6, extreme data is 1 or 12, boundary data is 1 and 12 (which must be accepted) together with 0 and 13 (which must be rejected), and abnormal data is 45 or the word June. Extreme and boundary data are not the same thing, and a question that asks for boundary data wants the rejected values as well.
| Type of test data | What it is | For an accepted range of 1 to 12 |
|---|---|---|
| Normal | A typical value the program should accept | 6 |
| Abnormal | A value the program should reject | 45, or the word June |
| Extreme | The largest or smallest acceptable value | 1 or 12 |
| Boundary | The largest or smallest acceptable value together with the corresponding smallest or largest rejected value | 1 and 12 accepted, 0 and 13 rejected |
Dry runs, trace tables and correcting errors
A dry run is carrying out an algorithm by hand, line by line, writing down the value of every variable as it changes. A trace table records the dry run: one column for each variable, one row for each pass through the algorithm, and usually a final row for the output.
Work down the algorithm in order and write a value only after the statement that changes it has been carried out. Leave a cell blank until the variable has a value, and never work out the answer first and fill the table backwards: the marks are for the intermediate values, and a table that shows only the final answer scores at most one mark. If a loop runs five times, the table needs five rows, even where a variable does not change on a pass; write the unchanged value in again.
Dry runs are also how you find errors. The errors you will be asked about fall into a few recognisable types: a loop whose condition never becomes true, so the algorithm never ends; a variable used before it has been given a value; a comparison written the wrong way round, so the wrong branch is taken; a loop that runs one time too many or one time too few; and an OUTPUT statement left inside a loop so that the answer is printed several times.
When you suggest a correction, write the statement as it should read and say where it goes. 'Change the loop' earns nothing, but 'change UNTIL Count > 10 to UNTIL Count = 10' earns the mark, because the examiner can see exactly what should change.
The trace table below follows an algorithm that reads four temperatures, adds each one to a total and counts how many are above 20. The temperatures entered are 12, 25, 9 and 25.
| Index | Temperature | Temperature > 20? | Total | Count |
|---|---|---|---|---|
| 1 | 12 | FALSE | 12 | 0 |
| 2 | 25 | TRUE | 37 | 1 |
| 3 | 9 | FALSE | 46 | 1 |
| 4 | 25 | TRUE | 71 | 2 |
| Output | 71 | 2 |
Key terms you must be able to define
- Algorithm
- A set of steps that solves a problem, in a fixed order, with each step unambiguous and the set of steps coming to an end.
- Program development life cycle
- The four stages a program passes through: analysis, design, coding and testing.
- Sub-system
- A part of a larger system that does one job, and that may itself be made up of further sub-systems.
- Decomposition
- Breaking a problem into its component parts until each part is small enough to design, code and test on its own.
- Abstraction
- Removing the detail that does not affect the solution and keeping only the detail that does.
- Structure diagram
- A diagram with the whole problem at the top and its sub-problems broken down underneath, level by level.
- Flowchart
- A diagram of a solution in which shapes for processes, decisions and input or output are joined by arrows showing the order of control.
- Pseudocode
- An algorithm written as precise statements using the syllabus keywords and the assignment arrow, so that it can be turned into program code.
- Iterative testing
- Testing each part of a program as soon as it has been written, during the coding stage, rather than waiting until the whole program is finished.
- Linear search
- A search that checks each item in turn from the start until the item is found or the list ends.
- Bubble sort
- A sort that compares neighbouring items and swaps them when they are in the wrong order, repeating passes until a complete pass makes no swaps.
- Validation
- An automatic check made as data is entered, to test whether the data is sensible and allowed; it cannot test whether the data is correct.
- Verification
- A check that data has been copied accurately and not changed on the way in, using a visual check or a double entry check.
- Check digit
- An extra digit calculated from the other digits of a long number and stored with it, so that a single mistyped digit can be detected.
- Normal data
- Test data of the kind a sensible user would enter, which the program should accept.
- Abnormal data
- Test data the program should reject, such as a value outside the accepted range or a word where a number is expected.
- Extreme data
- Test data consisting of the largest or smallest acceptable value.
- Boundary data
- Test data consisting of the largest or smallest acceptable value together with the corresponding smallest or largest rejected value.
- Dry run
- Carrying out an algorithm by hand, statement by statement, recording the value of each variable as it changes.
- Trace table
- A table documenting a dry run, with one column per variable and one row for each pass through the algorithm.
In context
2210 sets its questions inside systems a student already uses - a school network, a phone, a supermarket till, a vending machine, a website. These show how the theory is applied to a context you have not seen before, then you answer for the system you are given.
When a librarian types an ISBN, the catalogue program works along the list of books one entry at a time until it finds a match or reaches the end, which is a linear search. The last digit of the ISBN is a check digit calculated from the others, so a book whose barcode has been misread is rejected before the wrong title is issued to a pupil.
A spreadsheet of finishing times is put into order by a bubble sort: the two fastest neighbouring times are compared, swapped if they are the wrong way round, and the passes repeat until a whole pass makes no swaps. The smallest time then sits at the top, and the average time for the event is the total of the times divided by the number of runners.
A new member's date of birth must be typed as dd/mm/yyyy, so a format check rejects 3/4/09. The postcode is format-checked, the membership number is length-checked and check-digit-checked, and the email address is typed twice so that a double entry check catches a typing slip before the welcome message is sent to the wrong place.
The program that works out which bus to show accepts a route number from 1 to 40. Normal test data is 12; extreme data is 1 or 40; boundary data is 1 and 40, which must be accepted, together with 0 and 41, which must be rejected; abnormal data is 99 or the word express. Testing with 15 alone would never reveal what happens at the edges of the range.
The department's system decomposes into sub-systems for recording scores, calculating averages and producing reports. The averages sub-system is built and tested on its own with three sets of marks before it is connected to the others, which is iterative testing, and the whole system is tested again with boundary data once every sub-system has been joined together.
Flashcards
Click a card to flip it. Mark honestly — the tracker uses this.
Exam-style questions
8 questions, 28 marks. Write your answer and press Mark my answer — it is marked against the scheme and tells you which points you made and what would gain the next mark. You can still reveal the scheme and mark it yourself instead.
Mark scheme — tick each point you actually made
Mark scheme — tick each point you actually made
Mark scheme — tick each point you actually made
Mark scheme — tick each point you actually made
Mark scheme — tick each point you actually made
Mark scheme — tick each point you actually made
Mark scheme — tick each point you actually made
Mark scheme — tick each point you actually made
Exam technique for this topic
- Write algorithms in pseudocode with the syllabus keywords in upper case, the assignment arrow ←, and indentation for every line inside another statement. English sentences describing the steps earn nothing in a coding question.
- Learn the flowchart shapes as shapes. A decision is a diamond with exactly two exits, both labelled; a process is a rectangle with one exit; and a loop is drawn as an arrow going back to an earlier shape.
- In a trace table, write one row for every pass through the loop, even where a value has not changed, and give the output a row of its own at the end. The marks are for the intermediate values.
- For a validation question, name the check and say what it tests against. For a verification question, choose visual or double entry, and never offer a range check as an answer.
- For test data, give values rather than descriptions. Boundary data must include the values just outside the range as well as the values at its edges.
Why students lose marks here
Where this fits in O Level Computer Science 2210
This page is one topic of Cambridge O Level Computer Science 2210. O Level Computer Science 2210 is the course home: every area and every topic in Cambridge's own order, the papers you sit and what each one tests, and the exam-practice tools. The full topic list, with each topic linked to its revision page, is on the O Level Computer Science 2210 syllabus page.