**What is an Algorithm**

In this tutorial, we will discuss what is an algorithm with the help of an example. An algorithm is defined as a step-by-step procedure or method for solving a problem.

The world of computing is full of buzzwords: AI, supercomputers, machine learning, the cloud, quantum computing, and more. One word, in particular, is used throughout computing – algorithm. It is better to write an algorithm before writing the actual computer program because it saves time.

Let us consider the problem of preparing a bajji. To prepare a bajji, we follow the given below steps given:

- Get the frying pan.
- Get the oil.
- Do we have oil?
- If yes, put it in the pan.
- If no, do we want to buy oil?
- If yes, then go out and buy.
- If no, we can terminate.

- Do we have oil?
- Turn on the stove, etc…

What we are doing is, for a given problem (preparing a bajji), we are providing a step-by-step procedure for solving it.

While defining an algorithm steps are written in the human-understandable language and independent of any programming language. We can implement it in any programming language of our choice. From the data structure point of view, the following are some important categories of algorithms

**Sort –**Algorithm to sort items in a certain order (Either Ascending/Descending order).**Search –**Algorithm to search an item in a data structure.**Insert –**Algorithm to insert an item in a data structure.**Update –**Algorithm to update an existing item in a data structure.**Delete –**Algorithm to delete an existing item from a data structure.

**Characteristics of an Algorithm **

Not all procedures can be called an algorithm. An algorithm should have the following characteristics

– The algorithm should be clear and unambiguous. Each of its steps and its inputs/ outputs should be clear and must lead to only one meaning.**Clear and Unambiguous****Effectiveness**– An algorithm is also generally expected to be effective. This means that all of the operations to be performed in the algorithm must be sufficiently basic that they can in principle be done exactly and in a finite length of time.**Input**– An algorithm should have zero or more well-defined inputs.**Output**– An algorithm should have 1 or more well-defined outputs and should match the desired output.**Finiteness**– Algorithms must terminate after a finite number of steps.**Feasible –**The algorithm must be simple, generic, and practical, such that it can be executed with the available resources. It must not contain some future technology or anything.**Independent –**An algorithm should have step-by-step directions, which should be independent of any programming code.

**Advantages of Algorithms**

- It is a step-wise representation of a solution to a given problem, which makes it easy to understand.
- An algorithm is a step-wise representation of a solution to a given problem.
- It is not dependent on any programming language, so it is easy to understand for anyone even without programming knowledge.
- Every step in an algorithm has its own logical sequence so it is easy to debug.
- In Algorithm the problem is broken down into smaller pieces or steps hence, it is easier for the programmer to convert it into an actual program.
- An algorithm acts as a blueprint of a program and helps during program development.
- It is easy to first develop an algorithm and then convert it into a flowchart and then into a computer program.

**Disadvantages of Algorithms**

- Writing an algorithm takes a long time so it is time-consuming.
- Branching and Looping statements are difficult to show in Algorithms.
- Big tasks are difficult to put in algorithms.
- Understanding complex logic through algorithms can be very difficult.

**Algorithm 1: Add two numbers entered by the user**

```
Step 1: Start
Step 2: Declare variables num1, num2 and sum.
Step 3: Read values num1 and num2.
Step 4: Add num1 and num2 and assign the result to sum.
sum←num1+num2
Step 5: Display sum
Step 6: Stop
```

**Algorithm 2: Find the largest number among three numbers**

```
Step 1: Start
Step 2: Declare variables a,b and c.
Step 3: Read variables a,b and c.
Step 4: If a > b
If a > c
Display a is the largest number.
Else
Display c is the largest number.
Else
If b > c
Display b is the largest number.
Else
Display c is the greatest number.
Step 5: Stop
```