AS & A Level Computer Science · Area 1 · AS Level content

Computational thinking and algorithms

Before you write a line of code, a problem has to be turned into an algorithm: a solution expressed as a sequence of defined steps. This page covers abstraction and decomposition, the three constructs, identifier tables, how an algorithm is documented as structured English, a flowchart or pseudocode, and how stepwise refinement takes it to the level of detail a programmer can use. You lose marks here by describing sequence, selection and iteration without applying them to the question, by writing a loop that never ends, and by giving an identifier table that lists names but no data types.

Not started

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.
A definition question on 'algorithm' wants the phrase sequence of defined steps or sequence of unambiguous instructions. Writing 'a set of instructions' without saying they are in sequence and defined is the usual near miss.

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.
SystemEssential details keptDetail abstracted awayWhy
London Underground mapStations, the order of stations on each line, interchanges between linesTrue distances, true compass directions, the street layout aboveThe map is for planning a route, so only the connections between stations matter
Flight simulatorMass, engine thrust, lift, control-surface response, instrument readingsPaintwork, passenger comfort, the real consequences of a crashIt exists to train the handling of the aircraft, safely and repeatedly
Bank account recordAccount number, name, balance, overdraft limitThe customer's address history, the branch decor, the paper the form was onOnly the fields needed to process a transaction are stored
Never write that abstraction is 'making things simpler by removing information'. Say which information and why it is not needed - that is the difference between a definition and an explanation.

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.
If a question says 'explain how decomposition helps', every point needs a consequence. 'It breaks the problem up' scores nothing; 'each sub-problem can be tested on its own, so an error is traced to one module' scores.

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.

IdentifierDescriptionData type
StudentNameThe name of one student, entered by the userSTRING
MarkThe mark scored by one student, out of 100INTEGER
TotalMarkThe running total of all the marks enteredINTEGER
AverageMarkThe mean mark, total divided by the number of studentsREAL
PassCountHow many students scored 40 or moreINTEGER
IsPassTRUE if the current student's mark is 40 or moreBOOLEAN
An identifier table without data types is half a table. The marks are for the type column, and Mark guessed as STRING because it was typed in loses them.

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.
ConstructWhat it doesKeywordsUse it when
SequenceRuns statements one after another in ordernone - just the order of the statementsAlways, as the default structure of the algorithm
SelectionChooses between alternatives on a true/false conditionIF, THEN, ELSE, ENDIF; CASE OF, OTHERWISE, ENDCASEOne of two or more paths must be followed
Iteration - count-controlledRepeats a fixed number of timesFOR, TO, NEXTThe number of repetitions is known before the loop starts
Iteration - condition-controlled, test at startRepeats while a condition is true; may repeat zero timesWHILE, DO, ENDWHILEThere may be nothing to process, e.g. while there are records left to read
Iteration - condition-controlled, test at endRepeats until a condition becomes true; always repeats at least onceREPEAT, UNTILThe body must run at least once, e.g. a menu or a password prompt
If the question says how many times, use FOR. If it says 'until' or 'while', use a condition-controlled loop - and label which one, because WHILE and REPEAT are not interchangeable.

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.

