Syllabus coverage
- Show an understanding of abstraction: the need for and the benefits of using abstraction
- Describe the purpose of abstraction
- Produce an abstract model of a system by only including essential details
- Describe and use decomposition: break problems down into sub-problems leading to the concept of a program module (procedure / function)
- Show understanding that an algorithm is a solution to a problem expressed as a sequence of defined steps
- Use suitable identifier names for the representation of data used by a problem, and represent these using an identifier table
- Write pseudocode that contains input, process and output
- Write pseudocode using the three basic constructs of sequence, selection and iteration (repetition)
- Document a simple algorithm using a structured English description, a flowchart or pseudocode
- Write pseudocode from a structured English description, and write pseudocode from a flowchart
- Draw a flowchart from a structured English description, and draw a flowchart from pseudocode
- Describe and use the process of stepwise refinement to express an algorithm to a level of detail from which the task may be programmed
- Use logic statements to define parts of an algorithm solution
Part of the AS & A Level Computer Science syllabus 9618.
What an algorithm is
An algorithm is a solution to a problem expressed as a sequence of defined steps. The word to hold on to is defined: every step must say exactly one thing, in an order that is fixed, so that anyone following it would do the same thing and get the same result. An algorithm is not written in any particular programming language - it is the logic of the solution, and the same algorithm can be implemented in Python, Java or Visual Basic without changing a single step.
Every algorithm has the same skeleton. It takes input, which is the data it is given or reads, it performs processing, which is the calculation, comparison or storing of that data, and it produces output, which is the result shown to the user, printed or saved to a file. A program that adds two numbers has input (the two numbers), processing (the addition) and output (the total). So does a payroll system, a game or a washing machine controller - only the amount of each changes.
A useful algorithm has to meet a few conditions. It must have a defined start and finish, so it does not run forever by accident. Its steps must be unambiguous, because a step that could be read two ways cannot be programmed. It must be finite - a loop that never ends is a bug, not an algorithm. And it must produce the correct output for every valid input, including the awkward ones: no data at all, the largest value allowed, a value that is out of range. Testing those edge cases is part of designing the algorithm, not something added at the end.
Keep algorithm and program apart, because examiners test the difference. The algorithm is the solution; the program is that solution written in a programming language, with the syntax of that language, so that a computer can run it. A programmer designs the algorithm first and codes it second, because logic errors are far cheaper to find in a diagram or a few lines of pseudocode than in a thousand lines of working code. That is also why algorithms are written down in a language-independent form - so they can be checked, discussed and changed before anyone writes a line of code.
- Algorithm: a solution to a problem expressed as a sequence of defined steps.
- Input - the data the algorithm is given; processing - what it does with the data; output - the result it produces.
- The steps must be unambiguous, in a fixed order, and finite, and the algorithm must be correct for every valid input including the extremes.
- An algorithm is language-independent logic; a program is that algorithm written in a programming language and run on a computer.
- Writing the algorithm down first lets the logic be checked and changed cheaply, before any code exists.
Abstraction: keeping only what matters
Abstraction is the process of removing or hiding the detail that is not needed for a particular purpose, so that only the essential features of a problem or system are represented. The purpose is to make something complicated simple enough to reason about. A real system has an unlimited amount of detail - every rivet, every colour, every measurement to the millimetre - and a person, or a computer model, cannot work with all of it at once. Abstraction decides what is relevant and throws the rest away.
The need for abstraction follows from that. If you tried to model a road network with every lane, kerb and traffic light you would never finish, and you would not be able to answer the simple question you actually asked, which was how long the journey takes. Abstraction makes the problem small enough to solve, and it makes the solution general rather than tied to one specific case: a model of a customer that stores an account number, a name and a balance can be used for every customer in the bank.
An abstract model of a system includes only the essential details. To produce one, you decide what the model is for, then keep the features that affect that purpose and leave out everything else. A model of a car for a driving simulator needs mass, engine power, grip and steering response; it does not need the colour of the paint, the shape of the door handles or the material of the seats. The test is always the same question: if I removed this detail, would the model still answer the question it was built to answer? If the answer is yes, the detail should go.
Abstraction pays for itself in several ways. The model is simpler, so it can be understood and checked by one person. It is quicker and cheaper to build, because far less has to be described. It has fewer errors, because there is less to get wrong. It is easier to change, because a change to one part of a small model has fewer knock-on effects. And it lets you experiment safely: a flight simulator, a structural model of a bridge or a spreadsheet model of a business can be pushed to the point of failure without costing a life or a fortune.
There is a trap, and it is worth a mark on its own. Abstraction is not the same as leaving out whatever you do not understand. If you remove something that does matter to the purpose, the model gives confident wrong answers, which is worse than no model at all. A flight model that ignores wind, or a bank model that ignores overdrafts, is broken. Choosing correctly what is essential is the skill the syllabus is asking for, and it is worth saying so in an answer about benefits.
- Abstraction: removing or hiding detail that is not needed for the purpose, so that only essential features are represented.
- Purpose: to reduce complexity, so that a problem is small enough to understand, solve and model.
- Abstract model: a representation of a system that includes only the details essential to the purpose of the model.
- Benefits: simpler and cheaper to build, easier to understand and test, fewer errors, easier to change, and safe to experiment with.
- Not the same as ignoring detail you do not understand - remove something essential and the model is invalid.
| System | Essential details kept | Detail abstracted away | Why |
|---|---|---|---|
| London Underground map | Stations, the order of stations on each line, interchanges between lines | True distances, true compass directions, the street layout above | The map is for planning a route, so only the connections between stations matter |
| Flight simulator | Mass, engine thrust, lift, control-surface response, instrument readings | Paintwork, passenger comfort, the real consequences of a crash | It exists to train the handling of the aircraft, safely and repeatedly |
| Bank account record | Account number, name, balance, overdraft limit | The customer's address history, the branch decor, the paper the form was on | Only the fields needed to process a transaction are stored |
Decomposition: splitting the problem into sub-problems
Decomposition is breaking a large problem down into smaller sub-problems, each of which can be solved separately, until each one is small enough to be written and tested on its own. The sub-problems are chosen by function - what each part has to do - so a school exam-results system splits into reading the marks in, checking that each mark is valid, working out each grade, producing the report and saving the results to a file.
Each sub-problem becomes a program module. In this syllabus a module means a procedure or a function: a named block of code that carries out one job and can be called whenever it is needed. A procedure performs a task and does not return a value - print a report, update a total, save a record. A function performs a task and returns a value to the point where it was called - work out a grade, calculate an average, decide whether a mark is a pass. Modules are given the data they need when they are called, and a function hands its result back to the point where it was called.
The benefits are the ones to write in an answer. Each module is small enough to understand, so one person can hold it in their head and check it. It can be tested in isolation with its own test data, so a wrong grade is traced to one function rather than hunted through the whole system. It can be written by a different member of a team, so work runs in parallel. It can be reused - the same validation procedure serves every input in the program. When something changes, only the module responsible for it changes, which is why a decomposed program is easier to maintain. And an error is contained: a fault in the report module cannot corrupt the marks already stored.
Decomposition is top-down. You start with the whole problem, list the main jobs it involves, then take each job and split it again, and again, until each piece is a single module you could code straight away. That last stage overlaps with stepwise refinement: decomposition decides which pieces the solution is made of, and refinement adds the detail inside each piece until it can be programmed. A strong answer mentions both and keeps the two words apart.
- Decomposition: breaking a problem down into sub-problems, each of which can be solved separately.
- Sub-problems are identified by function - what each part has to do - and each becomes a program module.
- Procedure: a named block of code that performs a task and returns no value.
- Function: a named block of code that performs a task and returns a value.
- Benefits: smaller pieces are easier to understand, test, reuse and maintain; work can be shared across a team; faults are isolated to one module.
Identifiers and the identifier table
An identifier is the name a programmer gives to a piece of data or to a module - a variable, a constant, an array, a procedure or a function. The name is for the human reading the program, not for the computer, so it should say what the data is. TotalScore is suitable; x and ts1 are not, because six months later nobody, including you, can remember what they hold. Suitable identifiers are meaningful, consistent in style, and unique within their scope.
The practical rules are worth stating plainly. Use a name that describes the contents, such as NumberOfStudents rather than N. Use one convention throughout - capitalising each word, or separating words with an underscore - and never mix the two. Do not use spaces, punctuation or a name that starts with a digit. Do not use a reserved word such as IF, THEN, FOR or OUTPUT, because the language will refuse it. Avoid misleading abbreviations (Weight and Wait are too easy to confuse) and avoid a name so long that it hides the logic. A constant should look different from a variable, usually by being in capitals, so a reader can see at a glance that it does not change.
An identifier table is the design document that goes with the algorithm. It lists every identifier the solution will use, what it holds and what data type it is. It is drawn before the pseudocode is written, and it does two jobs: it forces you to decide the data types early, and it stops the same idea being given two different names in two different modules. In an exam it also earns marks on its own, so never answer a pseudocode question without one when the question invites it.
A complete identifier table has one row per identifier and three columns: the identifier, a description of what it represents, and its data type, chosen from INTEGER, REAL, CHAR, STRING, BOOLEAN or DATE. Choose the type that fits the values the data can actually take: a count of students is an INTEGER, a price is a REAL because it has pence, a name is a STRING, and a yes/no flag is a BOOLEAN. Getting the type wrong is not cosmetic - it decides whether a calculation rounds or truncates, and whether a comparison behaves as you expect.
| Identifier | Description | Data type |
|---|---|---|
| StudentName | The name of one student, entered by the user | STRING |
| Mark | The mark scored by one student, out of 100 | INTEGER |
| TotalMark | The running total of all the marks entered | INTEGER |
| AverageMark | The mean mark, total divided by the number of students | REAL |
| PassCount | How many students scored 40 or more | INTEGER |
| IsPass | TRUE if the current student's mark is 40 or more | BOOLEAN |
The three constructs: sequence, selection and iteration
Every algorithm, however large, is built from three basic constructs. Sequence is steps carried out one after another in the order written. Selection is a choice between alternatives, taken because a condition is either true or false. Iteration (repetition) is carrying out a group of steps more than once. If you can write these three and combine them, you can write any algorithm in this course - there is nothing else.
Sequence needs no keywords, only discipline: the statements run top to bottom, so the order matters. Reading a value into Total before setting Total to zero wipes the value you just read, and no compiler will warn you. Selection is written with IF ... THEN ... ELSE ... ENDIF. The condition is a logic statement that evaluates to TRUE or FALSE; if it is true the statements after THEN run, otherwise the statements after ELSE run, and the ENDIF marks where the two paths join again. Nested IFs handle more than two cases, and CASE OF ... OTHERWISE ... ENDCASE is the tidier form when one value has several possible matches.
Iteration comes in two families, and the exam expects you to choose correctly. Count-controlled iteration is FOR ... TO ... NEXT, used when the number of repetitions is known before the loop starts - process 20 students, print 12 months. Condition-controlled iteration repeats until some condition changes, and there are two forms that students constantly confuse. WHILE ... DO ... ENDWHILE tests the condition at the start, so if the condition is false first time the loop body never runs at all. REPEAT ... UNTIL tests the condition at the end, so the body always runs at least once. Use WHILE when there might be nothing to process, and REPEAT when you must ask at least once, such as a menu or a password prompt.
One rule catches more marks than any other: something inside the loop must change the value being tested, or the loop never ends. A WHILE Count < 10 DO loop whose body never adds 1 to Count is an infinite loop, and an answer containing one is a wrong algorithm however neat it looks. That is an algorithm design error, not a typing error, and it is the single most common fault in candidate pseudocode.
- Sequence: statements executed one after another, in the order written.
- Selection: IF ... THEN ... ELSE ... ENDIF, or CASE OF ... OTHERWISE ... ENDCASE where one value has several cases.
- Count-controlled iteration: FOR Index <- 1 TO 10 ... NEXT, when the number of repetitions is known.
- Condition-controlled, test at start: WHILE ... DO ... ENDWHILE - may run zero times.
- Condition-controlled, test at end: REPEAT ... UNTIL - always runs at least once.
- Every loop must change the value it tests, or it never terminates.
| Construct | What it does | Keywords | Use it when |
|---|---|---|---|
| Sequence | Runs statements one after another in order | none - just the order of the statements | Always, as the default structure of the algorithm |
| Selection | Chooses between alternatives on a true/false condition | IF, THEN, ELSE, ENDIF; CASE OF, OTHERWISE, ENDCASE | One of two or more paths must be followed |
| Iteration - count-controlled | Repeats a fixed number of times | FOR, TO, NEXT | The number of repetitions is known before the loop starts |
| Iteration - condition-controlled, test at start | Repeats while a condition is true; may repeat zero times | WHILE, DO, ENDWHILE | There may be nothing to process, e.g. while there are records left to read |
| Iteration - condition-controlled, test at end | Repeats until a condition becomes true; always repeats at least once | REPEAT, UNTIL | The body must run at least once, e.g. a menu or a password prompt |
Documenting an algorithm: structured English, flowcharts and pseudocode
An algorithm has to be written down so that other people can read it, check it and code it. The syllabus gives three ways of documenting one: a structured English description, a flowchart, or pseudocode. They are three views of the same logic, and a question may ask you to produce any one of them from any other.
A structured English description is a numbered list of steps in ordinary English, using the words of the three constructs - INPUT, IF ... THEN ... ELSE, REPEAT ... UNTIL - without any programming syntax. It is the version a client or a manager can read and agree with, which is why it is used at the start of a project to check that the programmer has understood the requirement. It is less precise than pseudocode: English can be read two ways, which is exactly what pseudocode exists to prevent.
Pseudocode is a structured, language-independent notation with strict-ish rules. It has keywords for input, output, assignment, selection and iteration, and indentation shows which statements belong inside a loop or an IF. It is not a real language, so there is no compiler to complain about a missing semicolon, but it must still be unambiguous and it must still be complete: every identifier you use should appear in the identifier table, and every loop should be closed with its ENDWHILE, UNTIL or NEXT.
A flowchart is a diagram of the same logic, drawn with a small set of standard symbols and arrows. It shows the shape of the solution at a glance - where the branches split and where the loops go back - which is why it is the best tool for talking through a design with someone else.
| Symbol | Shape | What it represents |
|---|---|---|
| Terminator | Rounded oval or stadium | START and STOP - the beginning and end of the algorithm |
| Input / Output | Parallelogram | Data going in (INPUT, READ) or coming out (OUTPUT, WRITE, PRINT) |
| Process | Rectangle | A calculation, an assignment or any step that changes data |
| Decision | Diamond | A condition with two exits, labelled YES and NO (or TRUE and FALSE) |
| Subroutine | Rectangle with double vertical lines | A call to a separate procedure or function |
| Flow line | Arrow | The direction in which control passes to the next symbol |
| Connector | Small circle | A jump to another part of the chart, to avoid long crossing lines |
Converting between the three representations
Converting is mechanical once you know the mapping, and the mapping is one table. INPUT and OUTPUT become parallelograms. An assignment or a calculation becomes a rectangle. IF ... THEN ... ELSE becomes a diamond with YES and NO on its two exits. A WHILE or a REPEAT becomes a diamond whose NO or YES exit goes back up to an earlier point in the chart. START and STOP become terminators.
Work through a small example. A gym charges 5 pounds for a member or for anyone under 18, and 8 pounds for everyone else. As structured English: 1. INPUT Age. 2. INPUT IsMember. 3. IF Age < 18 OR IsMember = TRUE THEN Price <- 5 ELSE Price <- 8. 4. OUTPUT Price. The pseudocode below is the same solution written line by line, and note that the IF line ends with THEN, the two branches are indented, and ENDIF closes the structure.
The same logic as a flowchart reads: START terminator, then a parallelogram reading Age, then a parallelogram reading IsMember, then a diamond asking Age < 18 OR IsMember = TRUE; the YES exit leads to a rectangle setting Price to 5, the NO exit leads to a rectangle setting Price to 8, both rectangles join, then a parallelogram outputs Price, and a STOP terminator ends it. If you can narrate a chart like that, you can draw one from any description.
When converting, work in a fixed order and do not skip steps. First list the inputs, then the outputs, then the processing that turns one into the other. Identify every decision and give each one two labelled exits. Identify every repetition and make its arrow return to the right place - back to the condition, not to the first line of the algorithm. Finally trace two or three paths through your own answer, one that takes each branch, and check that every path reaches STOP. Most conversion marks are lost by missing an input, by putting a calculation in a diamond, or by leaving a branch that never terminates.
- INPUT / OUTPUT -> parallelogram; calculation or assignment -> rectangle; condition -> diamond with YES and NO; START / STOP -> terminator.
- A loop is a diamond with one arrow going back to an earlier symbol - the condition, not the first line.
- Work in order: inputs, then outputs, then processing, then decisions, then loops.
- Every path through the chart must reach STOP, and every diamond must have two labelled exits.
| Line | Pseudocode | What it does |
|---|---|---|
| 1 | INPUT Age | Reads the customer's age into the identifier Age |
| 2 | INPUT IsMember | Reads a Boolean TRUE or FALSE into IsMember |
| 3 | IF Age < 18 OR IsMember = TRUE THEN | Tests a compound logic statement; the OR means either part can make it true |
| 4 | Price <- 5 | The YES branch - a member or a young person pays 5 |
| 5 | ELSE | The NO branch - everyone else |
| 6 | Price <- 8 | Sets the full price |
| 7 | ENDIF | Marks the point where the two branches join again |
| 8 | OUTPUT Price | Produces the result |
Stepwise refinement
Stepwise refinement is the process of taking an algorithm expressed at a high level and breaking each step into more and more detail, one level at a time, until every step is a single instruction that can be programmed. The stopping point is defined by the syllabus phrase a level of detail from which the task may be programmed: you stop when a programmer could code each line without having to make any further design decisions.
The first level states the job in a few broad steps, some of which are far too vague to code. A step such as calculate the wages hides decisions - how many hours were worked, what the hourly rate is, whether overtime is paid, what happens at exactly 40 hours. Refinement replaces that one step with several, each simpler, and then refines again if any of those is still too vague.
For a wages program, level 1 is: input the hours worked, input the hourly rate, calculate the pay, output the pay. Level 2 refines calculate the pay into: if hours are 40 or fewer, pay is hours x rate; otherwise pay is 40 x rate plus the extra hours x rate x 1.5. Level 3 refines each of those into readable pseudocode, and now every line can be typed. Three levels, each one adding detail to the level above, without ever rewriting what was already decided.
Work top-down and keep the structure visible by indenting each level under the step it refines, and by numbering steps 1, 1.1, 1.2. That way the refinement can be checked level by level, and the structure of the finished algorithm is the structure you designed. The benefits to quote: each level is easy to check against the level above, the detail is added in manageable amounts, the sub-steps that emerge are natural candidates for modules, and a change at one level is confined to that part of the design. It also lets you stop and confirm the design with the person who asked for the program before the expensive detail is added.
- Stepwise refinement: adding detail to an algorithm one level at a time until each step can be programmed directly.
- Stopping point: the level of detail from which the task may be programmed - no design decisions left for the coder.
- Work top-down, indenting or numbering each level under the step it refines (1, 1.1, 1.2).
- Refined sub-steps are natural modules, so refinement and decomposition support each other.
- Benefits: each level can be checked against the one above, detail is added in manageable amounts, and changes stay local.
Logic statements in an algorithm
A logic statement is an expression that evaluates to TRUE or FALSE. It is what a decision or a loop condition is made of, so the correctness of the whole algorithm depends on them. A logic statement is built from a comparison of two values, and comparisons can be combined with AND, OR and NOT.
The comparison operators are = (equal to), <> (not equal to), <, >, <= and >=. Note that = compares and does not assign: assignment in pseudocode is <-, so Total <- Total + 1 changes Total while Total = 10 asks whether it is ten. Mixing the two up produces an algorithm that either never loops or loops forever, and it is a very common slip in exam answers.
The combining operators behave as you would expect, but their precedence matters. NOT is applied first, then AND, then OR, so IF A OR B AND C THEN is read as A OR (B AND C), not as (A OR B) AND C. Do not rely on the reader remembering that: put the brackets in. A compound condition with brackets is clearer, and clarity is what a mark scheme rewards.
Logic statements are used in three places. In selection, to choose a path: IF Mark >= 40 AND Attendance >= 80 THEN. In iteration, to decide whether to go round again: WHILE NOT Found AND Count <= 100 DO. And in flags, a Boolean variable that records that something has happened - Found <- TRUE - so that a later condition can test it without repeating the whole comparison. A flag plus a logic statement is how you search a list and stop as soon as the item is found.
- Comparison operators: =, <>, <, >, <=, >=. = compares; <- assigns.
- Combining operators: AND (true only if both sides are true), OR (true if either side is true), NOT (reverses the value).
- Precedence: NOT, then AND, then OR - put brackets in compound conditions so the meaning is unambiguous.
- Use logic statements in selection conditions, in loop conditions, and with Boolean flags that record whether something has been found.
| Operator | Meaning | Example | Evaluates to TRUE when |
|---|---|---|---|
| AND | Both conditions must be true | Age >= 18 AND HasTicket = TRUE | The person is 18 or over and holds a ticket |
| OR | Either condition may be true | Choice = 'Y' OR Choice = 'y' | The user typed Y in either case |
| NOT | Reverses the condition | WHILE NOT Found DO | Found is FALSE |
| <> | Not equal to | Answer <> 'Q' | The answer is anything other than Q |
| >= | Greater than or equal to | Mark >= 40 | The mark is 40 or more, so 40 counts as a pass |
Key terms you must be able to define
- Algorithm
- A solution to a problem expressed as a sequence of defined steps. The steps must be unambiguous, in a fixed order and finite, and the algorithm must produce the correct output for every valid input. It is language-independent: the program is the algorithm written in a programming language.
- Abstraction
- Removing or hiding the detail that is not needed for a particular purpose, so that only the essential features of a problem or system are represented. Its purpose is to reduce complexity so the problem becomes small enough to understand, solve or model, and it produces an abstract model that contains only the essential details - if a detail that matters is removed, the model gives wrong answers.
- Decomposition
- Breaking a large problem down into smaller sub-problems, identified by the function each one performs, until each can be solved, written and tested separately. Each sub-problem becomes a program module.
- Program module
- A named, self-contained block of code that carries out one task and can be called when needed - in this syllabus a procedure or a function. A procedure performs a task and returns no value; a function performs a task and returns a value to the point where it was called.
- Identifier
- The name a programmer gives to a piece of data or to a module - a variable, constant, array, procedure or function. A suitable identifier is meaningful, consistently styled, unique in its scope, contains no spaces, does not begin with a digit and is not a reserved word.
- Identifier table
- A design document listing every identifier used by a solution, with a description of what it represents and its data type (INTEGER, REAL, CHAR, STRING, BOOLEAN or DATE). It is produced before the pseudocode and prevents the same idea being given two names.
- Pseudocode
- A structured, language-independent notation for an algorithm, using keywords such as INPUT, OUTPUT, IF ... THEN ... ELSE ... ENDIF, WHILE ... ENDWHILE, REPEAT ... UNTIL and FOR ... NEXT, with indentation showing which statements belong inside a structure.
- Structured English
- A numbered description of an algorithm in ordinary English that uses the words of the three constructs (INPUT, IF ... THEN ... ELSE, REPEAT ... UNTIL) but no programming syntax. It is readable by a non-programmer, which makes it useful for agreeing requirements with a client.
- Flowchart
- A diagram of an algorithm using standard symbols joined by arrows: terminators for START and STOP, parallelograms for input and output, rectangles for processes, diamonds for decisions with labelled exits, and subroutine symbols for calls to a procedure or function.
- Sequence
- The construct in which statements are carried out one after another, in the order in which they are written. No keyword is needed, so the ordering of the statements is entirely the programmer's responsibility.
- Selection
- The construct in which one of two or more paths is chosen according to whether a condition is true or false, written as IF ... THEN ... ELSE ... ENDIF, as nested IF statements, or as CASE OF ... OTHERWISE ... ENDCASE.
- Iteration (repetition)
- The construct in which a group of statements is repeated. Iteration is count-controlled when the number of repetitions is known (FOR ... NEXT) and condition-controlled when it depends on a condition: WHILE ... DO ... ENDWHILE tests at the start and may run zero times, REPEAT ... UNTIL tests at the end and always runs at least once.
- Stepwise refinement
- The process of adding detail to an algorithm one level at a time, breaking each vague step into more specific steps, until every step is at a level of detail from which the task may be programmed.
- Logic statement
- An expression that evaluates to TRUE or FALSE, built from comparisons (=, <>, <, >, <=, >=) combined with AND, OR and NOT, and used as the condition of a selection or a loop. NOT is applied first, then AND, then OR.
Applied to real systems
9618 sets its questions inside systems you already use - a phone, a school network, a supermarket till, a website, a bank. These show how to apply the theory to a context you have not seen before, then you write your own.
The map printed on the Underground keeps the stations, the order of the stations along each line and the interchanges where lines meet, and it discards true distances, true compass directions and the street layout above the tunnels. It is an abstract model built for one purpose, planning a journey, so the only details included are the ones that change which route you take. Harry Beck's design is the standard example because the distortion is deliberate: straightening the lines and evening out the spacing makes the connections easier to read, not harder. If you were asked instead for the walking distance between two stations, the same map would be the wrong model, because the detail it removed is the detail that question needs.
A flight simulator models the aircraft with the details that affect how it flies - mass, engine thrust, lift, drag, the response of the control surfaces - and the instrument readings the pilot uses, and it leaves out paintwork, cabin trim and the consequences of a real crash. The model is essential-detail only, which is why it runs in real time on ordinary hardware and why a trainee can repeat the same emergency approach twenty times. It also shows the risk of abstraction done badly: a simulator that leaves out wind shear or icing will teach a pilot to handle an aircraft that does not exist, and the wrong answers it gives are more dangerous than no training at all.
The software inside a cash machine is not one program but several modules, each with one job: read the card, verify the PIN entered against the card, check the balance and the withdrawal limit, instruct the dispenser to deliver the notes, print the receipt, and write the transaction to the bank's records. Each module can be tested on its own - the dispenser can be exercised with test transactions without any customer present - and a fault in the receipt printer does not stop cash being withdrawn. The modules are also reused: the PIN verification routine serves every transaction, and the same balance-checking function is called by the machine's screen and by the bank's mobile app. This is decomposition doing exactly what the syllabus says it should: sub-problems identified by function, each becoming a module.
The requirement arrives as one sentence: charge customers for the time they park. That is not programmable, so it is refined. Level 1: input the entry time, input the exit time, calculate the charge, output the charge. Level 2 refines the calculation: work out the number of minutes parked, round up to whole hours, if the hours are 3 or fewer charge 2 pounds otherwise charge 2 pounds plus 1 pound for each extra hour. Level 3 refines each of those into pseudocode with the identifiers HoursParked and Charge, and now every line can be typed. Each level can be checked against the one above it, and the refined steps - working out the minutes, rounding up, applying the tariff - are the natural modules for the finished program.
A lift door closes only when several conditions are true at once, which makes it a clean example of a compound logic statement: close the door IF no obstruction is detected AND no call button is pressed AND the door-open time has elapsed. The same algorithm uses NOT and a flag elsewhere - while the door is not fully closed, the lift must not move - so WHILE NOT DoorClosed DO holds the motor. Change one operator and the behaviour changes completely: replacing AND with OR would close the door while someone was still stepping through it. That is why precedence and brackets matter, and why the logic statement, not the code, is where this kind of error belongs.
Flashcards
Click a card to flip it. Mark honestly — the tracker uses this.
Exam-style questions
7 questions, 26 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
Exam technique for this topic
- Learn three definitions in the syllabus's own words and use them at the start of any answer: an algorithm is a solution to a problem expressed as a sequence of defined steps; abstraction removes detail that is not needed for the purpose so that only essential features remain; decomposition breaks a problem into sub-problems that each become a program module. The rest of the answer then has something to build on.
- Before writing any pseudocode, produce the identifier table with names, descriptions and data types. Marks are given for suitable names and correct types, and having the table stops you inventing a second name for the same value halfway through the algorithm.
- In every pseudocode answer: initialise totals and counters before the loop, put the INPUT inside the loop, and make sure something inside the loop changes the value being tested. A loop that cannot end, or a total that is reset on every pass, is marked wrong however good the rest of the algorithm is.
- For a flowchart, the marks are for symbols and labels: a terminator at each end, parallelograms for input and output, rectangles for processes, a diamond for every decision with both exits labelled YES and NO, and arrows showing direction. Trace one path through each branch before you finish and check that every path reaches STOP.
- When converting between representations, work in a fixed order - inputs, then outputs, then processing, then decisions, then loops - and tick each input and output off against the source. When refining, show at least two levels and indent the sub-steps, because the marks are for the intermediate levels rather than the finished code.