What is an algorithm?

An algorithm is a set of highly specific and organised instructions to be followed in order to carry out a task. A few examples of some very simple algorithms would be a following a medical prescription, brushing your teeth, putting a load of washing on, etc.

Another type of algorithm would be a recipe, telling you how to prepare a dish, step by step.

Going back to the asparagus, We will need to follow some instructions in order to cook it:

  1. Put some oil in the frying pan.
  2. Put the pan on the stove.
  3. Wait for the oil to heat up.
  4. Add the asparagus to the frying pan.
  5. Cook until done.
  6. Turn off the stove and remove the pan.
  7. Place the asparagus on a serving plate.
receta

An easy way of representing an algorithm is by using a flow chart.

What is a flow chart?

Flow charts are diagrams used to give a clear and simple representation of a process, such as that of an algorithm. These are the basic elements that are represented in a flow chart:

The start and end of the process.
The process or action executed starting from some data, which could be input, output or the result of a previous process.
The input and output data.
A condition or question that could have various paths: yes/no, true/false, greater than/less than, equal to/different to, etc.
The direction of the processes.


Programming a countdown timer

A button must be created for each contestant on a television game show. So every time the host asks a question, the contestants have to press the button if they know the answer and a light will indicate who was the fastest. Once the button has been released, the light should switch off.

First of all, we need to think about our algorithm, so that we can then create our flow chart:

  1. Start the game.
  2. Check the state of the button.
  3. If pressed, switch on LED.
  4. If not pressed, switch off LED.
  5. Check the state of the button again.
diagrama2

TIP: Develop the flow chart for the proposed exercises before you start programming. Then you´ll see how much it easier it is to resolve them.

And there´s more

    Here´s a few more ideas so you can keep on practising:

  • Write a simple algorithm down on paper for an everyday activity (sending a letter, making a phone call, getting ready to go to work, etc.)
  • Then rewrite the same algorithm, but with maximum detail in the instructions to enable someone else to carry them out.

Every time you´re faced with a problem, ask yourself these two questions: What do I need to do? How can I do it? The algorithms and diagrams can be really useful for outlining the solution to a problem. So now you know this, make sure you always have pen and paper to hand!