# What is an Algorithm?

# What is an Algorithm? Examples of Algorithm

### Content:

**What is an Algorithm?**

**Examples of Algorithm**

**What is an Algorithm? Diagram**

**Types of an Algorithm**

**Advantages of an Algorithm**

**Disadvantages of an Algorithm**

**What is an Algorithm?**

**What is an Algorithm?**

**Algorithm: Simple Definition**

An algorithm is a well-defined process that allows the computer to solve any problem. It can also be defined that it is a sequence of unambiguous instructions. It becomes easiest for a task to perform by a computer that task uses algorithms.

It is a step-by-step procedure for solving a problem. It is used for data processing, calculations, mathematical problems, and other computer-related operations. It is also used to manipulate data in multiple ways. For example, a new data item, sorting an item or searching a particular item.

**Algorithm: AM7S defines**

It is a detailed series of instructions for solving the problem. Algorithms are used in everyday tasks in a non-technical approach. For example to compute an employee’s paycheck. An appropriate data is entered inti the system to accomplish the task.

An algorithm is pronounced as Al-Go-Rith-Um. It is a formula for solving a problem. A computer program is viewed as an elaborate algorithm. An algorithm means a small procedure for solving a recurrent problem in mathematics and computer science.

Algorithms are used in all areas of Information Technology. For example, a search engine algorithm takes the search for things of keywords and operators as input. It then searches its associated database for relevant web pages and returns results.

**What is an Algorithm Types:**

There are many types of algorithms. The most fundamental types of algorithms are described below:

- Recursive algorithms
- Dynamic programming algorithm
- Backtracking algorithm
- Divide and conquer algorithm
- Greedy algorithm
- Brute Force algorithm
- Randomized algorithm

**Simple Recursive Algorithm:**

It is used to solve the base case directly. It recurs with an easier input every time.

**Example:**

**For finding factorial using recursion, the pseudo-code is:**

** **

** Fact(x)**

** If x is 0 [ /*0 is the base value and x is 0 is base case*/]**

** return 1**

** return (x*Fact(x-1)) [/* breaks the problem into small problems*/]**

** What is an Algorithm?**

**Dynamic Programming Algorithm:**

It is also called a Dynamic Optimization Algorithm. It remembers the pat results and uses them to find new results. It means that it breaks a complex problem into a collection of subproblems and then solves them. In this attempt, it solves the mild stones one by one and stores their results for future use instead of precomputing their solutions again.

**Example:**

**Fibonacci sequence, the pseudo code is:**

** **

**Fib(n)**

** if n=0**

** return 0**

** else**

** prev_Fib=0,curr_Fib=1**

** repeat n-1 times /*if n=0 it will skip*/**

** next_Fib=prev_Fib+curr_Fib **

** prev_Fib=curr_Fib**

** curr_Fib=new_Fib**

** return curr_Fib**

**BackTracking Algorithm:**

It is a technique for solving problems recursively.

**Example:**

**Queens Problem**

**Divide and Concur Algorithm:**

This algorithm consists of two parts. Firstly it divides the problems into smaller subproblems of the same type and solves them recursively. To form the solution of the original problem, these submodules’ results are combined.

**Example:**

**Merge Sort**

**Quicksort**

**Greedy Algorithm:**

This is a type of algorithm that solves the problem by taking an optimal solution at the local level.

It is not necessary that you are definitely going to find the optimal solution by following this algorithm.

There are some problems for which this solution (Optimal Solution) does not exist. These types of problems are called NP-complete problems.

**Example:**

**Counting money**

**Huffman tree**

**Brute Force Algorithm:**

This algorithm tries all the possibilities until a satisfactory solution is found. It is used to find optimal solutions and finding satisfactory solutions. It stops as soon as the solution to the problem is found.

**Example:**

**Exact string matching algorithm**

**Randomized Algorithm:**

It uses random numbers at least once during the computation for making a decision.

**Example:**

**Quicksort**

**An algorithm in programming:**

A programming algorithm is a procedure of computer that tells the computer precisely what steps should be taken to solve a problem. It is like a recipe. If a procedure is recipe then all its ingredients are called inputs and the results are called output.

## Example Of What is an Algorithm?

**Advantages of an Algorithm:**

- It is easy to write.
- It is easy to understand.
- It uses easy techniques to understand the logic.
- It is easy to identify mistakes.
- Every step has its own logical sequence.
- It is easy to debug.
- No need to understand a particular programming language.
- It’s flexible.
- It allows writing code in any language.
- It is written in simple English language.
- A non-technical user can also easily understand.

**Disadvantages of an Algorithm:**

- It is time-consuming.
- It is difficult to show looping and branching.
- It is not suitable for big programs.
- It is difficult for big tasks to fit into an algorithm.

**As you read What is an Algorithm?**

**See More Here: **