SymbolShapeWhat it represents
TerminatorRounded oval or stadiumSTART and STOP - the beginning and end of the algorithm
Input / OutputParallelogramData going in (INPUT, READ) or coming out (OUTPUT, WRITE, PRINT)
ProcessRectangleA calculation, an assignment or any step that changes data
DecisionDiamondA condition with two exits, labelled YES and NO (or TRUE and FALSE)
SubroutineRectangle with double vertical linesA call to a separate procedure or function
Flow lineArrowThe direction in which control passes to the next symbol
ConnectorSmall circleA jump to another part of the chart, to avoid long crossing lines
A decision diamond always has exactly two arrows leaving it, both labelled. An unlabelled branch is the commonest lost mark in a flowchart question, and it is free to fix.

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.
LinePseudocodeWhat it does
1INPUT AgeReads the customer's age into the identifier Age
2INPUT IsMemberReads a Boolean TRUE or FALSE into IsMember
3IF Age < 18 OR IsMember = TRUE THENTests a compound logic statement; the OR means either part can make it true
4 Price <- 5The YES branch - a member or a young person pays 5
5ELSEThe NO branch - everyone else
6 Price <- 8Sets the full price
7ENDIFMarks the point where the two branches join again
8OUTPUT PriceProduces the result
In a conversion question, count the inputs and the outputs in the source and tick each one off in your answer. Missing an input is the most frequent single-mark loss in this topic.

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.
A refinement answer that jumps straight to finished code earns little. The marks are for showing the intermediate levels, because that is what the word stepwise means.

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.
OperatorMeaningExampleEvaluates to TRUE when
ANDBoth conditions must be trueAge >= 18 AND HasTicket = TRUEThe person is 18 or over and holds a ticket
OREither condition may be trueChoice = 'Y' OR Choice = 'y'The user typed Y in either case
NOTReverses the conditionWHILE NOT Found DOFound is FALSE
<>Not equal toAnswer <> 'Q'The answer is anything other than Q
>=Greater than or equal toMark >= 40The mark is 40 or more, so 40 counts as a pass
>= and > are not interchangeable. 'A pass is 40 or more' is Mark >= 40; using > fails every candidate who scored exactly 40, and the mark scheme tests the boundary.

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.

Abstraction: the London Underground map

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.

Abstraction: a flight simulator

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.

Decomposition: the software in a cash machine (ATM)

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.

Stepwise refinement: charging for a car park

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.

Logic statements: controlling a lift door

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.

Q1Define an algorithm, and name the three parts every algorithm has.
A solution to a problem expressed as a sequence of defined steps - each step unambiguous, in a fixed order, and the sequence finite, producing the correct output for every valid input. Every algorithm takes input, performs processing on it, and produces output. The algorithm is the language-independent logic; a program is that algorithm written in a programming language.
Q2What is abstraction, and what is its purpose?
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 that the problem becomes small enough to understand, solve or model, and so that the model can be applied generally rather than to one specific case.
Q3What is an abstract model, and what are the benefits of producing one?
A representation of a system that includes only the details essential to the purpose of the model, such as a tube map that keeps stations and interchanges but discards true distances. Benefits: simpler and cheaper to build, easier to understand, check and test, fewer errors, easier to change, and safe to experiment with. The risk is removing something essential, which makes the model invalid.
Q4What is decomposition, and what does each sub-problem become?
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 - a procedure or a function - which can be given data through parameters and can return a result.
Q5What is the difference between a procedure and a function?
Both are named modules that carry out one task and are called when needed. A procedure performs a task and returns no 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 (calculate a grade, work out an average).
Q6Give four benefits of decomposing a problem.
Each module is small enough to understand and check; each can be tested in isolation with its own test data, so faults are traced to one place; different modules can be written by different programmers in parallel and reused elsewhere; and a change affects only the module responsible, which makes the program easier to maintain.
Q7What makes an identifier suitable, and what does an identifier table contain?
A suitable identifier is meaningful (TotalScore, not x), consistently styled, unique in its scope, contains no spaces or punctuation, does not begin with a digit, and is not a reserved word. An identifier table lists every identifier with a description of what it represents and its data type - INTEGER, REAL, CHAR, STRING, BOOLEAN or DATE - and is drawn before the pseudocode.
Q8Name the three basic constructs, with the keywords used for each.
Sequence - statements in order, no keyword. Selection - IF ... THEN ... ELSE ... ENDIF, or CASE OF ... OTHERWISE ... ENDCASE. Iteration - FOR ... NEXT (count-controlled), WHILE ... DO ... ENDWHILE and REPEAT ... UNTIL (condition-controlled).
Q9What is the difference between FOR, WHILE and REPEAT loops?
FOR ... NEXT is count-controlled and runs a known number of times. WHILE ... DO ... ENDWHILE tests its condition at the start, so it may run zero times. REPEAT ... UNTIL tests at the end, so it always runs at least once. Every loop must change the value it tests, or it never terminates.
Q10Name the flowchart symbols and the rule every decision must follow.
Terminator (rounded) for START and STOP; parallelogram for input and output; rectangle for a process; diamond for a decision; rectangle with double vertical lines for a subroutine call; arrows for flow direction; circles as connectors. Every decision diamond has exactly two exits, both labelled YES and NO, and every path must reach STOP.
Q11What is stepwise refinement, and when does it stop?
Adding detail to an algorithm one level at a time, breaking each vague step into more specific steps, working top-down and indenting or numbering each level under the step it refines. It stops at the level of detail from which the task may be programmed - when no design decision is left for the programmer to make.
Q12How are logic statements built, and in what order are the operators applied?
From comparisons - =, <>, <, >, <=, >= - combined with AND (both true), OR (either true) and NOT (reverses). Precedence is NOT, then AND, then OR, so brackets should be used to make compound conditions unambiguous. Logic statements form the conditions of selections and loops, and are also used with Boolean flags that record whether something has been found.
0 of 12 marked as known

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.

