Safekipedia
AlgorithmsMathematical logicTheoretical computer science

Algorithm

Adapted from Wikipedia · Adventurer experience

Historical diagram showing Charles Babbage's Analytical Engine calculating Bernoulli numbers, an early concept in computer science.

An algorithm is a step-by-step process for solving a problem or doing a calculation. In mathematics and computer science, algorithms are like recipes. They tell a computer or a person exactly what to do, step by step, to get a result. Algorithms can help with simple math problems or complex tasks like organizing data or playing games.

Algorithms are important because they help us solve many kinds of problems quickly and accurately. We use them in almost every part of modern life. They help search engines find information and help credit cards process payments. Some algorithms can even help make choices for us, like deciding what videos to watch next or what products to buy.

Not all ways to solve problems are algorithms. Some methods are called heuristics. These are guidelines that help us make decisions but don’t always give the perfect answer. For example, recommender systems on social media use heuristics because there isn’t one single “right” answer for what someone should see next.

An algorithm must finish in a limited amount of time and space. This means it can’t go on forever or need endless memory. Some algorithms are deterministic, meaning they always give the same result for the same starting point. Others are randomized algorithms, which use some randomness to explore different possibilities and often find better solutions.

Etymology

Muḥammad ibn Mūsā al-Khwārizmī: The 9th-century mathematician whose name is the origin of the word 'algorithm'.

The word "algorithm" comes from the name of a Persian scientist, Muḥammad ibn Mūsā al-Khwārizmī. He wrote important books about math around 825 AD. When his books were translated into Latin in the 12th century, his name changed to "Algoritmi." This is how the word algorism entered English. It meant a way to do calculations with numbers. Over time, the word changed to "algorithm." Today, we use it to describe step-by-step processes in math and computer science.

Definition

An algorithm is a set of rules that tells you the steps to follow to finish a task. This can be things like computer programs, instructions to complete a job, or even a recipe for cooking. For an algorithm to work well, it should finish at some point, but sometimes people might want steps that keep going forever.

History

Ada Lovelace's diagram from "Note G", the first published computer algorithm

People have used step-by-step ways to solve math problems for a very long time. For example, people in Babylonian mathematics, Egyptian mathematics, and Greek mathematics made rules to help with calculations. One old example is a Sumerian clay tablet from around 2500 BC that shows a way to do division.

Later, a mathematician named Muḥammad ibn Mūsā al-Khwārizmī made clear, step-by-step ways to solve problems. His work helped change math into a process with set rules. This is a big idea behind modern algorithms. Today, algorithms are used in many places, like social media apps such as Instagram and YouTube, to help choose what you see based on what you like.

Representations

Algorithms can be written in many ways. You can use everyday words, special code called pseudocode, diagrams called flowcharts, or computer languages. Each way has its own good points. For example, flowcharts use simple shapes and arrows to show the steps clearly.

One special way to think about algorithms uses a Turing machine. This is a model for how computers might work. These algorithms can be described in simple terms, in more detailed steps, or in very exact rules. Flowcharts are helpful because they use easy-to-understand symbols to show how an algorithm works.

Algorithmic analysis

Main article: Analysis of algorithms

We often want to know how much time or space an algorithm needs to do its job. Scientists use special ways to guess these needs. For example, adding numbers in a list might take time that grows with the list size, shown as O(n).

Scientists study algorithms in two ways: by math and by testing. Math helps understand what an algorithm can do, while testing shows how it works in real life. Every algorithm has a best case (when it works fastest) and a worst case (when it takes the most time).

Design

Algorithm design is a way to solve problems by giving computers step-by-step instructions. It helps break big problems into smaller ones (divide-and-conquer) or find ways to save time and memory (dynamic programming). A main goal is to make sure the algorithm works well with lots of data, which is measured using big O notation.

Structured programming makes algorithms easier to understand. With just a few basic steps, like making choices and repeating actions, programmers can create clear and correct programs. This structure helps avoid messy code and makes it easier to see that the algorithm works right.

Legal status

See also: Software patent

Algorithms themselves usually cannot be patented. In the United States, just working with ideas, numbers, or signals is not enough to get a patent. But, using an algorithm for a real purpose can be patented. For example, using an algorithm to help make synthetic rubber was allowed as a patent. Patenting software, especially for things like data compression, is still talked about a lot. Some secret codes also have rules about where they can be used.

Classification

Algorithms can be grouped in different ways based on how they work.

Some algorithms use a method called recursion, where the algorithm calls itself until it stops. Others use iteration, which repeats steps using loops or special tools. For example, the Tower of Hanoi puzzle can be solved using recursion.

Algorithms can be deterministic, meaning they make exact decisions each time, or non-deterministic, where they make guesses that improve with heuristics. Some algorithms find the exact answer, while others, like approximation algorithms, look for answers close to the right one. For instance, the Knapsack problem tries to fit items into a bag without going over a weight limit.

Another way to group algorithms is by their design paradigm. Brute-force methods try every option until they find the best one. Divide-and-conquer breaks problems into smaller parts, solves each part, and then puts the solutions together—like in merge sorting, where a list is split, sorted, and then merged back together. Randomized algorithms make random choices to find answers, which can be faster for some problems.

For optimization problems, algorithms can use methods like linear programming to find the best solution under certain rules, or dynamic programming to break problems into smaller parts and remember the answers. Greedy algorithms build a solution step by step, often finding a good but not perfect answer. Heuristic algorithms work toward the best answer over time and include methods like local search and genetic algorithms.

Examples

Further information: List of algorithms

One of the simplest algorithms helps us find the biggest number in a list. You start by thinking the first number is the biggest. Then you look at each number in the list. If you find a number bigger than the one you’re holding, that new number becomes the biggest. You keep doing this until you’ve looked at all the numbers. The number you end up with is the largest one in the list.

We can write these steps in a special way, almost like giving directions to a computer. This is called pseudocode or pidgin code.

This article is a child-friendly adaptation of the Wikipedia article on Algorithm, available under CC BY-SA 4.0.

Images from Wikimedia Commons. Tap any image to view credits and license.