# Introduction to Algorithms

Here, We will learn why every programmer should learn introduction to algorithms, categories of algorithms, characteristics of algorithms, how to write algorithms with help of examples like write algorithm for the addition of two numbers.

### What are algorithms?

Algorithms are a series of steps or rules for solving a computational problem.

In other words, an algorithm a step-by-step procedure which defines a set of instructions to be executed in a certain order to get the desired output.

Example Code:

``````if (clock.getTime() == 7am){
coffeeMaker.boilWater();
if (water.isBoiled()){
coffeeMaker.pourCoffee();
}
}
else{
coffeeMaker.doNothing();
}
```Code language: C++ (cpp)```

A good algorithms is like using right and efficient tool in workshop.

Example: Using wrong algorithms mean cutting paper with a saw or trying to cut a piece of plywood with knife.

### Categories of Algorithms

1. Search – Algorithm to search an item. Ex- Searching Techniques
2. Sort – Algorithm to sort items in a certain order. Ex – Sorting Algorithms
3. Insert – Algorithm to insert item.
4. Update – Algorithm to update an existing item.
5. Delete – Algorithm to delete an existing item.

### Characteristics of an Algorithm

Not all procedure can be called an algorithm.

An algorithm should have the following characteristics:

1. Unambiguous – Each of its step and their inputs/outputs should be clear and must lead to only one meaning
2. Input – Should have 0 or more well-defined inputs
3. Output – should have 1 or more desirable well-defined outputs.
4. Finiteness – must terminate after a finite number of steps.
5. Feasibility – Should be feasible with the available resources.
6. Independent – Should have step-by-step directions and independent of any programming language.

### How to Write an Algorithm?

There is no well defined standard for writing algorithms. Algorithms are never written in support of a particular programming code.

We write algorithms in a step-by-step manner. Algorithms writing is a process and is executed after the problem domain is well-defined.

##### Write algorithm for addition of two numbers and display the result.
``````step 1 - START
step 2 - declare three integers a, b &c
step 3 - define values of a & b
step 4 - add values of a & b
step 5 - store output of step 4 to c
step 6 - print c
step 7 - STOP```Code language: C++ (cpp)```

Algorithms tell the programmers how to code the program. Alternatively, the algorithm can be written as :

``````step 1 - START ADD
step 2 - get values of a & b
step 3 - c ← a + b
step 4 - display c
step 5 - STOP```Code language: C++ (cpp)```

In design and analysis of algorithms, usually the second method is used to describe an algorithm.

We design algorithms to get a solution to a given problem. A problem can be solved in more than one ways.

### Heap Sort

Here, We will discuss about Heap Sort in C, their algorithm, implementation code in C, time and space complexity, and their applications. What …

### Linear Search

Here, We discuss about Linear Search, their implementation in C, time and space complexity and its applications. What is Linear Search? Linear Search is the simplest …

### Counting Sort

Here, We will discuss about Counting Sort in C, their algorithm, implementation code in C, time and space complexity, and their applications. What is Counting …

### Divide and Conquer Algorithms

Here, We will discuss about divide and conquer algorithms, their strategy, pros and cons of divide and conquer, applications of divide and conquer algorithm. What is …

### Insertion Sort

Here, We will learn about insertion sort in C, their algorithm, implementation code in C, time and space complexity and advantages.. What is Insertion sort? Insertion Sort …

### Binary Search

Here, We discuss about Binary Search, their implementation in C, time and space complexity and its applications. What is Binary Search? Binary Search is the …

### Want to Contribute:-

If you like “To The Innovation” and want to contribute, you can mail your articles to [email protected]. See your articles on the main page and help other coders. 