You might already know that an algorithm is a series of steps that solve a problem, for example, how to get dressed in the morning. First you have to find where you keep your clothes, then pick out what to wear, then get dressed for the day.
Algorithms are a critical part of computing. They’re more defined than how to get dressed but they are similar:
- In computing, the steps in an algorithm are clearly defined and thus repeatable.
- Each operation within a step effectively solves the problem
- And the steps are finite. They don’t continue forever once the problem is solved.
Most programmers would add that a good algorithm also produces the same correct result every time it is used. And correct doesn’t mean precise: sometimes an estimated solution is good enough.
Programmers spend a lot of time creating and using algorithms as they code. Their experience with algorithms is more complicated than a simple definition.
For example, not all algorithms that solve a problem are equally good. Some algorithms work best for one kind of problem but not another. And algorithms use data structures which also have their good and bad points. Analyzing algorithms becomes an important skill to learn.
You might think the most obvious way to analyze algorithms is to compare how fast they run through their steps to solve a problem. However, computers have different configurations. What runs fast on one computer runs slow on another. Programming languages also affect speed: an algorithm coded in C will almost always run faster than when coded in Python. Because of these factors, comparing the run time of two different algorithms is not an effective way to analyze algorithms.
Instead, perhaps the simplest way to analyze algorithms is to compare the number of steps an algorithm takes to complete its tasks and solve a problem.
The number of steps is measured as an order of magnitude, or big O notation. The simplest is an algorithm with a fixed number of steps regardless of the number of inputs or the steps within the algorithm. For example, if you only say hello to the first person you meet every day, that’s a constant time order of magnitude because you only say hello one time each day.
There are more complicated examples of order of magnitude. If you want to learn more, definitely look up The Self-Taught Computer Scientist by Cory Althoff. His book describes computer science concepts programmers use in their work, including how to analyze algorithms.