StateAO11 mark
State what is meant by an algorithm.

Mark scheme — tick each point you actually made

Examiner tip: One mark, one sentence. The two words that earn it are 'solution' and 'sequence of defined steps' - a list of instructions with no reference to a sequence of defined steps is not enough.
DefineAO12 marks
Define the terms abstraction and decomposition.

Mark scheme — tick each point you actually made

Examiner tip: Keep the two definitions distinct. Abstraction is about detail and what is essential; decomposition is about splitting the problem up. If both definitions describe splitting, only one mark is available.
ExplainAO23 marks
A large software project is being written by a team of four programmers. Explain how decomposition helps the team.

Mark scheme — tick each point you actually made

Examiner tip: Each point must name a benefit and say why it follows. 'It makes it easier' scores nothing; 'it can be tested on its own, so the fault is traced to one module' scores.
ExplainAO24 marks
Explain how sequence, selection and iteration are each used when writing an algorithm, giving an example of the keyword used for each.

Mark scheme — tick each point you actually made

Examiner tip: Name the construct, say what it does and give the keyword - all three are needed for each mark. Lumping WHILE and REPEAT together as 'loops' loses the fourth mark, which is specifically about the difference between them.
WriteAO35 marks
A program is required to input the marks of 20 students, each out of 100. It must output the number of students who passed (a mark of 40 or more) and the average mark. Write pseudocode for this algorithm.

Mark scheme — tick each point you actually made

Examiner tip: Initialisation before the loop, INPUT inside it, and the average output once after it - those three positions are where the marks sit. Writing the OUTPUT inside the loop, or using > 40 instead of >= 40, costs a mark even if the rest is perfect.
DrawAO35 marks
Draw a flowchart for the following structured English description. 1. INPUT Number. 2. IF Number < 0 THEN OUTPUT 'negative' ELSE IF Number = 0 THEN OUTPUT 'zero' ELSE OUTPUT 'positive'. 3. STOP.

Mark scheme — tick each point you actually made

Examiner tip: Draw the two decisions as two separate diamonds on the same branch - do not try to put both tests in one diamond. Label every exit and check that each of the three outputs is reached by exactly one of the three routes.
DiscussAO26 marks
Discuss the benefits of using abstraction and stepwise refinement when producing a solution to a large problem.

Mark scheme — tick each point you actually made

Examiner tip: Take the two techniques in turn and say what each achieves for a large problem, then link them together in the last point. A discussion that describes both without saying what benefit follows from each stays in the middle band.

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.

Why students lose marks here

