Algorithm Basics for Everyone
Introduction to Algorithms
What is an Algorithm?
Think of an algorithm as a recipe. A recipe gives you a finite list of steps to follow to cook a dish. You start with ingredients (the input), follow the instructions, and end up with a meal (the output). If the recipe is good, you get a tasty dish every time. If it's bad, you might burn your food.
An algorithm is just like that, but for solving a problem or completing a task. It's a clear, step-by-step procedure for getting from a starting point to an end goal.
Algorithm
noun
A process or set of rules to be followed in calculations or other problem-solving operations, especially by a computer.
You use algorithms all the time, even if you don't realize it. The steps you take to get ready for work in the morning? That's an algorithm. The way you solve a Rubik's Cube? An algorithm. The instructions for building a piece of furniture? Also an algorithm.
They provide a blueprint for achieving a specific outcome in a predictable way.
Algorithms and Computers
Computers are powerful, but they aren't smart. They can't think for themselves or figure things out on their own. A computer needs to be told exactly what to do, and that's where algorithms come in. Every piece of software, from your web browser to your favorite game, is built on algorithms.
These instructions tell the computer how to handle data, make calculations, and execute tasks. An algorithm written for a computer must be precise and unambiguous. There's no room for guessing.
Algorithms are the logic behind the code. They are the brains of the operation, while the code is just the language used to communicate the instructions.
For example, let's say we want a computer to find the largest number in a list of numbers: [12, 4, 37, 21, 8]. The algorithm might look like this:
- Create a variable called
largest_so_farand set it to the first number in the list (12). - Go through the rest of the numbers in the list, one by one.
- For each number, compare it to
largest_so_far. - If the current number is bigger, update
largest_so_farto be this new number. - After checking all the numbers,
largest_so_farwill hold the biggest number in the entire list.
This is a simple but complete algorithm. It takes an input (a list of numbers) and produces a predictable output (the largest number).
Why Bother with Algorithms?
It’s not enough to just have an algorithm; we often need an efficient one. Imagine looking for a friend's phone number. You could start at the beginning of your contacts and scroll through every single name until you find them. That's one algorithm. Or, you could use the search bar and type the first few letters of their name. That's a different, much faster algorithm.
Both methods get the job done, but one is clearly better. In computer science, choosing the right algorithm can be the difference between a program that runs in a fraction of a second and one that takes hours, or even years.
Understanding how to think in terms of algorithms is fundamental to computer science and problem-solving in general. It allows us to break down complex challenges into smaller, manageable steps and develop clear, effective, and efficient solutions. This skill is valuable far beyond just writing code.
Time to check what you've learned.
Which of the following provides the best analogy for an algorithm?
Why are algorithms so crucial for computers?
Now that you understand what algorithms are, you can start to see them everywhere.

