No history yet

Algorithm Basics

What Is an Algorithm?

Think of an algorithm as a recipe. It's a list of steps for accomplishing a task. Just as a recipe guides you from raw ingredients to a finished dish, an algorithm guides a computer from a problem to a solution. It's a clear, step-by-step plan.

An algorithm is a finite sequence of well-defined instructions to solve a problem or perform a task.

Whether it's sorting a list of names, finding the fastest route on a map, or recommending a movie, an algorithm is the logical engine doing the work behind the scenes. It's not the code itself, but the idea behind the code. The same algorithm can be written in many different programming languages, just like a cookie recipe can be written in English or Spanish.

The Five Core Properties

For a set of instructions to be a true algorithm, it must have five specific properties. These rules ensure that the algorithm is reliable, clear, and actually works.

Finiteness

noun

An algorithm must always terminate after a finite number of steps.

An algorithm can't run forever. It has to have a clear stopping point. Your GPS wouldn't be very useful if it searched for the best route indefinitely. It needs to complete its task and give you directions. A process that never ends is an infinite loop, not an algorithm.

Definiteness

noun

Each step of an algorithm must be precisely and unambiguously defined.

Every instruction must be crystal clear. Computers don't do well with vague commands. An instruction like "add a little bit of sugar" is fine for a human baker, but an algorithm needs something exact, like "add 5 grams of sugar." There should be no guesswork about what to do next.

Lesson image

Input

noun

An algorithm has zero or more well-defined inputs.

Inputs are the ingredients your algorithm will work on. An algorithm for adding two numbers needs, well, two numbers as its input. An algorithm for sorting a list of names needs that list. Some simple algorithms might have no inputs at all, like one that just prints "Hello, World!"

Output

noun

An algorithm has one or more well-defined outputs.

An algorithm must produce a result. This is the output. If you give an addition algorithm the inputs 2 and 3, you expect the output 5. The output is directly related to the input and the algorithm's purpose. Without an output, the algorithm hasn't really accomplished anything.

Effectiveness

noun

Each step must be simple enough that it can, in principle, be carried out by a person using only pencil and paper.

This property ensures that the algorithm is practical. Each operation must be basic and achievable. An instruction like "calculate the square root of 25" is effective because it's a known, doable operation. An instruction like "find the perfect strategy for winning the lottery" is not, because there is no known, finite way to do it. The steps have to be grounded in reality.

These five properties—Finiteness, Definiteness, Input, Output, and Effectiveness—are the pillars that make algorithms the powerful problem-solving tools they are.

Now, let's test your understanding of these fundamental concepts.