What is an algorithm?

One of the early classes in computer science curriculum is “data structures and algorithms”. When you read computer science text books, you’ll see these words paired together. This makes the word sound more fancy and important than it should. An algorithm, while important, is not particularly fancy.

Algorithms, simply put, are how you go about doing something.

When paired with data structures, “algorithm” means how you do something using a particular data structure. One example of this is how do you put an item into a list? Well, that depends a bit on what the underlying data structure to the list is. Maybe you’re moving some pointers around. Maybe you’re doing a big shuffle of blocks of memory. The exact machinations of this are your “algorithm”.

This doesn’t need to be tied to specific data structures either. If you’re building a web app, you might have a user registration flow. A common flow generates an email with a link that validates they typed the correct email address. The recipe for generating this token and how you go about looking it up is your “algorithm”.

To cite another example, you might have heard of “algorithmic trading”. This is a way to automate buying and selling stocks on the stock market. You would qualify to be an “algorithmic trader” if you wrote a computer program to buy any time the stock price ended with a prime number. Your algorithm that answers “do I buy?” is a simple “Are the cents on this price prime?”. Nonsensical, sure, but a valid algorithm.

Algorithm is one of those “50 cent words” that doesn’t mean quite as much as you think it does, so there’s no need to be worried about it. There are algorithms everywhere and you’ve written some, as sure as you’ve written software.