What is an algorithm?
Using flowcharts to simplify problem solving
Aspire to be an independent learner. Click here to learn how.
Using flowcharts to simplify problem solving
Click the arrow to expand and follow the instructions below...
Draw a diagonal line.
Draw another diagonal line connected to the top of the first one.
Draw a straight line from the point where the diagonal lines meet.
Draw a horizontal line over the straight line.
At the bottom of the straight line, draw a curvy line.
Draw a diagonal line from the bottom of the first diagonal to the straight line.
Draw a diagonal line from the bottom of the second diagonal to the straight line.
Compare your picture with your friends. What should it have been?
It should have looked like this.. a kite.
Were the pictures different?
Why?
What was difficult about following the instructions?
What was missing from the instructions?
An algorithm is basically a set of 'steps' written in a logical order which will enable a solution to be found to a particular problem.
Algorithms are unique and are usually only written for a single purpose. For example, an algorithm let's say written to tell a robot where to drive to reach the exit of a maze cannot be used to win at chess. We would need a different algorithm for each problem, because they are unique.
A nice way of understanding how algorithms work is the 'intelligent piece of paper'. This will teach you a way of winning (or drawing) at tic-tac-toe (noughts and crosses) every time.
Working in pairs (on the same device), using the embedded Tic Tac Toe game below, player 1 (X's) carefully follows the algorithm, whilst player 2 (0's) plays their own way. Keep a tally of who wins each game.
The Big Bang Theory - Sheldon uses an algorithm in the form of a flowchart to explain friendship.
Click the arrow the reveal the algorithm.
I am X, and I go first.
Move 1: Go in a corner.
Move 2: IF the other player did not go there THEN go in the opposite corner to move 1. ELSE go in a free corner.
Move 3: IF there are 2 Xs and a space in a line THEN go in that space. ELSE IF there are 2 Os and a space in a line THEN go in that space. ELSE go in a free corner.
Move 4: IF there are 2 Xs and a space in a line THEN go in that space. ELSE IF there are 2 Os and a space in a line THEN go in that space. ELSE go in a free corner.
Move 5: Go in the free space.
It can be extremely difficult to follow complex sets of instructions. When designing an algorithm, to make it easier to visualise, flowcharts are used.
Let's consider a home gas-powered central heating system...
In a central heating system, hot water is circulated around the home in a complicated network of pipes into radiators.
In the boiler, gas is burned and water is circulated in pipes around it, heating it up. A water pump pushes it around.
Used hot water is returned (cooler) back to the boiler. This is done in a continuous loop.
The temperature in a central heating system is set and monitored by an electronic thermostat.
When the heat has reached the desired temperature, the thermostat stops calling for heat, the boiler stops burning gas. The pump continues to circulate water around the house.
When does the system know when to turn on and off? And how can we program this electronically?
Flowcharts are a very common way of designing algorithms. Let's have a go ourselves.
Let's consider the traffic lights at a pedestrian crossing...
Routine
A routine is is the set of instructions that form the main 'body' or part of an algorithm (or program).
Subroutine
A subroutine is a smaller, repeatable set of instructions that can be 'called' (referred to) within the main algorithm (or program). Subroutines are useful because they can be called as many times as needed but only need to be written once. This keeps things smaller, simpler and helps avoid mistakes.
Using your knowledge of flowcharts and the images below, create an algorithm for making a cup of tea.
Please fill out this worksheet to complete the homework task.
Extension task. Introduce sub-routines for sugar, and / or brew strength.
A 'perfect cup of tea' infographic. You could use this to help you with your decision making (but you don't have to).
Flowchart or Flow diagram
A flow diagram shows a series of symbols which visualise the algorithm in an easy to follow way.
Pseudocode
Pseudocode is a text-based, rough-out 'plan' of what an algorithm might look like in a programming language. It isn't a language in itself. It just resembles what it might look like in simple INPUT-PROCESS-OUTPUT terms.