Jump to a key chapter

In this article, we will learn about **algorithms**, their properties and their applications.

## Definition of Algorithms

An **algorithm** shows the order in which a process should be followed for an event to occur or for a problem (a mathematical problem) to be solved.

Almost every activity you can think of has an algorithm. Your morning routine has an algorithm. The recipe for your food and how you prepare it has an algorithm. The process of building a house has an algorithm. Basically, anything you can think of that involves a series of processes has an algorithm. For example if you want to make a cup of tea in the morning you'll probably follow the steps below.

Step 1 - Boil water in a kettle

Step 2 - Put a tea bag in a cup

Step 3 - Pour the boiled water into the cup

Step 4 - Add milk to the tea

Step 5 - Add sugar to the tea

Step 6 - Stir the tea

Step 7 - Drink the tea

The above steps make up an algorithm for preparing a cup of tea.

## Algorithm Facts

An algorithm should contain an **input**, the process to be carried out and the desired **output**. Apart from your everyday activities, algorithms also help in problem-solving. When the process for solving a problem is properly outlined in the correct order, the problem will be more easily solved.

Algorithms are very essential, especially for mathematicians, computer scientists and programmers. Before they attempt to solve any problem, they must, first of all, write down the steps to be taken to solve the problem in the correct order. This helps to solve the problem quickly because there is a clear path to follow.

The steps that makes up an algorithm can also be represented in other forms like in a flow chart. To see what a flow chart looks like and to know more about it, check out the article on Charts and diagrams.

## Algorithm Properties

There are many properties of algorithms but the general ones are below.

**Input**- An algorithm can have zero or more inputs. This means that there can be algorithms with no input at all, just one input, or multiple inputs. For example, if the algorithm is only going to print a statement, there is no input for that. You will have an output which is the statement. On the other hand, if an algorithm shows how to add two numbers there are two inputs which are the numbers to be added.**Output**- Unlike the input, an algorithm cannot have zero output. It must have at least one output even if there are no inputs.**Finiteness**- When something is finite, it means it is limited to a specific number. So, an algorithm should have a finite number of steps. The process cannot go on and on. There should be a point of termination or end.**Definiteness**- Every step or instruction in an algorithm must be definite. It must be clear and precise. It shouldn't contain any ambiguity because it needs to be easily understood and interpreted. The instructions should have a meaning and this meaning must be specific. It shouldn't have multiple meanings.**Effectiveness**- An algorithm must be effective. It should be able to do what it was written to do. It should not contain any unnecessary or wrong statements otherwise, it won't be able to perform as it should and the correct output won't be gotten.

## Algorithm Examples

Mathematical problems can be solved using an algorithm like adding and subtracting numbers, finding the squares of numbers, calculating the areas of shapes, and many more. Let's take some examples to illustrate this.

Write an algorithm to add two numbers \( a \), \( b\) and \( c\).

**Solution.**

This algorithm will have three parts. The input, the process for addition, and the output. Here, there are two inputs \( a\) and \( b\). Below is the algorithm.

**Step 1** - Place \( a \), \( b\) and \( c\) on top of each other according to their place values forming columns.

**Step 2 **- Add the numbers from the right taking note of their place values.

**Step 3** - If you add the numbers in the right column and the number exceeds \( 9\), carry over the tens unit of the number to the next column.

**Step 4** - Write the sum of the numbers.

This algorithm is correct because it satisfies the properties of an algorithm. It has an input and output, it has a finite number of steps, each step of the algorithm is complete and easy to understand and the algorithm is able to perform the task that it is written for.

Let's take another example.

Write an algorithm to find out if a number is an odd number.

**Solution.**

**Step 1** - Divide the number by \( 2\)

**Step 2** - If after division there is a remainder, then the number is odd. Otherwise, it is not.

This algorithm is clear and complete. It has a finite number of steps and can give the desired result. It posses the properties of a good algorithm

Let's see some other examples.

Write an algorithm to calculate the area of a triangle.

**Solution.**

When calculating the area of a triangle, you consider the base and the height. Having this in mind, let's write the algorithm.

**Step 1** - Note the value of the base \( b\) of the triangle.

**Step 2** - Note the value of the height \( h\)** **of the triangle.

**Step 3** - Multiply the value for the base and height of the triangle (\( b \cdot h \)).

**Step 4** - Divide the result from the multiplication by \( 2\) to get the area \( \left( \frac {b \cdot h} {2} \right) \).

The algorithm above is a good one. You can identify the inputs as \(b\) and \(h\), and the output as the area of the triangle. It has a finite number of steps and each step is complete and precise. The algorithm can do what its meant to do.

Let's take another example.

Which of these is the correct algorithm for finding the perimeter of the shape below.

**Step 1**- Add \( a\) and \( b\).

** Step 2** - Add \( c\), \( d\) and \( e\) .

**Step 3** - The sum is the perimeter.

B. **Step 1** - Count the number of sides of the shape.

**Step 2** - Add.

**Step 3** - The sum is the perimeter.

C. **Step 1** - Note the value of the sides of the shape - \( a\), \( b\), \( c\), \( d\) and \( e\).

**Step 2** - Add the values \( a\), \( b\), \( c\), \( d\) and \( e\) to get the perimeter.

D. **Step 1 - **Note the value of the sides of the shape - \( a\), \( b\), \( c\), \( d\) and \( e\).

**Step 2 - **Add the values \( a\), \( b\), \( c\), \( d\) and \( e\).

