What Is an Algorithm? | Definition & Examples

An algorithm is a set of steps for accomplishing a task or solving a problem. Typically, algorithms are executed by computers, but we also rely on algorithms in our daily lives. Each time we follow a particular step-by-step process, like making coffee in the morning or tying our shoelaces, we are in fact following an algorithm.

In the context of computer science, an algorithm is a mathematical process for solving a problem using a finite number of steps. Algorithms are a key component of any computer program and are the driving force behind various systems and applications, such as navigation systems, search engines, and music streaming services.

Instantly correct all language mistakes in your text

Upload your document to correct all your mistakes in minutes

upload-your-document-ai-proofreader

What is an algorithm?

An algorithm is a sequence of instructions that a computer must perform to solve a well-defined problem. It essentially defines what the computer needs to do and how to do it. Algorithms can instruct a computer how to perform a calculation, process data, or make a decision.

The best way to understand an algorithm is to think of it as a recipe that guides you through a series of well-defined actions to achieve a specific goal. Just like a recipe produces a replicable result, algorithms ensure consistent and reliable outcomes for a wide range of tasks in the digital realm.

And just like there are numerous ways to make, for example, chocolate chip cookies by following different steps or using slightly different ingredients, different algorithms can be designed to solve the same problem, with each taking a distinct approach but achieving the same result.

Algorithms are virtually everywhere around us. Examples include the following:

  • Search engines rely on algorithms to find and present relevant results as quickly as possible
  • Social media platforms use algorithms to prioritize the content that we see in our feeds, taking into account factors like our past behavior, the popularity of posts, and relevance.
  • With the help of algorithms, navigation apps determine the most efficient route for us to reach our destination.
Note
It is important to keep in mind that we cannot call a set of instructions an algorithm unless it has all the following properties:

  • It must be correct. In other words, it should take a given problem and provide the right answer or result, even if it stops working due to an error.
  • It must consist of clear, practical steps that can be completed in a limited time, whether by a person or the machine that must execute the algorithm. For example, the instructions in a cookie recipe might be considered sufficiently concrete for a human cook, but they would not be specific enough for programming an automated cookie-making machine.
  • There should be no confusion about which step comes next, even if choices must be made (e.g., when using “if” statements).
  • It must have a set number of steps (not an infinite number) that can be managed using loops (statements describing repeated actions or iterations).
  • It must eventually reach an endpoint and not get stuck in a never-ending loop.

The only proofreading tool specialized in correcting academic writing - try for free!

The academic proofreading tool has been trained on 1000s of academic texts and by native English editors. Making it the most accurate and reliable proofreading tool for students.

Try for free

How do algorithms work?

Algorithms use a set of initial data or input, process it through a series of logical steps or rules, and produce the output (i.e., the outcome, decision, or result).

Algorithm boxes

If you want to make chocolate chip cookies, for instance, the input would be the ingredients and quantities, the process would be the recipe you choose to follow, and the output would be the cookies.

Algorithms are eventually expressed in a programming language that a computer can process. However, when an algorithm is being created, it will be people, not a computer, who will need to understand it. For this reason, as a first step, algorithms are written as plain instructions.

Example of algorithm 
Let’s consider for example an algorithm that calculates the square of a given number.

  • Input: the input data is a single-digit number (e.g., 5).
  • Transformation/processing: the algorithm takes the input (number 5) and performs the specific operation (i.e., multiplies the number by itself).
  • Output: the result of the calculation is the square of the input number, which, in this case, would be 25 (since 5 * 5 = 25).

We could express this as an algorithm in the following way:

Algorithm: Calculate the square of a number

  1. Start.
  2. Input the number (N) whose square you want to find.
  3. Multiply the number (N) by itself.
  4. Store the result of the multiplication in a variable (result).
  5. Output the value of the variable (result), which represents the square of the input number.
  6. End.

An algorithm represents the thinking process for solving a problem in an abstract yet precise way, rather than the answer itself.

It is important to keep in mind that an algorithm is not the same as a program or code. It is the logic or plan for solving a problem represented as a simple step-by-step description. Code is the implementation of the algorithm in a specific programming language (like C++ or Python), while a program is an implementation of code that instructs a computer on how to execute an algorithm and perform a task.

Instead of telling a computer exactly what to do, some algorithms allow computers to learn on their own and improve their performance on a specific task. These machine learning algorithms use data to identify patterns and make predictions or conduct data mining to uncover hidden insights in data that can inform business decisions.

Broadly speaking, there are three different types of algorithms:

  • Linear sequence algorithms follow a specific set or steps, one after the other. Just like following a recipe, each step depends on the success of the previous one.
  • Conditional algorithms make a decision between two actions. Instead of executing all steps sequentially, a conditional algorithm involves making choices based on specific scenarios or input data. It uses “if/then” statements to determine what to do.
    • For example, in the context of a cookie recipe, you would include the step “if the dough is too sticky, you might need to refrigerate it.”
  • Looping algorithms repeat a specific set of instructions multiple types until either a certain condition is met or a predefined number of repetitions has been completed. The purpose of looping algorithms is to efficiently perform repetitive tasks without the need to write the same instructions multiple times.
    • For example, a looping algorithm could be used to handle the process of making multiple cookies from a single batch of dough. The algorithm would repeat a specific set of instructions to form and bake cookies until all the dough has been used.

Examples of algorithms

Algorithms are fundamental tools for problem-solving in both the digital world and many real-life scenarios. Each time we try to solve a problem by breaking it down into smaller, manageable steps, we are in fact using algorithmic thinking.

