Algorithms

Posted by admin at April 16, 2020

Computers are particularly useful because they perform repeatable tasks in a predictable way (even when you’re frustrated with your computer for not doing what you want). When you open a word processor or play a computer game, the computer operates against a set of commands or instructions that a team of programmers wrote and those instructions tell the computer what to do and when it needs to do them. These instructions always do the same thing and, when the program is written well, it does them consistently and without errors.

Algorithms in Real Life

These instructions are called “algorithms”. Author Yuval Noah Harari defines an algorithm this way: “An algorithm is a methodical set of steps that can be used to make calculations, resolve problems and reach decisions. An algorithm isn’t a particular calculation, but the method followed when making the calculation.” Some have referred to an algorithm as a recipe. But put simply, an algorithm is a repeatable set of steps that can take inputs and that produce a predictable, consistent output.

There are many popular metaphors that educators have used to illustrate algorithms and one of my favorites is the steps used when making a peanut butter and jelly sandwich. We can describes the steps–the algorithm–for making this sandwich this way:

Step 1: set out the ingredients: peanut butter, jelly, bread, and a spreader

Step 2: open the jars of peanut butter and jelly

Step 3: Set out two pieces of bread on a flat surface

Step 4: Spread a thin amount of peanut butter on one slice of bread

Step 5: Spread a thin amount of jelly on the other slice of bread

Step 6: Place one slice of bread on top of the other

Step 7: Enjoy!

Notice that this is a very rudimentary description. We can get much more specific on each of the steps. For example, we could specify exactly how much peanut butter and jelly to spread in steps 4 and 5. In step 6, we didn’t specify that the bread should be placed on top of each other with the peanut butter and jelly sides of the bread facing each other (not doing this would result in a very messy sandwich). But the point is, we’ve described a process for making the sandwich and the process is repeatable and always results in the same output: a sandwich.

Of course, because this is a very imprecise set of instructions, each sandwich will turn out a little bit different. Still, at a very high level, we end up with essentially the same results. Computers follow similar instructions but computer systems are very precise and the instructions they follow generally result in output that is much more consistent.

Algorithms and Computer Science

When programmers write computer programs, they essentially are writing recipes just like this to tell the computer what to do. Programs are written in sets of routines that specify what the computer should do in various circumstances. For example, you could write a computer program that adds two numbers together. The computer user might specify the numbers he or she wants to add, and your algorithm will do the addition operation and output the result. You would write your program in a specific language like JavaScript or C# (pronounced C-sharp) and that language–which makes it easy for humans to use–is compiled to the bits and bytes so the computer can understand it. But it’s still an algorithm at the end of the day.

Algorithms and Logic

We’re now getting closer to understanding the relationship between computer science and logic. Logic follows this algorithmic model by describing a consistent way in which ideas should relate to one another. It provides a set of recipes we can use to organize thought.


Comments

Write a Reply or Comment

Your email address will not be published. Required fields are marked *