**Step 3 **- Divide the sum by \( 5\) to get the perimeter.

**Solution**

The answer is option **C. **All other options do not possess the properties of an algorithm. They are ineffective and ambiguous.

Here's why the other options are wrong.

Option **A** is not effective. Following those steps will not give you the perimeter of the shape.

Option **B **is ineffective and ambiguous. You will not get the perimeter following the steps and the second step has no meaning.

Option **D** is a wrong algorithm. Its Step 3 says to divide by 5. You do not get the perimeter of a shape by dividing by anything. It is ineffective.

Let's see another type of example.

A friend has given you the following algorithm to look over. Explain why or why not this is an algorithm.

**The Algorithm**

**Step 1 - **Pick it up.

**Step 2 - **Walk to the bin.

**Step 3 - **Throw it away.

**Solution**

You should first examine each step of the algorithm to see what is wrong and what is write.

Step 1 says to ''pick it up''. What exactly should be picked up? It doesn't say what to pick up or where to pick it up from. There is no clarity and it doesn't make much sense. This goes against the definiteness property of an algorithm.

Step 2 says to ''walk to the bin''. It is an instruction to take an action. It makes sense on its own but because you do not know what step 1 is communicating, step 2 won't make as much sense as it should. This also goes against the definiteness property of an algorithm.

Step 3 says to ''Throw it away''. Again, throw what away? We do not know what we are to throw away. So this goes against the definiteness property of an algorithm.

The problem with this algorithm is that it doesn't have a clear meaning. It is incomplete and not easy to understand. That means you can go ahead to let your friend know that this is not an algorithm.

Let's see some more examples.

Which of the following is the correct sequence for an algorithm for brushing your teeth.

- Brush your teeth.
- Open your mouth.
- Open the toothpaste.
- Put tooth paste on the toothbrush.
- Rinse your mouth with water.

- 4, 3, 1, 2, 5
- 3, 2, 1, 4, 5
- 4, 2, 5, 1, 3
- 3, 4, 2, 1, 5

**Solution**

The correct option is **D. **It is the correct order of steps for brushing your teeth.

Let's take the last example.

Write an algorithm to solve \( 2 + 5 \times 4 \).

**Solution**

To write the correct algorithm for this, you need to have know about BODMAS. (To know more about BODMAS, check out the article on Structure and Calculation)

The algorithm is as follows.

**Step 1** - Multiply 5 and 4

**Step 2** - Add the result from the previous step to 2 to get the answer.

This algorithm can give the result it is supposed to give, The steps are clear and complete and it has a finite number of steps. Hence, it is a good algorithm.

## Applications of Algorithms

As we've seen every activity we carry out and problem we try to solve has an algorithm. Let's look at some applications of algorithms.

- Algorithms are used in solving mathematical and scientific problems. Algorithms can be written for various mathematical problems and these algorithms will help for easy problem-solving.
- Algorithms are used in our everyday lives. You can write algorithms by yourself to help you carry out your daily activities properly. The recipes we follow for our food, our morning routine, the process of brushing our teeth and other activities all have algorithms.
- Algorithms are used in computer programming. Before programmers write their codes, they first write down a set of instructions in an orderly manner to follow. These instructions are the algorithms and they help the programmer to write accurate codes that will solve their problems.

## Algorithms - Key takeaways

- An algorithm shows the order in which a process should be followed for an event to occur or for a mathematical problem to be solved.
- An algorithm should contain an input, the process to be carried out and the desired output.
- The properties of algorithms are below.
**Input**- An algorithm can have zero or more inputs. This means that there can be algorithms with no input at all, just one input, or multiple inputs.**Output**- An algorithm cannot have zero output. It must have at least one output even if there are no inputs.**Finiteness**- An algorithm should have a finite number of steps. There should be a point of termination or end.**Definiteness**- Every step or instruction in an algorithm must be clear and precise. It shouldn't contain any ambiguity because it needs to be easily understood and interpreted.**Effectiveness**- An algorithm must be effective. It should be able to do what it was written to do.

###### Learn with 6 Algorithms flashcards in the free StudySmarter app

We have **14,000 flashcards** about Dynamic Landscapes.

Already have an account? Log in

##### Frequently Asked Questions about Algorithms

What are algorithms?

An algorithm shows the order in which a process should be followed for an event to occur or for a mathematical problem to be solved.

What is an example of an algorithm?

An example of an algorithm is the steps taken to add two numbers.

What are algorithms used for?

Algorithms are used for problem solving and they are used to help carry out activities.

What are the properties of algorithms?

Properties of algorithms are below.

- Should have an input.
- Should have an output.
- Finiteness
- Definiteness
- Effectiveness.

What are the types of algorithms?

Some types of algorithms are:

- Recursive algorithm
- Brute force algorithm
- Dynamic programming algorithm
- Greedy algorithm

##### About StudySmarter

StudySmarter is a globally recognized educational technology company, offering a holistic learning platform designed for students of all ages and educational levels. Our platform provides learning support for a wide range of subjects, including STEM, Social Sciences, and Languages and also helps students to successfully master various tests and exams worldwide, such as GCSE, A Level, SAT, ACT, Abitur, and more. We offer an extensive library of learning materials, including interactive flashcards, comprehensive textbook solutions, and detailed explanations. The cutting-edge technology and tools we provide help students create their own learning materials. StudySmarter’s content is not only expert-verified but also regularly updated to ensure accuracy and relevance.

Learn more