Example of algorithm in everyday life
Daily routines are examples of how we use algorithms without realizing that we are doing so. While it may seem to come naturally to us, for example, deciding what to wear in the morning is a complex decision involving many steps. If you had to write down your process in detail, you would end up with an algorithm, which could look something like this:

  1. Identify which clothes are clean.
  2. Consider the weather forecast for the day.
  3. Consider the occasion for which you are getting dressed (e.g., work or school etc.).
  4. Consider personal preferences (e.g., style or which items match).

All of this can be represented with data, either as words (e.g., “casual”) or numbers (e.g., the temperature), which can serve as input for your decision. The next step is processing these input quantities. If you had to write this down, it would include statements like “If it’s below 50 degrees, pick out a sweater and put it on” or “If it’s sunny, grab sunglasses and put them on.” After getting dressed, we step out of the house, which is the output of our getting-dressed algorithm.

In mathematics, algorithms are standard methods for performing calculations or solving equations because they are efficient, reliable, and applicable to various situations.

Example standard algorithm for addition
In mathematics, a standard algorithm refers to a specific, well-defined set of steps or procedures used to solve mathematical problems of a particular type. Different places in the world use different algorithms, so every school system may teach this concept differently. In the United States, schools use a standard algorithm based on place value and the properties of operations for addition, subtraction, multiplication, and division.

Suppose you want to add the numbers 345 and 278. You would follow a set of steps (i.e., the standard algorithm for addition):

    1. Write down the numbers so the digits align.
    2. Start from the rightmost digits (the ones place) and add them together: 5 + 8 = 13. Write down the 3 and carry over the 1 to the next column.
    3. Move to the next column (the tens place) and add the digits along with the carried-over value: 4 + 7 + 1 = 12. Write down the 2 and carry over the 1 to the next column.
    4. Move to the leftmost column (the hundreds place) and add the digits along with the carried-over value: 3 + 2 + 1 = 6. Write down the 6.

The final result is 623

Algorithm calculation example

Navigation systems are another example of the use of algorithms. Such systems use algorithms to help you find the easiest and fastest route to your destination while avoiding traffic jams and roadblocks.

Example of algorithm: Navigation systems
The algorithms used in navigation systems like Google Maps are essentially the brains of these apps. These algorithms use a wealth of data, including detailed maps and live traffic updates, to determine the best way to get where you want to go. They consider factors like how far you need to travel or which roads are busy.

If there are any unexpected problems, such as accidents on a given route, algorithms quickly recalculate and suggest alternate routes to avoid delays; this ensures that you don’t waste time in traffic. They also provide you with step-by-step directions so you know exactly where to turn. These algorithms learn from how people use them and therefore keep getting better at finding the quickest routes.

Other interesting articles

If you want to know more about ChatGPT, AI tools, fallacies, and research bias, make sure to check out some of our other articles with explanations and examples.

Check for common mistakes

Use the best grammar checker available to check for common mistakes in your text.

grammar-checker-common-mistakes

Fix mistakes for free

Frequently asked questions about algorithms

What is an algorithm in computer science?

In computer science, an algorithm is a list of unambiguous instructions that specify successive steps to solve a problem or perform a task. Algorithms help computers execute tasks like playing games or sorting a list of numbers. In other words, computers use algorithms to understand what to do and give you the result you need.

Are algorithms the same as artificial intelligence (AI)?

Algorithms and artificial intelligence (AI) are not the same, however they are closely related.

  • Artificial intelligence is a broad term describing computer systems performing tasks usually associated with human intelligence like decision-making, pattern recognition, or learning from experience.
  • Algorithms are the instructions that AI uses to carry out these tasks, therefore we could say that algorithms are the building blocks of AI—even though AI involves more advanced capabilities beyond just following instructions.
Are algorithms the same as computer programs?

Algorithms and computer programs are sometimes used interchangeably, but they refer to two distinct but interrelated concepts.

  • An algorithm is a step-by-step instruction for solving a problem that is precise yet general.
  • Computer programs are specific implementations of an algorithm in a specific programming language. In other words, the algorithm is the high-level description of an idea, while the program is the actual implementation of that idea.
Why do we need algorithms?

Algorithms are valuable to us because they:

  • Form the basis of much of the technology we use in our daily lives, from mobile apps to search engines.
  • Power innovations in various industries that augment our abilities (e.g., AI assistants or medical diagnosis).
  • Help analyze large volumes of data, discover patterns and make informed decisions in a fast and efficient way, at a scale humans are simply not able to do.
  • Automate processes. By streamlining tasks, algorithms increase efficiency, reduce errors, and save valuable time.

Cite this Scribbr article

If you want to cite this source, you can copy and paste the citation or click the “Cite this Scribbr article” button to automatically add the citation to our free Citation Generator.

Nikolopoulou, K. (2023, August 29). What Is an Algorithm? | Definition & Examples. Scribbr. Retrieved April 25, 2024, from https://www.scribbr.com/ai-tools/what-is-an-algorithm/

Is this article helpful?
Kassiani Nikolopoulou

Kassiani has an academic background in Communication, Bioeconomy and Circular Economy. As a former journalist she enjoys turning complex scientific information into easily accessible articles to help students. She specializes in writing about research methods and research bias.

1 comment

Kassiani Nikolopoulou
Kassiani Nikolopoulou (Scribbr Team)
August 9, 2023 at 7:24 PM

Thanks for reading! Hope you found this article helpful. If anything is still unclear, or if you didn’t find what you were looking for here, leave a comment and we’ll see if we can help.

Still have questions?

Please click the checkbox on the left to verify that you are a not a bot.