ELI5: What is an algorithm and how is it related to programming?

An algorithm is a single, specific way of performing a complex task efficiently and repeatedly. The algorithm works by performing all of the smaller steps you need to do to perform the complex task, and is guaranteed to work (something that doesn't really work or only works sometimes would just be considered incomplete).

To use a non-programming example, consider a manufacturing plant for a cookie company. The machines have pre-determined procedures for making chocolate chip cookies, oatmeal raisin abominations cookies, and sugar cookies.

Now imagine that you're the guy whose job it is to switch the production lines to a new recipe whenever you change what kind of cookie you're making. It would be a huge pain if, every time, you had to manually input the recipe, and give the machines instructions like "measure 50kg of chocolate chips" and "move the flour bin at 0.1 m/s until it reaches the mixing bowl, and then rotate it at 0.25°/s until all of the flour is in the mixing bowl." It would take a ton of time, and even if you knew the recipes by heart it would still be way too easy to make a tiny mistake and cover the floor in raisins.

Instead, the machine has preset routines. You push the "sugar cookie" button, and it follows the exact steps you gave it to make sugar cookies, every time. You don't have to worry about stupid mistakes, and it doesn't take you three hours to input the instructions.

Algorithms are like those routines. Computer programs have thousands of tasks that are used over and over again. Things like "sort this list of numbers," "draw a triangle with these vertexes and this color," and "save this file." People have worked out efficient, consistent ways of doing those tasks, and now everyone just uses those instead of doing it themselves every time. Some algorithms are designed for less common things, like finding special prime numbers: not things people do all the time, but things where coming up with a better way of doing them is still a big deal.

In the end, "algorithm" is basically just a fancy term for "method of doing something complicated/repetitive/irritating."

Credit goes to: /u/Aurigarion

/r/learnprogramming Thread