Informal definition: algorithms are just recipes

At its most basic, an algorithm is simply a set of well-defined steps that you can follow, generally taking some inputs and producing a different set of outputs. A cupcake recipe can be an algorithm. So are the directions to a friend’s house, playing a piece of sheet music, or the process of looking up a word in a dictionary. Raymond Queneau even printed a book of ten sonnets with lines that can be mixed and matched seamlessly to create 100,000,000,000 original poems. How these algorithms are implemented varies widely, but you don’t need to be familiar with any programming languages to understand the basic logic behind them. For example, the following is an algorithm for giving simple walking directions.

That’s a very simple algorithm that uses a lot of inputs that humans can easily process; we already know about walking, streets, materials, entering, and all those other things. If we were creating a directional algorithm for a robot, it would have to be a lot longer and more specific, which is what makes many algorithms look so confusing to humans.

More formally: algorithms are clear, unambiguous formulas

One algorithm you probably use every day is Google’s PageRank algorithm, which looks at hundreds of factors about a webpage, runs them through its formula, and assigns it a score. The search results you see in response to your search term are a direct result of that score. It works so well because it follows a clearly defined set of rules that tell it what to look for, what to ignore, and what to do with the information it finds. To visualize a very simple search process, here’s a linear search algorithm looking for the number 3 in a list of numbers. list = [1, 3, 5] Following these steps, the computer will look at the first number, which is one. Since it doesn’t equal three, it moves on and checks the next number. Since that number is three, it returns something like “The number three is the second item in the list.” In Python code, a linear sorting algorithm would look like the following image.

All that code is doing is taking a list of numbers, looking at each element in the list, and checking to see if it matches the search term. If nothing does, it just returns “False.” This is an extremely simple algorithm, but whether it’s one line of code or a million, every algorithm in existence operates on the same basic principle: take information, process it according to some preset logic, and get results.

Everyday algorithms

Most of the algorithms that actually run our everyday lives aren’t open source. We don’t know exactly how Google determines what search results to show or how Facebook puts your news feed together, but we can still see the results of those computations. Nonetheless, they are important, and we have a pretty good idea of the basic logic behind them.

Everything is an algorithm

Once you know what an algorithm looks like, you can’t stop noticing them. They’re not only in our technology, as, after all, they’re in our brains. Everything we do is a result of receiving inputs, processing them, and producing outputs. Most of these processes are stored inside a constantly rearranging black box, but they’re there, behind the scenes, helping us walk around, understand language, and make decisions about things. Humans are equipped to understand algorithms at an instinctual level, so even if computer algorithms are written in indecipherable mathematics and code, they can all be translated into terms we understand. Image credit: Mandelbrot set image, Websites interlinking to illustrate PageRank, CTP TheoryOfComputation Linear Search, Shell sorting algorithm color bars