Study Guide
Solving Problems with Algorithms
How a programmer turns a real problem into a working program: the four stages of the program development life cycle, keeping what matters and breaking the rest into parts, describing each part by its inputs, processes, outputs and storage, drawing a structure diagram, and stating what an algorithm is for.
Lesson 5.1 Algorithms and Programming
For: Complete beginners to programming: Key Stage 3 (about ages 11 to 14), or the start of a Cambridge IGCSE Computer Science course
Stage: Think
An app for the canteen
Elmfield School (a fictional school) wants an app that lets pupils order lunch before morning break, so that the kitchen knows how many of each meal to cook. The head of the canteen asks a programmer, Priya, to build it. Priya is about to start.
Think it through
Priya has a laptop open and is ready to type. What should she do first, before she writes any code, and why?
- Hint 1: Who will use the app? What do they need it to do?
- Hint 2: What might go wrong if she builds the wrong thing very well?
Show a model answer
She should find out exactly what the canteen needs: who will use the app, what pupils will order, what the kitchen needs to see, and how payment will work. If she starts coding first she may build something that works perfectly but is not what anyone needed, and have to start again.
Stage: Discover
Putting the jobs in order
Here are four jobs on the canteen project, listed in a jumbled order:
- Try the app with sample orders and check that the results are right.
- Write the program code.
- Find out exactly what the canteen needs.
- Plan, on paper, how the app will work.
Think it through
Put the four jobs in the order you would do them. Give one reason for the job you put first and one for the job you put last.
Work this out on paper or the board first. Nothing here is marked: compare yours with the model answer.
- Hint 1: Which job could not be done properly without the others already finished?
Show a model answer
A sensible order is: find out what the canteen needs; plan how the app will work; write the code; try the app with sample orders. The first job comes first because every other job depends on knowing what the app is for. Testing comes last because there has to be a finished program to test.
Programmers follow an order very like yours. The stages a program goes through, from idea to working program, are called the program development life cycle. It has four stages:
| Stage | What is done in it |
|---|---|
| Analysis | Work out exactly what the problem is and what the program must do (the requirements). Abstraction and decomposition, met below, are used here. |
| Design | Plan the solution before writing any code, using structure diagrams, flowcharts and pseudocode. |
| Coding | Write the program code, testing each part as it is written (this is called iterative testing). |
| Testing | Run the finished program with test data and check the results against the requirements. |
It is called a life cycle because the stages can be repeated: testing may show that something in the design was wrong, and the programmer goes back to fix it.
Check your understanding
Show the answer
Answer: B. Design, because she has not planned how the app will work before coding.
Design comes between analysis and coding. Skipping it often means code that has to be rewritten when the parts do not fit together.
Stage: Discover
Keeping what matters
In the analysis stage Priya lists everything she knows about the canteen.
Think it through
Which of these does the lunch-ordering app need to know about, and which can it ignore? (1) the meals on the menu; (2) the colour of the dining-hall walls; (3) the price of each meal; (4) the make of the kitchen’s fridges; (5) which meals contain nuts; (6) each pupil’s name or ID.
- Hint 1: For each detail, ask: would the app behave differently without it?
Show a model answer
The app needs 1, 3, 5 and 6: the menu, the prices, the allergy information and who is ordering. It can ignore 2 and 4: the wall colour and the make of the fridges do not change anything the app does.
Choosing what to keep and what to leave out is called abstraction. Priya keeps the details that matter to the problem and hides the rest, so that she can concentrate on what is important. A map does the same: a bus map shows the stops and routes and leaves out the shops and the shapes of the houses.
Check your understanding
Show the answer
Answer: C. Used abstraction, by leaving out a detail that does not matter.
Abstraction means keeping only the details that matter to the problem.
Stage: Discover
Breaking a problem into parts
Even with the unimportant details removed, the app is too big to build all at once.
Think it through
List the smaller jobs the app has to do, from the moment a pupil opens it to the moment the kitchen starts cooking.
- Hint 1: What does a pupil do first? What happens after they choose a meal?
Show a model answer
For example: the pupil logs in; the pupil sees the menu; the pupil chooses a meal; the pupil pays; the order is sent to the kitchen; the kitchen sees how many of each meal to cook. Your list may be split differently, and that is fine as long as each job is smaller than the whole app.
Breaking a problem down into smaller parts is called decomposition. Each part is a sub-system: a smaller system that does one job. A sub-system can often be broken down again. “Pay” could be made of checking the pupil has enough money, taking the payment and recording it. Every computer system is built like this, as sub-systems made of further sub-systems, until each part is small enough to solve on its own. Different people can then build different parts, and each part can be tested separately.
Do not confuse: Abstraction and decomposition
- What do I keep?Abstraction
- Decide which details matter and leave the others out.The app needs prices but not the colour of the walls.
- How do I split it up?Decomposition
- Break the problem into smaller parts, each easier to solve.The app is split into log in, choose meal, pay and tell the kitchen.
Both are used in the analysis stage. Abstraction makes the problem simpler; decomposition makes it smaller.
Apply it
Show the answer
Answer: C. Decomposition, because the problem has been broken into three smaller parts.
Breaking a problem into parts is decomposition.
Stage: Explain
Describing one part
Take one sub-system of the canteen app: Pay for the meal.
Think it through
For this one sub-system, write one example of each: something that goes in, something the program must work out, something that comes out, and something that must be remembered until tomorrow.
- Hint 1: What does the program need to be told before it can take payment?
- Hint 2: What would the pupil expect to see afterwards?
Show a model answer
For example: in, the meal chosen and the pupil’s ID; worked out, whether the pupil’s balance is at least the price, and the new balance; out, a message such as “Paid” or “Not enough credit”; remembered, the pupil’s new balance.
Any part of a problem can be described by four things:
- Inputs: the data that goes in.
- Processes: the work done on the data, such as calculating or comparing.
- Outputs: the results that come out, shown to the user or passed to another part.
- Storage: the data that is kept, so that it is still there later (for example, a balance saved until tomorrow).
- Say what the part must achieve. A pupil borrows a book and the library records it. This keeps the description focused on one job.
- Inputs. The pupil’s library card number and the book’s code. These are the facts the part cannot work out for itself.
- Processes. Check that the card is valid, check that the book is on the shelf and work out the date it is due back. These turn the inputs into a decision.
- Outputs. A message saying “Borrowed, due on the 14th” (or why not), and a receipt. These are what the pupil and librarian need to see.
- Storage. A record that this book is on loan to this pupil until that date. It must be stored, because it must still be known when the book is returned next week.
Working in this order means nothing is forgotten: inputs and outputs first fix the edges of the part, and the processes are whatever turns one into the other.
Check your understanding
Show the answer
Answer: D. Storage, because it is data kept for later.
Data that stays between uses is storage, however often it is read.
Stage: Apply
Sorting a late-fine system
A school library (fictional) has a sub-system that works out a fine when a book comes back late. Decide which of the four each item is.
| Item | Which of the four? |
|---|---|
| The pupil’s card number, typed in at the desk | |
| Working out the fine: days late multiplied by 10p | |
| The message “You owe 30p” | |
| The total unpaid fines for each pupil, kept until the next visit | |
| Today’s date, read from the computer’s clock |
- Ask of each item: does it go in, get done to data, come out, or stay for later?
Show the completed table
| Item | Which of the four? |
|---|---|
| The pupil’s card number, typed in at the desk | input |
| Working out the fine: days late multiplied by 10p | process |
| The message “You owe 30p” | output |
| The total unpaid fines for each pupil, kept until the next visit | storage |
| Today’s date, read from the computer’s clock | input |
Stage: Explain
Drawing the breakdown
Priya wants to show the breakdown to the canteen staff on one page.
Think it through
On paper, draw the lunch app as a tree: the whole app at the top, its four main parts below it, and the three parts of “Pay” below that. Use boxes and lines.
Work this out on paper or the board first. Nothing here is marked: compare yours with the model answer.
- Hint 1: Each line joins a part to the box directly above it, the thing it belongs to.
Show a model answer
The app is the single box at the top. Four boxes sit beneath it, joined to it by lines: Log in, Choose meal, Pay, Tell kitchen. Under Pay, three more boxes: Check balance, Take payment, Record payment.
A diagram like your tree is a structure diagram. It shows decomposition: the whole problem at the top, its parts below, and each line joining a part to the box it belongs to. Here is the same diagram written as indented text, so that it can be read by a screen reader and printed:
Lunch pre-order app
├── Log in
├── Choose meal
├── Pay
│ ├── Check balance
│ ├── Take payment
│ └── Record payment
└── Tell kitchenRead it from the top: the app has four parts, and one of them, Pay, has three parts of its own. A box with nothing beneath it is small enough to build directly.
Check your understanding
Show the answer
Answer: B. Take payment.
A box’s sub-systems are the boxes directly beneath it, joined to it.
Here is a second diagram, for the sports-day program, written as a table. Fill in the box that each one sits directly beneath.
| Box | Directly above it |
|---|---|
| Sports day results | none: this is the top box |
| Enter results | |
| Type in times | |
| Work out positions | |
| Show scoreboard | |
| Type in names |
Show the completed table
| Box | Directly above it |
|---|---|
| Sports day results | none: this is the top box |
| Enter results | Sports day results |
| Type in times | Enter results |
| Work out positions | Sports day results |
| Show scoreboard | Sports day results |
| Type in names | Enter results |
Stage: Predict
What is this algorithm for?
When the design is finished, each small part becomes an algorithm: a list of precise steps that solves a problem. You will learn to write algorithms in standard notation in the next lesson. For now, read this one in plain words (a fictional teacher uses it):
- Set a running total to 0.
- Repeat steps 3 and 4 five times.
- Ask for a test mark.
- Add the mark to the running total.
- Divide the running total by 5 and tell the user the answer.
Think it through
In one sentence, what is this algorithm for? Try to say it without listing the steps.
- Hint 1: Imagine the five marks are 4, 6, 8, 6 and 6. What does the user get told?
Show a model answer
It works out the average (mean) of five test marks. The answer says what the algorithm achieves, not how it does it.
The purpose of an algorithm is what it achieves, in a few words: “works out the average of five marks”. It is not a description of each step (“it asks for a mark, adds it, repeats, divides”). Describing the steps is a separate task, called describing the processes, and an exam question will say which one it wants. Read the command word: “state the purpose” wants the goal; “describe” wants the steps.
Check your understanding
Show the answer
Answer: C. To find the highest mark.
The way to find an algorithm’s purpose is to try it with a few values and see what it tells the user.
Apply it
Show the answer
Answer: A. It lists the steps of the algorithm; it does not say what the algorithm is for.
State the purpose as the goal; describe the steps only when asked to.
Stage: Apply
Coding and testing in practice
Priya has finished the design. She writes the whole of the 400-line app without running it once. When she tries it, nothing works.
Think it through
What would you advise her to do differently next time, and why would it have helped?
- Hint 1: If she had run the code after writing only the log-in part, what would she have known?
Show a model answer
She should write a small part, run it, and fix any problem before moving on. If the log-in part is tested alone and then the menu is added, a fault is almost certainly in the part just written, so it is quick to find. With 400 untested lines the fault could be anywhere.
Testing the code as it is written, a little at a time, is called iterative testing, and it belongs to the coding stage. The testing stage is separate and comes at the end: the finished program is run with test data (inputs chosen on purpose, with the correct results already worked out) and the results are compared with what the requirements said it should do.
Apply it
Show the answer
Answer: D. Testing, because the finished program is run with test data.
Running the finished program on prepared data and checking the results is the testing stage.
Stage: Consolidate
Show what you know
Think it through
A friend says: “I don’t need to plan, I just start typing code.” Explain to your friend why that is risky. Name at least two stages of the life cycle in your answer.
Show a model answer
A good answer names stages and what each prevents. For example: “Analysis finds out what the program must do, so you do not build the wrong thing. Design lets you break it into parts and plan them on paper, so the parts fit together. If you start with coding you may build something nobody needed or have to rewrite it, and you will have no test data to check it against.”
Apply it
Show the answer
Answer: A. Design, using a structure diagram to show the problem broken into parts.
Boxes joined to a whole, drawn before any code, show design using a structure diagram.
- The program development life cycle has four stages: analysis (what the program must do), design (a plan), coding (writing the code, testing as you go) and testing (the finished program, with test data).
- Abstraction keeps the details that matter and leaves the rest out. Decomposition breaks a problem into smaller parts, called sub-systems.
- Any part can be described by its inputs, processes, outputs and storage.
- A structure diagram shows the breakdown: the whole at the top, and each part beneath the box it belongs to.
- An algorithm is a list of precise steps that solves a problem. Its purpose is what it achieves, in a few words, not a list of its steps. Lesson 2 teaches the notation for writing algorithms.
Sources and scope
- What this lesson is. The first lesson of the Algorithms and Programming module, written for this site. It teaches the program development life cycle, sub-systems and decomposition into inputs, processes, outputs and storage, structure diagrams and the purpose of an algorithm, which are points 7.1, 7.2(a), 7.2(b) and 7.3 of Cambridge IGCSE Computer Science 0478 (2026 to 2028, version 6). Its curriculum links are provisional: they show where the lesson may help with a course and imply no review or endorsement by any examination board.
- Original material. Elmfield School, Priya, the lunch-ordering app, the school library, the sports-day program, the bus company and Sam are fictional and were written for this lesson, as were the diagrams and the small algorithms.
- Simplified on purpose. Real projects repeat the stages many times and add others (planning, maintenance). The lesson keeps the four stages the syllabus names. The structure diagram is shown as indented text so that it can be read without seeing a picture.
- Left to later lessons. Flowcharts and pseudocode (Lesson 2); totalling, counting, finding the largest and smallest, and averaging (Lesson 6); test data, validation and trace tables are not taught here.
Keeping only the details that matter to a problem and leaving out the rest, so that the problem is easier to think about.
A sequence of precise steps that solves a problem or completes a task.
Breaking a problem down into smaller parts that are easier to solve one at a time.
A diagram of an algorithm that uses standard shapes joined by arrows to show the steps and the order they happen in.
The stages a program goes through from idea to working program: analysis, design, coding and testing.
A precise but language-independent way of writing an algorithm, with set keywords such as IF, WHILE and OUTPUT, that is not tied to any one programming language.
A diagram that shows a problem or system broken into parts: the whole at the top, with its sub-systems in boxes below, joined by lines.
One part of a larger system. A sub-system can itself be made of further sub-systems.
A table used to follow an algorithm by hand, with a column for each variable and for the output and a row for each step, to record how the values change.
Your progress on this lesson
Saved in this browser only. It is not sent anywhere, does not follow you to another device, and is lost if you clear this site’s data.
This browser is not allowing the site to save progress, so it will be forgotten when you leave the page.