# Algorithm The algorithm is all about making planning. We plan our weekend, our daily work. For example: Plan involved in making tea is :(Get Analysis of Algo here)

Step1: Boil water

Step2: Add ingredients (milk, sugar etc)

Step3: Pour tea in teapot

Step4: Serve

In the same way before writing any program step by step procedures are involved and this is defined as algorithm.

The word algorithm involves steps that are designed to perform a particular task.

This can be a basic procedure, for example, multiplying two numbers, adding two numbers, finding the prime numbers or a mind-boggling activity, for example, playing a compacted video document.

Real-life examples where the algorithm is used are in mp3 players, video players, making dictionaries and there are many examples.

It helps to do a given task in programming to get the output.

Algorithm solved many different problem.

In programming, stemmer(synonym of the algorithm) prompts an answer and attempts to be the most efficient arrangement we can brainstorm.

Before writing any program pseudocode and flowchart must be written

Pseudocode is a method of writing the stemmer and flowcharts involve program flow from the top to bottom approach using different shapes and symbols.

Different types of algorithm:

### 1. Recursive Algorithm

In this, problems are solved by repeatedly breaking them into sub-problems. An example of this type is the Tower of Hanoi.

### 2. Divide and Conquer

This consists of breaking down a problem into some smaller independent sub-problems of the same type and finding the final solution of the original problems after solving these smaller problems separately.

### 3. Dynamic Programming Algorithm

Similarly, divide and conquer, this simplifies a complex problem by breaking it down into some simple sub-problems. It requires overlapping of sub-problems.

### 4. Greedy

It refers to always finding the best solution in every step instead of considering the overall optimality.

### 5. Brute Force Algorithm

This is simple and normally based on the description of the problem and the definition of the concept involved.

### 6. Backtracking

This is based on a depth-first recursive search, the backtracking focusing on finding the solution to the problem during the enumeration-like searching process.

One of the most famous backtracking example it the eight queens puzzle.

Characteristics of an Algo:

• Precision – Definitely stated(defined).
• Uniqueness – after-effects of each progression are particularly defined and just rely upon the info and the consequence of the preceding steps.
• Limit – The calculation stops after a limited number of instructions are executed.
• Input – The algo gets input.
• Output – The algo produces yield.
• Generality – the algo applies to a set of inputs.

Different categories of Algo:

• Search − Algo to search an element.
• Sort − Algo to sort the elements in any order.
• Insert − Algo to insert element.
• Update − Algo to update an existing element in data structure.
• Delete − Algo to delete an existing element from a data structure.

### Steps to design an algo:

Algorithms are used to perform operations/tasks on the given data contained in data structures.

A complex algorithm is often divided into smaller units called modules.The advantages of dividing algorithm into smaller units are as follows:

It makes the complex algo simpler to design and implements

Independently work can be performed on each module.

While working on one module, the details of other modules can be ignored, thereby enhancing clarity in design which in turn simplifies implementation, testing, documenting, and maintenance of the whole algo.

There are two main approaches to design an algorithm—top-down approach and bottom-up approach

### Top-down approach

The top-down approach is defined as dividing the complex algo into one or more sections or modules.

These modules can further be decomposed into one or more sub-modules, and this process of decomposition is repeated until the desired level of module complexity is achieved.

Therefore, in a top-down approach, we start from an abstract design followed by each and every step, this design is refined until a level is reached that requires no further refinement.

### Bottom-up approach-

A bottom-up approach is the reverse of the top-down approach. We start with designing the most basic section and then proceed towards designing higher levels of parts in the bottom-up design,.

When the lower-level modules perform the operation then the higher levels of modules get implemented.

However, this process is repeated until the design of the complete algorithm is obtained.

#### First Algorithm

Find the sum of two numbers:

1 : Start

2 : Take first number

3 : Take second number

4 : Add the above two numbers

5 : Display the result

6 : Stop