No history yet

Algorithm Basics

What Is an Algorithm?

Think about a recipe for baking cookies. It gives you a list of ingredients and a set of instructions. Follow the steps correctly, and you end up with cookies. An algorithm is just like that, but for solving problems or completing tasks. It’s a clear, step-by-step procedure designed to achieve a specific goal.

An algorithm is a finite sequence of well-defined instructions to solve a class of problems or to perform a computation.

Whether it's sorting a list of names, finding the fastest route to a destination, or recommending a movie, an algorithm provides the exact instructions a computer needs to follow. The process isn't magic; it's just a carefully constructed plan.

The Five Key Traits

Not just any set of instructions can be called an algorithm. To be a true, reliable algorithm, a procedure must have five specific characteristics. These qualities ensure that the algorithm is clear, consistent, and actually works.

Finiteness

noun

An algorithm must eventually terminate after a finite number of steps. It can't run forever. Just like a recipe ends when the cookies are baked, an algorithm must have a clear stopping point.

Without finiteness, you'd never get your answer. The process would just keep running, which isn’t very helpful for solving a problem.

Definiteness

noun

Each step of an algorithm must be precisely and unambiguously defined. There should be no room for interpretation. An instruction like "add a pinch of salt" is too vague for a computer. An algorithm would specify "add 1 gram of salt."

Every action must be clear so that the steps can be executed without any guesswork.

Input

noun

An algorithm has zero or more quantities that are externally supplied. These are the values the algorithm works with to produce a result. For a recipe, the inputs are the ingredients like flour, sugar, and eggs.

Some algorithms might not need any input. For example, an algorithm to print the first 100 prime numbers doesn't need you to provide any starting information. It generates the result from its own defined process.

Output

noun

An algorithm must produce at least one quantity as a result. This is the solution to the problem or the result of the completed task. For a recipe, the output is the finished dish. For a sorting algorithm, it’s the sorted list.

An algorithm that doesn't produce any output is useless. The entire point is to get a result that relates to the inputs.

Effectiveness

noun

Every instruction in an algorithm must be basic enough that it can, in principle, be carried out by a person using only pen and paper. Each step must be feasible. Operations should be simple and executable, not theoretical or impossible.

For example, an instruction to "calculate the square root of a number" is effective because it's a well-known, doable operation. An instruction to "find the perfect song" is not, because "perfect" isn't a computable concept.

These five characteristics form the foundation of all algorithms, ensuring they are reliable tools for computation and problem-solving.