Syllabus coverage
- Understand the program development life cycle, limited to analysis, design, coding and testing
- Understand that every computer system is made up of sub-systems, which are made up of further sub-systems
- Understand 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
- Identify the inputs, processes, outputs and storage of a problem
- 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 check, length check, type check, presence check, format check 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 IGCSE Computer Science syllabus 0478.
What an algorithm is, and why the wording has to be precise
An algorithm is a sequence of steps that solves a problem. It does not have to be written in a programming language: a recipe, a set of directions and the instructions on a ticket machine are all algorithms. What makes something an algorithm is that the steps are in the right order, each step means only one thing, and the sequence finishes after a finite number of steps.
Every algorithm can be split into inputs, processes, outputs and storage. The inputs are the data the algorithm is given, the processes are the calculations and decisions it carries out, the outputs are the results it produces, and the storage is anything it has to hold on to while it is working. A school register algorithm takes each pupil's name as input, counts the present pupils as a process, prints a summary as output, and keeps a running total of the pupils marked present while it goes.
You may be asked to explain the purpose of a given algorithm, and that means two things. Stating the purpose is one sentence about what the whole algorithm achieves, such as 'it finds the largest number in a list'. Describing the processes means going through what the algorithm actually does, step by step: 'it sets the maximum to the first value, then compares every other value with the maximum and replaces it whenever it finds a larger one'.
Precision is required. Cambridge marks algorithms written in precise pseudocode, and x > y is acceptable where 'x is greater than y' is not. The same rule applies to the decision boxes of a flowchart: write the condition as an expression, not as a sentence. Use the conventions of the syllabus, with upper-case keywords such as DECLARE, INPUT and OUTPUT, and the assignment arrow ←.
- State the purpose in one sentence, then describe the processes in the order the algorithm carries them out.
- Name every variable the algorithm uses, every value it outputs and every point at which the user is prompted for input.
- Write conditions as expressions: x > y is acceptable, x is greater than y is not.
| Part of the algorithm | What it means | Example from a school register program |
|---|---|---|
| Inputs | The data the algorithm is given to work with | The name and the mark for each pupil on the register |
| Processes | The calculations and decisions the algorithm carries out | Adding up the pupils present and comparing the total with the number on roll |
| Outputs | The results the algorithm produces | A printed attendance summary for the form tutor |
| Storage | The values the algorithm has to keep while it is working | A running total of pupils marked present, held in a variable |
Decomposition and abstraction: breaking a problem into sub-systems
Every computer system is made up of sub-systems, and each sub-system is made up of further sub-systems. A school's computer system has sub-systems for teaching, attendance and reporting. The attendance sub-system has its own sub-systems for registration, absence checking and letters home. Each level does one job properly and passes its result up to the level above, so a problem that looks impossible at the top becomes a set of small jobs at the bottom.
Decomposition is breaking a problem down into its component parts until each part is small enough to solve on its own. An online shop decomposes into a basket, a payment system and a delivery calculator, and the payment system decomposes further into card checking, address checking and order confirmation. Each part can then be designed, written and tested separately, and different programmers can work on different parts at the same time.
Abstraction is the other half of the job. It means removing the detail that does not matter for the problem in front of you and keeping only what does. A tube map is an abstraction of a railway network: it keeps the stations and the lines and throws away the real distances and the shape of the streets above them. In the same way, a program that works out a class average does not need to know a pupil's address or their shoe size.
Structure diagrams are the usual way to record decomposition on paper. The whole problem sits at the top, the main sub-problems sit underneath it, and each of those is broken down again. The diagram shows the whole solution at a glance, and each box can later become a procedure or a function in the finished program.
| Design method | What it shows | Best used for |
|---|---|---|
| Structure diagram | The problem at the top with its sub-problems underneath, broken down level by level | Planning the overall solution and showing how the parts fit together |
| Flowchart | The steps of a solution as shapes joined by arrows, including the decisions and the loops | Showing the flow of control through a solution, especially where decisions are involved |
| Pseudocode | The steps of a solution written as precise statements, using the syllabus keywords | Setting out the detail of a solution so that it can be turned into program code |
The program development life cycle: analysis, design, coding and testing
The program development life cycle has four stages, and Cambridge limits the examinable list to these: analysis, design, coding and testing. The stages run in order, but the cycle can be repeated: if testing uncovers a problem with the design, you go back and change the design.
In analysis you work out what the problem really is. That means abstracting the important details, decomposing the problem, and identifying the problem and its requirements: what the program must take in, what it must produce, and what it must do in between. Getting this stage wrong is expensive, because everything that follows depends on it.
In design you work out how the solution will be built, without writing the finished code. Decomposition carries on here, and the design is recorded as structure diagrams, flowcharts or pseudocode.
In coding you turn the design into program code and test it as you go. This is iterative testing: you check each procedure or function as soon as you write it, rather than waiting until the whole program is finished and trying to test everything at once.
In testing you run the finished program with planned test data and compare what it produces with what you expected. Testing is not proof that a program works; it is a search for errors, and the test data has to be chosen to try to make the program fail.
| Stage | What you do at this stage | What you produce |
|---|---|---|
| Analysis | Abstract the problem, decompose it, and identify the problem and its requirements | A clear statement of what the program must do, with its inputs, processes, outputs and storage |
| Design | Decompose further and decide how the solution will work | Structure diagrams, flowcharts and pseudocode |
| Coding | Write the program code and test each part as it is written, which is iterative testing | Working, commented program code |
| Testing | Run the program with planned test data and compare the results with the expected results | A record of the tests carried out, the test data used and the results |
Sequence, selection and iteration, in pseudocode and in flowcharts
Sequence means the statements are carried out one after another, in the order they are written. It is the default, and the order matters: setting a total to 0 before a loop gives a correct total, while the same statement inside the loop wipes out the total on every pass.
Selection means the program chooses between different paths. An IF statement tests a condition and runs its statements only when the condition is true, with an optional ELSE clause for the other case. A CASE statement chooses between several branches depending on the value of one variable, and an OTHERWISE branch at the end catches anything that does not match.
Iteration means repeating statements, and there are three loops you must be able to tell apart. A count-controlled loop (FOR ... NEXT) repeats a known number of times. A pre-condition loop (WHILE ... DO ... ENDWHILE) tests its condition before the statements run, so it may run zero times. A post-condition loop (REPEAT ... UNTIL) tests its condition after the statements have run, so it always runs at least once.
In a flowchart the three constructs look different straight away. Sequence is a run of process boxes joined by arrows, selection is a diamond with two labelled exits, and iteration is a loop in which an arrow carries control back to a point earlier in the chart. There are six flowchart symbols you are expected to use, and they are listed in the table below.
| Symbol | How it is drawn | What it is used for |
|---|---|---|
| Flow line | An arrow | Shows control passing between the connected shapes |
| Process | A rectangle | Something being performed or done, such as a calculation or an assignment |
| Subroutine | A rectangle with double lines down its left and right sides | A call to a subroutine, which is drawn as its own, non-linked flowchart |
| Input/Output | A parallelogram | Data being input into, or output from, the flowchart |
| Decision | A diamond | A Yes/No or True/False question, with two lines leaving it for the two possible outcomes |
| Terminator | A rounded, stadium-shaped box | The Start and the Stop of the process |
Standard methods of solution: search, sort, totalling, counting and averages
Cambridge limits the standard methods of solution to six: linear search, bubble sort, totalling, counting, and finding maximum, minimum and average values. You need to recognise each one from its pseudocode, complete one that is partly written, and say what it does.
Totalling keeps a running total: the total is set to 0 before the loop and Total ← Total + Value sits inside it. Counting keeps a running count of how many items have been processed: the count is set to 0 before the loop and Count ← Count + 1 sits inside it. The two are often used together so that an average can be worked out as Total / Count.
Finding the maximum starts by setting the maximum to the first value in the list, then compares every remaining value with it and replaces the maximum whenever a larger value turns up. Finding the minimum is the same with the comparison reversed. Setting the maximum to 0 instead of to the first value is a classic error, because a list of negative numbers would leave the maximum sitting at 0.
A linear search checks each item in turn from the start until the item is found or the list runs out. It works on any list, sorted or not, but it is slow on a long list. A bubble sort puts a list into order by comparing neighbouring pairs and swapping them whenever they are in the wrong order, passing through the list again and again until a complete pass produces no swaps. Both of these are built out of the three constructs: a loop for the repetition, a selection for the comparison, and a sequence for the swap.
| Method | What it does | The line that does the work |
|---|---|---|
| Totalling | Adds every value in a list to give a running total | Total ← Total + Value, with Total set to 0 before the loop |
| Counting | Counts how many items have been processed | Count ← Count + 1, with Count set to 0 before the loop |
| Finding the maximum | Finds the largest value in a list | IF Value > Maximum THEN Maximum ← Value, with Maximum set to the first value in the list |
| Finding the minimum | Finds the smallest value in a list | IF Value < Minimum THEN Minimum ← Value, with Minimum set to the first value in the list |
| Finding the average | Divides the total by the number of values | Average ← Total / Count |
| 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 | Compares neighbouring items and swaps them when they are in the wrong order, repeating until a complete pass makes no swaps | IF List[Index] > List[Index + 1] THEN swap the two items using a temporary variable |
Validation, verification and test data
Validation is an automatic check made by the program as data is input, to test whether the data is sensible and allowed. It cannot tell whether the data is correct, only whether it is reasonable. A range check would accept 12/04/2009 as a date of birth for a Year 8 pupil even though it belongs to the wrong pupil, because it is a perfectly valid date.
Verification is a check that the data has been entered accurately, without being changed on the way in. It is about copying, not about sense. The two examinable methods are a visual check, where a person reads the data back and compares it with the source document, and a double entry check, where the data is typed in twice and the program compares the two versions, accepting the data only if they match.
The examinable validation checks are the range check, length check, type check, presence check, format check and check digit. A range check accepts only values between a lowest and a highest; a length check accepts only strings with the right number of characters; a type check accepts only data of the right type; a presence check refuses to accept a field that has been left empty; a format check insists on a particular pattern, such as dd/mm/yyyy for a date; and a check digit is a calculated extra digit added to a long number such as a barcode so that a single mistyped digit can be detected.
Test data has to be chosen deliberately. The four types are normal, abnormal, extreme and boundary data. Extreme data is the largest or smallest acceptable value, while boundary data is the largest or smallest acceptable value together with the corresponding smallest or largest rejected value. For a program that accepts an age from 11 to 18, extreme data would be 11 and 18, and boundary data would be 11 and 18 (which must be accepted) together with 10 and 19 (which must be rejected).
| Check or term | What it tests | Example |
|---|---|---|
| Range check | That a value lies between a lowest and a highest acceptable value | An exam mark must be from 0 to 100 |
| Length check | That a string contains the right number of characters | A mobile number must be exactly 11 digits |
| Type check | That the data is of the right data type | An age 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 correctly | The last digit of a barcode is calculated from all the others |
| Visual check | That the data on screen matches the source document | Reading a name back from the screen and comparing it with the form |
| Double entry check | That the same data has been typed in twice in exactly the same way | A password or a bank account number typed in twice and compared |
Dry runs, trace tables and finding errors
A dry run is working through an algorithm by hand, line by line, writing down the value of every variable as it changes. A trace table is how you record a dry run: one column for each variable, one row for each pass through the algorithm, and often a column showing what the algorithm outputs.
Work down the algorithm in order and write the value of a variable only after it has been changed. Leave a cell empty until that variable has a value, and never guess the final answer and work backwards: the marks are for the intermediate values as the algorithm runs. If a loop runs four times, the trace table needs four rows, and the output goes in its own row after the loop has finished.
The trace table below follows an algorithm that adds up only those scores of 50 or more, and counts how many of them there are. The four scores input are 40, 60, 70 and 30, and the algorithm outputs the value of Count once the loop has finished.
Dry runs are also the best way to find errors. The errors you will be asked about usually fall into a few types: a loop whose condition never becomes false, so the algorithm never finishes; a variable that is used before it has been given a value; a comparison written the wrong way round, so the algorithm takes the wrong branch; a loop that runs one time too many or one time too few; and an OUTPUT statement left inside a loop when it should sit after the loop, so the answer is printed several times.
When you are asked to suggest a correction, write the statement as it should be. 'Change the loop' earns nothing, but 'change UNTIL Count > 10 to UNTIL Count = 10' earns the mark, because the examiner can see exactly what you mean and where.
| Index | Score input | Score >= 50? | Total | Count |
|---|---|---|---|---|
| 1 | 40 | FALSE | 0 | 0 |
| 2 | 60 | TRUE | 60 | 1 |
| 3 | 70 | TRUE | 130 | 2 |
| 4 | 30 | FALSE | 130 | 2 |
| Output | 2 |
Key terms you must be able to define
- Algorithm
- A sequence of steps that solves a problem. The steps are in a fixed order, each step is unambiguous, and the sequence finishes after a finite number of steps.
- Program development life cycle
- The four stages a program goes through: analysis, design, coding and testing.
- Decomposition
- Breaking a problem down into its component parts, or sub-problems, until each part is small enough to solve on its own.
- Abstraction
- Removing the detail that does not matter for the problem being solved and keeping only the detail that does.
- Sub-system
- A part of a larger system. Every computer system is made up of sub-systems, and each sub-system is made up of further sub-systems.
- Structure diagram
- A diagram that shows a problem at the top with its sub-problems broken down underneath, level by level.
- Flowchart
- A diagram of a solution in which shapes representing processes, decisions and input/output are joined by arrows showing the flow of control.
- Pseudocode
- A way of writing an algorithm as precise statements using the syllabus keywords, such as DECLARE, INPUT, OUTPUT, IF and REPEAT, which can later be turned into program code.
- Sequence
- Statements carried out one after another, in the order in which they are written.
- Selection
- A construct in which the program chooses between different paths, using an IF statement or a CASE statement.
- Iteration
- A construct in which statements are repeated. It may be a count-controlled loop, a pre-condition loop or a post-condition loop.
- Dry run
- Working through an algorithm by hand, step by step, writing down the value of each variable as it changes.
- Trace table
- A table used to document a dry run, with one column for each variable and one row for each pass through the algorithm.
- Validation
- An automatic check made by the program as data is input, to test whether the data is sensible and allowed. It does not check whether the data is correct.
- Verification
- A check that data has been entered accurately and has not been changed on the way in. The two methods are the visual check and the double entry check.
- Range check
- A validation check that accepts only values lying between a lowest and a highest acceptable value.
- Length check
- A validation check that accepts only strings containing a set number of characters.
- Type check
- A validation check that accepts only data of the expected data type, such as an integer where a number is required.
- Presence check
- A validation check that refuses to accept a field that has been left empty.
- Format check
- A validation check that accepts only data following a required pattern, such as a date written as dd/mm/yyyy.
- Check digit
- An extra digit calculated from the other digits of a long number and added to it, so that a single digit typed wrongly can be detected.
- Visual check
- A verification method in which a person reads the data back and compares it with the source document.
- Double entry check
- A verification method in which the data is typed in twice and the program compares the two versions, accepting it only if they match.
- Normal data
- Test data of the kind a reasonable user would be expected to enter, which the program should accept.
- Abnormal data
- Test data that 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.
- 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 through the list until a complete pass makes no swaps.
Applied to real systems
Cambridge sets 0478 in systems you already use - a phone, a school network, a supermarket till, a website, a bank. Use these as models for how to apply the theory to a context you have not seen before, then write your own.
Every barcode ends in a check digit calculated from all the other digits. If a digit is misread or mistyped, the check digit will not match, so the till rejects the code instead of charging the wrong price. The barcode number is also checked for length and format, which is why a short code or one containing a letter never gets as far as looking up the product.
A cash machine uses several validation checks on the same keypad entry. A presence check makes sure something has been typed, a length check makes sure the PIN has the right number of digits, a type check makes sure every character is a digit, and a range check makes sure the amount requested is not larger than the daily limit. The amount is also verified by asking the customer to confirm it before the cash is handed over.
A school's attendance system decomposes into sub-systems for registration, absence checking and letters home, and each of those is broken down again. The registration sub-system has its own inputs (the mark for each pupil), processes (totalling the present pupils and comparing the total with the number on roll), output (the daily summary) and storage (the running total while the register is taken).
When you place an order, the postcode is checked against a format, the card number against a check digit, and the house number with a presence check so that the order cannot be sent nowhere. If any check fails, the order is not submitted, which is why a form sometimes refuses to accept what you have typed and highlights one box in red.
A height restriction is a decision, so it is drawn in a flowchart as a diamond. The rider's height is input, the decision box asks whether the height is greater than or equal to the minimum, and one exit leads to a process box that admits the rider while the other leads to an output telling them they are too short. Boundary data for testing that program is exactly the minimum height, which must be admitted, and one centimetre less, which must be turned away.
Sorting a playlist by title is a bubble sort. The app compares each pair of neighbouring titles, swaps them when they are in the wrong order, and repeats the passes until a complete pass makes no swaps at all. Only then is the list in order, which is why a very long playlist can take a moment to sort on an older phone.
Flashcards
Click a card to flip it. Mark honestly — the tracker uses this.
Exam-style questions
8 questions, 25 marks. Write your answer, then reveal the mark scheme and tick each point you actually made. Answering honestly here is what makes the rest of the site useful.
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, not in English. Use the conventions in the syllabus: upper-case keywords such as DECLARE, IF, THEN, OUTPUT and REPEAT, the assignment arrow ←, and indentation for every line that sits inside another statement.
- Learn the six flowchart symbols as shapes. Questions ask you to complete a flowchart or to say which shape is missing, and a process box where a decision box belongs loses the mark even when the logic is right.
- In a trace table, fill in one row for every pass through the loop and leave the output for a row of its own at the end. Marks are awarded for the intermediate values of the variables, not for the final answer.
- In a validation question, name the check and say what it tests. 'A range check' on its own earns nothing; 'a range check so that the mark entered is between 0 and 100' earns the mark.
- For test data questions, give values rather than descriptions. For an accepted range of 11 to 18, boundary data is 11 and 18 (accepted) together with 10 and 19 (rejected), not 'a value slightly too big'.