What Does an Algorithm Look Like?

We know that Facebook, Google, and Amazon have algorithms that give us updates, search results, and product recommendations, but what does that actually mean? What qualifies as an algorithm? Can you write one down? What would it look like if you did? Since they run so many parts of our daily lives, it’s important to have a basic sense of what exactly is going on under the hood – and it’s really not as intimidating as it often seems.

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.

After walking out of your door, turn right.

Walk down the road until you come to Market Street

When you reach Market Street, turn right.

Walk straight until you see a brick building.

Go in the front door.

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]

Check each item in the list.

As soon as one of the items equals three, return its position.

If three is not in the list, return “Three is not in the list!”

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.

Google PageRank works by looking at the number and quality of links leading to and from a webpage, though there are a large number of secret criteria that are constantly being updated to improve results and prevent anyone from gaming the system.

Facebook’s News feed measures the strength of your relationship with people and groups based on your activity, then uses these and some other factors to generate your news feed.

Amazon and Netflix use recommendation algorithms that look at user data, figure out things that each user might want, and show the user those things.

UPS’s ORION system is a huge (1000+ pages!) algorithm, but it can calculate the most efficient route for any delivery while also taking into account all kinds of real-time data and operational parameters, like requested delivery windows.

Artificial intelligence applications like self-driving cars, facial recognition, natural language processing, predictive analytics, and many more rely on algorithms that can take in visual, audio, or digital data, figure out what’s going on, and return appropriate results.

Advertising algorithms are everywhere. While humans are the ones who come up with the ads you see, it’s an algorithm that ultimately decides if you’re the right audience.

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.