Log In Start studying!

Select your language

Suggested languages for you:
StudySmarter - The all-in-one study app.
4.8 • +11k Ratings
More than 3 Million Downloads
Free
|
|

Algorithms

Algorithms

Everyone gets excited when its summer time because it means no more school for a while. We get to do different things and visit family. Every day is a new activity. But during the school period you do the same thing every week day, especially in the mornings. If you write down everything you do in the morning in the order that you do them, that is called an algorithm. You can also call the series of steps you take to solve a math problem an algorithm.

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.

  1. 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.
  2. Output - Unlike the input, an algorithm cannot have zero output. It must have at least one output even if there are no inputs.
  3. 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.
  4. 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.
  5. 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.

Algorithms A polygon StudySmarterFig. 1. Polygon with irregular sides.

  1. 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.

  1. Brush your teeth.
  2. Open your mouth.
  3. Open the toothpaste.
  4. Put tooth paste on the toothbrush.
  5. Rinse your mouth with water.
  1. 4, 3, 1, 2, 5
  2. 3, 2, 1, 4, 5
  3. 4, 2, 5, 1, 3
  4. 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.

  1. 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.
  2. 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.
  3. 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.
    1. 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.
    2. Output - An algorithm cannot have zero output. It must have at least one output even if there are no inputs.
    3. Finiteness - An algorithm should have a finite number of steps. There should be a point of termination or end.
    4. 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.
    5. Effectiveness - An algorithm must be effective. It should be able to do what it was written to do.

Frequently Asked Questions about 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.

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

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

Properties of algorithms are below.

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

Some types of algorithms are:

  • Recursive algorithm
  • Brute force algorithm
  • Dynamic programming algorithm
  • Greedy algorithm

Final Algorithms Quiz

Question

What are algorithms?

Show answer

Answer

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

Show question

Question

List the properties of algorithms

Show answer

Answer

  • Input
  • Output
  • Finitness
  • Definiteness
  • Effectiveness

Show question

Question

How or where can algorithms be applied?

Show answer

Answer

  • Algorithms can be used for solving mathematical problems.
  • They can be used for solving scientific problems.
  • They can be applied in our everyday lives like using a recipe for a meal.
  • Computer programmers use algorithms to state out the instructions to follow before writing their codes.

Show question

Question

An algorithm can have more than one input. 

TRUE OR FALSE

Show answer

Answer

True

Show question

Question

An algorithm can have more than one output.

TRUE OR FALSE

Show answer

Answer

False

Show question

Question

An algorithm can have zero input.

TRUE OR FALSE

Show answer

Answer

True

Show question

Question

An algorithm should be made to go on and on without stopping.

TRUE OR FALSE

Show answer

Answer

False

Show question

Question

An instruction in an algorithm should have a definite meaning.

TRUE OR FALSE

Show answer

Answer

True

Show question

Question

If an algorithm does not perform the task it is written for, we say the algorithm is...

Show answer

Answer

Ineffective.

Show question

60%

of the users don't pass the Algorithms quiz! Will you pass the quiz?

Start Quiz

Discover the right content for your subjects

No need to cheat if you have everything you need to succeed! Packed into one app!

Study Plan

Be perfectly prepared on time with an individual plan.

Quizzes

Test your knowledge with gamified quizzes.

Flashcards

Create and find flashcards in record time.

Notes

Create beautiful notes faster than ever before.

Study Sets

Have all your study materials in one place.

Documents

Upload unlimited documents and save them online.

Study Analytics

Identify your study strength and weaknesses.

Weekly Goals

Set individual study goals and earn points reaching them.

Smart Reminders

Stop procrastinating with our study reminders.

Rewards

Earn points, unlock badges and level up while studying.

Magic Marker

Create flashcards in notes completely automatically.

Smart Formatting

Create the most beautiful study materials using our templates.

Sign up to highlight and take notes. It’s 100% free.

Get FREE ACCESS to all of our study material, tailor-made!

Over 10 million students from across the world are already learning smarter.

Get Started for Free
Illustration