A student wroteA student wrote: 'An algorithm is a program written in a programming language that a computer can run, and abstraction is when you make a program shorter.'
Why it loses marksBoth definitions describe the wrong thing. An algorithm is not tied to a programming language at all - the program is one possible implementation of it. And abstraction is not shortening: it is choosing which details are essential to the purpose and removing the rest, which may leave the model no shorter in code but very different in what it represents.
The answer that scoresAn algorithm is a solution to a problem expressed as a sequence of defined steps - defined meaning that each step has only one meaning and the order is fixed, so that anyone following it gets the same result. It is language-independent: the same algorithm can be implemented in several programming languages, and the program is that implementation, written with the syntax of one language so that a computer can execute it. 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. Its purpose is to reduce complexity so the problem is small enough to understand, solve or model, and it produces an abstract model containing only essential details - such as a tube map that keeps stations and interchanges but discards true distances because the map exists for route planning.
A student wroteA student wrote: 'Decomposition means writing the whole program first and then splitting it into procedures at the end, which makes it easier to test.'
Why it loses marksThat is refactoring after the event, not decomposition, and it gets the direction of the process wrong. Decomposition is a design activity carried out before any code is written: the problem is broken into sub-problems by function, and each sub-problem then becomes a module that is written and tested separately.
The answer that scoresDecomposition is breaking a large problem down into smaller sub-problems, each of which can be solved separately, until each 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 results system splits into reading the marks in, validating them, calculating grades, producing the report and saving the results. Each sub-problem becomes a program module, either a procedure or a function. Because the split happens before coding, each module can be given to a different programmer, can be tested in isolation with its own test data, can be reused elsewhere in the program, and can be changed later without affecting the other modules, which is what makes a decomposed program easier to maintain.
A student wroteA student wrote this loop to read 10 marks: 'Count <- 0 / WHILE Count < 10 DO / INPUT Mark / Total <- Total + Mark / ENDWHILE'.
Why it loses marksNothing inside the loop ever changes Count, so the condition is still true after the tenth mark and the loop never ends. There is also no initialisation of Total, so the first addition is made to an undefined value. Both are algorithm design errors, and an algorithm that does not terminate is not an algorithm.
The answer that scoresInitialise the counter and the total before the loop, change the counter inside it, and close the loop properly: Count <- 0, Total <- 0, then WHILE Count < 10 DO, INPUT Mark, Total <- Total + Mark, Count <- Count + 1, ENDWHILE. Because the number of repetitions is known in advance, a count-controlled loop is the better choice and removes the risk entirely: FOR Count <- 1 TO 10, INPUT Mark, Total <- Total + Mark, NEXT. The average is then calculated after the loop, Average <- Total / 10, and output once, not inside the loop.
A student wroteA student wrote: 'Abstraction means leaving out as much as possible so the model is simple, and a simple model is always a better model.'
Why it loses marksSimplicity is not the objective on its own. The objective is to represent the features that matter to the purpose of the model; a model that leaves out something essential is not simpler, it is wrong, and it produces confident but incorrect answers. What counts as essential is decided by what the model is for.
The answer that scoresAbstraction removes the detail that is not needed for the purpose, so that only the essential features are represented, and what is essential is decided by the purpose of the model. A model of a car for a driving simulator must keep mass, engine power and grip because they change how it drives, and can discard paintwork and seat material because they do not. Remove something that does matter - wind resistance from the flight model, the overdraft limit from the bank record - and the model gives wrong answers, which is worse than no model. So the skill is not removing as much as possible; it is deciding correctly what is essential, and the benefit that follows is a model that is cheaper to build, easier to understand and test, easier to change, and safe to experiment with.
A student wroteA student was asked for an identifier table and produced: 'Mark, Total, Average, Count' with no data types, and used the name 'Total' for both the running total of marks and the total number of students.
Why it loses marksThe table has no data types, so it does not show the design decision the examiner is looking for, and one identifier is being used for two different quantities - which is exactly the confusion a good identifier table exists to prevent. 'Mark' is also too vague to show what it holds.
The answer that scoresA complete identifier table gives every identifier, a description and a data type, and every quantity has its own name: StudentMark (INTEGER - the mark for the current student, out of 100), MarkTotal (INTEGER - the running sum of all marks entered), StudentCount (INTEGER - how many students have been processed), AverageMark (REAL - MarkTotal divided by StudentCount), IsPass (BOOLEAN - TRUE when StudentMark is 40 or more). The names are meaningful and consistently styled, they are unique, and the data types are chosen to fit the values each one can take, with AverageMark as REAL because a mean need not be a whole number.