# Introduction to Algorithms

In this article, we are going to learn - Introduction to Algorithms, properties, notations and example.
Submitted by Mansha Lamba, on September 02, 2018

Algorithms are an integral part of the development world. Before starting coding of any software first an effective algorithm is designed to get desired outputs. In this article, we will understand what are algorithms, characteristics of algorithms, some examples of famous algorithms, Types of algorithms etc..

Let's get started...

## What is an Algorithm?

It is a combination of a sequence of finite steps to solve a particular problem. or, It is a well-defined procedure which takes zero or more input and must produce at least one output to solve a particular problem.

### Properties/Characteristics of Algorithms

• Input: It may take zero or more input.
• Output: It must produce at least one output.
• Definiteness (Unambiguous): Every step in algorithm should be well defined, unique, precise.
• Finiteness (Limited): Every algorithm should contain a finite number of steps and should produce a result infinite amount of time.
• Effectiveness: Operations used in algorithm must be simple and easy to understand.
• Language independent.

Note:

• An algorithm is a step by step procedure to solve a particular problem whereas a program is an algorithm that is encoded in any programming language.
• Program is language dependent and algorithm is language independent.

### Notation of an Algorithm

1. Name of the algorithm: It should specify the problem to be solved.
2. Step no.: It is an identification tag ( step numbering ) that specify the numbering of steps/statements. It is a positive integer.
3. Explanatory comments: It is used to specify the meaning of instruction that is used in the algorithm. It is used to understand the logic of operations by the use of [ ] for comments in the algorithm.
4. Termination: Generally it is a STOP statement and the last statement of an algorithm that denoted ending of the algorithm.

### Example

Algorithm for addition of two numbers:

```    ADD( A , B )

Step 2: sum=A+B [ A & B are added and their value is stored in sum ]
Step 3: PRINT ‘Sum of A & B =’, sum
Step 4: STOP
```

This is an algorithm, the corresponding program will be different for different languages like for C language it is:

```#include<stdio.h>

int main()
{
int num1,num2,opt;

printf("Enter the first Integer:\n");
scanf("%d",&num1);
printf("Enter the second Integer:\n");
scanf("%d",&num2);
printf("Enter an correct option -> 1:addition 2: subtraction 3: multiplication 4: division -> \n");
scanf("%d",&opt);

switch(opt)
{
case 1:
printf("\nAddition of  %d and %d is: %d",num1,num2,num1+num2);
break;

case 2:
printf("\nSubstraction of %d  and %d is:  %d",num1,num2,num1-num2);
break;

case 3:
printf("\nMultiplication of %d  and %d is:  %d",num1,num2,num1*num2);
break;

case 4:
if(num2==0)
{
printf("OOps Devide by zero\n");
}
else
{
printf("\n Division of %d  and %d is:  %d",num1,num2,num1/num2);
}
break;

default:
printf("\n Enter correct option\n");
}

return 0;
}
```

Output

```Enter the first Integer: 10
Enter the second Integer: 20
Enter an correct option -> 1:addition 2: subtraction 3: multiplication 4: division ->  3

Multiplication of 10  and 20 is:  200
```

### Types of Algorithm

1. Divide and conquer algorithm
2. Greedy algorithm
3. Dynamic programming
4. Branch and bound algorithm
5. Back Tracking
6. Simple Recursive algorithm
7. Randomized algorithm
8. Brute force algorithm

This was just the basic understanding of algorithm world. Read more articles/tutorials on Algorithms.

What's New

Top Interview Coding Problems/Challenges!

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates