In this article, we will learn what is an algorithm, what is the purpose of using it, how to do it and what is the analysis of algorithms.

## What is an Algorithm

**“An algorithm is the step by step set of meaningful and clear instructions to solve a particular problem”**

In the above definition of algorithm, I have mentioned the words “meaningful and clear”, which means the instructions should not be ambiguous(double meaning, no clear meaning).

To understand the concept of algorithm, **lets take an example**: Lets write an algorithm to “make a tea”

1. Get the frying pan 2. Pour the water in the frying pan and let it boil for some time 3. Add sugar, tea leaves and milk. a. Do we have sugar? i. if yes, put it in the pan ii. If no, get the sugar from market and then put it b. Do we have tea leaves? i. if yes, put it in the pan ii. If no, get the tea leaves from market and then put it c. Do we have milk? i. if yes, put it in the pan ii. If no, get the milk from market and then put it 4. Once done, switch off the stove and serve it.

Now that we know what is an algorithm, lets talk about the analysis of algorithm

## What is Analysis of Algorithms

The analysis of algorithm is to compare the various algorithms to solve a same problem. This is done to analyse which algorithm takes less resources such as time, effort and memory to solve a particular problem.

### Types of analysis of algorithm

To analyze a particular algorithm, we need to understand for which input the algorithm takes less time and for which input it takes more time. Based on this, we divide the inputs in three cases:

1. **Best case** where we assume the input, for which algorithm takes less time.

2. **Worst case** where we assume the input, for which algorithm takes long time.

3. **Average case** where the input lies in between best and worst case.

Now that we know the cases and types of analysis we perform on a algorithm. Lets move forward and understand how can we represent the best, worst and average cases of an algorithm with the help of expressions (**notations**). This we will learn in our next tutorial “**Data structure asymptotic notation**“.