Presentation is loading. Please wait.

Presentation is loading. Please wait.

Algorithms Today we will look at: what the word algorithm means

Similar presentations


Presentation on theme: "Algorithms Today we will look at: what the word algorithm means"— Presentation transcript:

1 Algorithms Today we will look at: what the word algorithm means
some example algorithms for simple tasks different ways of writing down algorithms why it’s useful to think about this!

2 What is an Algorithm? Algorithm is just the name we give to a step-by-step procedure for doing something – like a recipe or a set of instructions. It takes its name from Abū ʿAbdallāh Muḥammad ibn Mūsā al-Khwārizmī, a Persian mathematician who also gave use the words algorism (using place value) and algebra. But don’t panic – it’s easier than algebra! In fact, an algorithm is just words.

3 Algorithm Example We can create an algorithm for anything. The algorithm for making a cup of tea, for example, might look like this: Fill kettle with water Switch on kettle Put tea in teapot Wait If kettle has boiled pour water into teapot, else go back to step 4 Put milk in cup Pour tea into cup All you need to do is follow the steps in order. Notice that step 5 involves making a decision.

4 Flowcharts Stop Start Has the kettle boiled? Pour the tea! Put the tea in the teapot Fill the kettle with water Wait Switch on the kettle Put milk in the cups Yes No Algorithms can also be described in the form of a diagram called a flowchart. Different stages have different shaped boxes: a rounded one for the beginning and end a square one for a simple instruction a parallelogram (slanted box) for input and output a diamond for a decision.   The flowchart for making a cup of tea would look like the one on the right:

5 Planning a Task There isn’t necessarily only one correct algorithm for a particular task... for example, it might not matter if you add the sugar or the milk first when you make the tea. Or you could put the tea in the teapot before you switch on the kettle – it wouldn’t really matter. But... some of the steps might need to be done before others... for example, your tea wouldn’t be very nice if you poured the water into the tea pot before you boiled it, and it probably wouldn’t be a good idea to switch on the kettle before you put the water in. For some tasks – e.g. sorting things - there might be some ways of doing them that is quicker (or more efficient)

6 Why Are We Doing This? Nearly everything you do requires an algorithm:
everyday tasks, such as cooking and cleaning mathematical calculations Internet searches sorting navigation (we have already looked at an algorithm for doing this) The main reason we are thinking about this, though, is because it helps us to... write a computer program

7 Computer Programming A computer program is a sequence of commands used to control the computer; to tell it what to do. For the program to run efficiently, it needs to be planned carefully. The Golden Rule of programming is "don't rush straight to the computer"; you need to first think about what you are going to do. The first stage in planning a computer program is to break job into small steps and write them out in plain English – i.e. we need an algorithm.

8 Planning a Program You need to decide on the steps that your program will perform before you start to create it You need to decide how the program will start and end, and also whether anything will need repeating: a fixed number of times until a particular event happens – e.g. until a key is pressed, or for a fixed amount of time while a particular variable has a particular value – e.g. keep asking for a password until a password has been entered forever – e.g. traffic lights Your program might need to make a decision

9 Example Imagine you were going to write the program to do the National Lottery “lucky dip” – what would it need to do? Pick a whole number from 1 – 49 Check that the number hasn’t been drawn already – if it has, then go back to step 1 Repeat steps 1 and 2 until six different numbers have been drawn Sort the numbers into order


Download ppt "Algorithms Today we will look at: what the word algorithm means"

Similar presentations


Ads by Google