Demystifying algorithms
Charlie Kozey
Posted on April 21, 2022
Algorithms have an intimidating reputation for programmers and non-programmers alike. This post is meant to 1) provide a high-level overview of what an algorithm is (with a non-techy, hopefully easy-to-grasp example) and 2) briefly touch on what makes algorithms important.
In the simplest terms, algorithms are just a series of steps executed in a specific order. Algorithms can be run by computers, of course, but they can also be done by hand. An example of an algorithm that most people have had experience with from an early age is long division.
The long division algorithm looks something like this (Follow along with a pencil and paper if you'd like! Or, even better, hide this tab and try to write out the steps yourself. It can be a useful exercise to articulate the steps of a process that has become automatic for you, because that's what you'll have to do when translating steps into code.):
Set up the dividend (the number being divided) and divisor (the number that is divided by) in the bracket: dividend inside and divisor on the left. Example: 42 on the left, 1000 inside bracket.
Examine the dividend one digit at a time, starting from the left, and check to see if the divisor can fit into that number at least once. (Let's call that number the fragment). If not, expand the fragment by one digit to the right and check again. 1 = too small. 10 = too small. 100 = big enough.
Once you reach a fragment that can be divided by the divisor, put the quotient (the nearest whole number) on top of the bracket above the fragment's final digit. 100/42 = 2
Multiply the quotient by the divisor, and place the result directly underneath the fragment, lining up the corresponding place-value columns. 42 * 2 = 84
Subtract the result from the fragment. 100 - 84 = 16
Repeat steps 2-5 with the result found in step 5. If the result of step 5 is too small, bring the next digit of the dividend down and append it to the result of step 5. If at any point you run out of digits in the dividend, add a decimal point and as many zeros as necessary to the dividend. Also add a decimal point in the quotient in the same position. 16 = too small. 160 = big enough. 160/42 = 3. 3 * 42 = 126. 160 - 126 = 34. 34 = too small. 340 = big enough. 340/ 42 = 8
Stop when you reach a number that is evenly divided into your divisor, when you reach a repeating decimal, or when you have enough decimal places for your precision needs. 23.8 is precise enough for me.
At a fundamental level, any algorithm you can think of—search algorithms, recommendation algorithms, routing algorithms (and the list goes on...)—works exactly in this step-by-step manner. On a practical level, technical interviews for coding jobs often emphasize algorithms. It's an important skill to have if you want a job. Like most things, working with algorithms is a skill that you can improve with practice. There are many free resources online for this purpose.
And on a societal level, it's important to think critically about algorithms and their real impact on people's lives. Like a lot of terms in, for example, finance, there’s a hand-wavey mystique about the word "algorithm." This mystique helps to maintain a status quo where insiders have a monopoly on knowledge and power. Moreover, because algorithms are iterative, their results are compounding. Small tweaks in their initial state can produce big changes in the output. Finally, an important implication of point 2 is that whatever biases are coded in by the programmers at the outset—however minor or unintentional—can have a huge impact on the final result (see, for example, racial biases in facial recognition algorithms). Algorithms are not a source of truth, which is especially important to remember since many people believe that if "a computer calculated it," it must be objectively true.
Posted on April 21, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.