No history yet

Algorithm Basics

What is an Algorithm?

If you’ve ever followed a recipe to bake a cake, you’ve used an algorithm. A recipe is just a list of steps to get to a specific outcome: a delicious cake. An algorithm is the same idea, but for computers. It’s a clear, step-by-step set of instructions for solving a problem or completing a task.

An algorithm is a step-by-step procedure to solve a problem in a finite amount of time.

Whether you're sorting a list of names, finding the fastest route home, or recommending a movie, an algorithm is the logical blueprint that makes it happen. But not just any set of instructions can be called an algorithm. To be reliable and effective, it must follow a few strict rules.

The Five Core Rules

For any set of instructions to qualify as a true algorithm, it must have five key characteristics. These aren't just suggestions; they are the essential properties that guarantee an algorithm works correctly and predictably every time.

Finiteness

noun

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

An algorithm can't run forever. It must have a clear stopping point. Imagine a GPS that keeps recalculating your route infinitely, never actually telling you where to turn. That wouldn't be very useful. Every algorithm must eventually finish its job and deliver a result.

Definiteness

noun

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

The instructions must be crystal clear. Vague commands like "add a little sugar" work in a kitchen but fail in computing. An algorithm needs precise instructions like "add 5 grams of sugar." There should be no room for guesswork. Each step must have only one interpretation.

Lesson image

This flowchart is a great example of definiteness. It checks if a number is zero. The path is unambiguous: if it is, one thing happens; if it isn't, something else happens. There's no confusion.

Inputs and Outputs

Algorithms are designed to process information. They take something in, do something with it, and produce something new. This flow of information is described by inputs and outputs.

Input

noun

The data or values an algorithm operates on, provided externally.

An algorithm has zero or more inputs. These are the ingredients. For a sorting algorithm, the input is a list of items to be sorted. For a search algorithm, the inputs might be a list and the specific item you're looking for. Some simple algorithms might not need any input at all, like one that just prints "Hello, World!"

Output

noun

The result or data produced by an algorithm after it has finished processing.

Every algorithm must produce at least one output. This is the finished cake. It's the solution to the problem you were trying to solve. For a sorting algorithm, the output is the sorted list. For a navigation algorithm, the output is the best route. Without an output, the algorithm hasn't accomplished anything.

Making it Work

Effectiveness

noun

Every instruction must be basic enough to be carried out, in principle, by a person with only a pencil and paper.

This last rule ensures that an algorithm is actually feasible. Each step must be something that can be done. An instruction like "find the largest number" is an algorithm in itself, not a single, basic step. A more effective instruction would be to compare two numbers at a time. The steps should be broken down into their simplest, most fundamental operations.

Think of it this way: could you explain each step to a five-year-old and have them follow it? If so, your algorithm is probably effective.

These five characteristics—finiteness, definiteness, input, output, and effectiveness—are the bedrock of all algorithms. They ensure that we can create reliable, predictable, and powerful tools to solve problems with computers.

Time to check your understanding of these core concepts.

Quiz Questions 1/5

Which of the following best describes an algorithm?

Quiz Questions 2/5

A GPS navigation system that continuously recalculates a route without ever providing a final direction is violating which key characteristic of an algorithm?

With these foundations in place, you're ready to explore how different types of algorithms are designed and analyzed.