At the simplest level, an algorithm is a set of specific instructions or steps that can be taken to successfully complete a task and that can be repeated indefinitely.

When we talk about an algorithm in computational terms, we’re talking about the specific set of steps that are carried out to complete the computation.

Of course, the details of what make algorithms so important are a lot more complicated than this, but as a starting point, this introductory definition is a great place to start when thinking about algos (that’s the abbreviation for algorithms).

Algorithm Essentials – Complexity and Cocktail Parties

Think of almost any complex task and without fail, the simplest way to get it done is usually to break it down into a series of smaller, manageable steps.

This is essentially what an algorithm does.

An algorithm does its thing by carrying out all of the smaller component steps that are needed to complete the final complex task.

You can think of this a bit like any number of repetitive, multi-step, and otherwise complex routines that might need to be carried out in the real world – like spending the night making individual cocktails for guests at a party.

Each cocktail made requires a very specific set of steps that have to be followed in a specific order and using specific quantities of ingredients each time.

Not just this, but each type of cocktail requires a different set of variables to the others.

When someone orders a Margarita, the requirements are going to be very different to a Manhattan or a Moscow Mule. Each are different and each have specific steps which culminate in a complex (but delicious) end-product.

However what about if everybody that night orders Mojitos?

Well in this case, the same step by step preparation is required, but it needs to be repeated exactly the same each time the drink is made.

What we need, is an algorithm.

Now lets say we decide to build a robotic assistant that will flawlessly execute the production of our cocktails. In order to program our automated mixing maestro to create the perfect drink on command every time, we need to give it instructions on how to create each drink a guest orders so that it can repeat as often as necessary without fail.

We’ll need to produce a series of algorithms (one for each drink) that let the machine know the exact steps that need to be taken, in which order they need to be executed, and the ingredients and quantities required at each step along the way.

Here’s what the (overly simplified) non-code version of our algorithm might look like for making a Strawberry Daiquiri:

  1. Guest orders Strawberry Daiquiri
  2. Take 1 medium glass
  3. Add 1 strawberry to the base of the glass and muddle
  4. Add 3/4 ounce of lime juice to the glass
  5. Add 2 ounces of white rum to the glass
  6. Fill remainder of the glass with ice to the rim
  7. Add cocktail shaker to top of glass and hold both together
  8. Continue to hold shaker and glass together and simultaneously turn glass, emptying contents of the glass into shaker
  9. Continue to hold shaker and glass together and shake both vigorously
  10. Take a new, chilled glass from the refrigerator
  11. Place a strainer over chilled glass and empty the contents from the cocktail shaker into the strainer
  12. Serve drink to guest

With this set of instructions in place, our robo-mixologist should be ready to tackle this order and make the perfect drink whenever it’s requested.

Tags:

Once we program all of the other drinks into the machine in the same way – with individual algorithms for each – not only will we not need to tell the machine every single time a drink is requested (or worse yet, make it ourselves), but from that point on, the perfect replicable cocktail is just a button press or voice command away.

This is the power of algorithms and they form the backbone of computer programs which have to carry out thousands of complex and varied tasks again and again and again…and again.

Sometimes algorithms are put to work helping with the mundane repetitive tasks that we simply wouldn’t want to carry out on repeat day in and day out, and sometimes they’re put to work on less common tasks where having a programmed system find a better way of doing them is also incredibly beneficial.

July 8, 2019

RELATED POSTS