A recipe is a program for people
You follow steps to make a cup of tea. Boil the water. Put a tea bag in a cup. Pour the water. Wait. Take the bag out.
If you change the order, the tea goes wrong. A list of steps in the right order is an algorithm: a list of clear steps that solves a problem.
Key words
| Word | What it means | Example |
|---|---|---|
| Algorithm | A list of clear steps in order that solves a problem. | a recipe |
| Flowchart | A picture of an algorithm made of shapes and arrows. | start, check age, end |
| Terminator | The shape for Start and End. | a rounded box |
| Process | The shape for one thing to do. | add 1 to the score |
| Sub-process | The shape for a job that has its own flowchart. | check the password |
| Decision | The shape for a question with two answers. | is it raining? |
| Sequence | Steps one after another, in order. | wake up, wash, eat |
| Selection | Choosing a path by asking a question. | if it rains, take an umbrella |
| Iteration | Repeating steps. | knock until the door opens |
| Loop | Another name for iteration. | repeat until the door opens |
The cells students fill in are left blank in this preview.
Is it an algorithm?
Have a go
Is it an algorithm?
3 questionsWhat makes a good algorithm
| It is... | This means... | Example |
|---|---|---|
| Clear | Each step has only one meaning. | "Add 2" not "add a bit" |
| In order | The steps are in the right order. | Boil the water before you pour it |
| Finite | It ends after a fixed number of steps. | It does not run for ever |
| Has inputs and outputs | It takes in data and gives a result. | In: age. Out: ticket price |
| Correct | It solves the whole problem. | It works for a child and an adult |
The cells students fill in are left blank in this preview.
Why write an algorithm first?
A computer cannot guess. It does exactly what the steps say. Nothing more.
If you write the algorithm first, you find mistakes before you write code. You can also show the plan to other people.
The flowchart shapes
Match the shape to its job
Have a go
Loading…
Your answers are marked here and are not kept. A college account keeps every student’s marks.
Arrows show the order
Arrows show the order. Follow them from Start to End.
A decision has two arrows out. Each arrow has a label, such as yes or no. The circle with a letter is a connector. It joins two parts of a chart that are far from each other.
Read a flowchart: a bus pass
Your turn: draw a flowchart
A cinema checks if you can see a film. The film is for age 15 and over. Finish the flowchart. Use the right shape for each step.
- Add an input for the age.
- Add a decision: is the age 15 or more?
- Add an output for each answer: Welcome, or Sorry, too young.
flowchart TD
s([Start]) --> todo[Put your steps here]
todo --> e([End])
Make a free account to save your work, or press Start lab to work through the whole lesson.
Three ways to control the order
Every algorithm is built from three actions.
Sequence: do the steps one after another.
Selection: ask a question and choose a path.
Iteration: repeat steps until something is true.
Iteration: a loop in a flowchart
Sequence, selection or iteration?
Have a go
Sequence, selection or iteration?
4 questionsWatch: algorithms and flowcharts
Press Play on the short film below. It goes from the tea steps to the flowchart shapes, builds the bus pass flowchart and follows one input through it, then shows a loop. Watch where a question has to go, and why each of its arrows has a label.
Film: algorithms and flowcharts
Algorithms and flowcharts
Every scene, as text
- An algorithm is a list of clear steps in order that solves a problem. To make a cup of tea: boil the water, put a tea bag in a cup, pour the water, wait, then take the bag out.
- A flowchart is a picture of an algorithm made of shapes and arrows. A rounded box, the terminator, is Start or End. A slanted box is an input or output. A diamond is a decision, a question with two answers. A rectangle is a process, one thing to do.
- A bus pass, read by following the arrows from Start to End: input the pass type, then the decision, is it a student pass? Yes, the fare is 1 pound; no, the fare is 2 pounds. Output the fare, then End. Each arrow out of a decision has a label.
- Trace one input, a student pass. Start, and the input is student. Is it a student pass? Yes, so the fare is 1 pound and the output is 1 pound. End.
- Sequence, selection and iteration control the order. Iteration repeats steps until something is true: set count to 0; is count 3? No, so output Hello, add 1 to count and go back to the question. After three Hellos count is 3, so yes: End.
- Myth (false): a question goes in a rectangle. A rectangle is one thing to do, and its two arrows out say nothing. A question is a decision, so it goes in a diamond, and each arrow out has a label, yes or no.
Good and bad points of flowcharts
| Good points | Bad points |
|---|---|
| You can see the whole path quickly. | A big chart is slow to draw and hard to change. |
| Good for people who do not code. | Too many arrows become confusing. |
| Decisions and loops are clear. | It does not show the exact details a computer needs. |
| Mistakes in the logic are easy to spot. | Not every program fits on one page. |
The cells students fill in are left blank in this preview.
Key words crossword
Have a go
Loading…
Your answers are marked here and are not kept. A college account keeps every student’s marks.
Exit quiz
Have a go
Exit quiz
6 questionsRemember
Important
An algorithm is clear steps in order. A flowchart draws it with six shapes and arrows. Sequence, selection and iteration control the order.