# What is an Algorithm | Introduction to Algorithms

Algorithms: In this tutorial, we will learn about algorithms, what is an algorithm, its properties, notations, and examples. By Mansha Lamba Last updated : August 12, 2023

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 with the tutorial on algorithms.

## 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

The following are the main 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

**Name of the algorithm:**It should specify the problem to be solved.**Step no.:**It is an identification tag ( step numbering ) that specify the numbering of steps/statements. It is a positive integer.**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.**Termination:**Generally it is a STOP statement and the last statement of an algorithm that denoted ending of the algorithm.

## Algorithm Example

**Algorithm for addition of two numbers:**

ADD( A , B ) Step 1: Read 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

## Algorithm implementation using C language

#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 Algorithms

- Divide and conquer algorithm
- Greedy algorithm
- Dynamic programming
- Branch and bound algorithm
- Back Tracking
- Simple Recursive algorithm
- Randomized algorithm
- Brute force algorithm

Related Tutorials

- Introduction to Greedy Strategy in Algorithms
- Stability in sorting
- External Merge Sorting Algorithm
- Radix Sort and its Algorithm
- Bucket Sort Algorithm
- Bubble sort Algorithm, Flow Chart and C++ Code
- Insertion sort Algorithm, flowchart and C, C++ Code
- Merge Sort | One of the best sorting algorithms used for large inputs
- Binary Search in C, C++
- Randomized Binary Search
- Meta Binary Search | One-sided Binary Search
- Difference between Linear Search and Binary Search
- Binary Search in String
- Variants of Binary Search
- Sieve of Eratosthenes to find prime numbers
- Optimal Merge Pattern (Algorithm and Example)
- Given an array of n numbers, Check whether there is any duplicate or not
- Finding the missing number
- Find the number occurring an odd number of times
- Find the pair whose sum is closest to zero in minimum time complexity
- Find three elements in an array such that their sum is equal to given element K
- Bitonic Search Algorithm
- Check whether a number is Fibonacci or not
- Segregate even and odd numbers in minimum time complexity
- Find trailing zeros in factorial of a number
- Find Nearest Greatest Neighbours of each element in an array
- Interpolation search algorithm
- Floor and ceil of an element in an array using C++
- Two Elements whose sum is closest to zero
- Find a pair with a given difference
- Count number of occurrences (or frequency) in a sorted array
- Find a Fixed Point (Value equal to index) in a given array
- Find the maximum element in an array which is first increasing and then decreasing
- Dynamic Programming (Components, Applications and Elements)
- Algorithm for fractional knapsack problem
- Algorithm and procedure to solve a longest common subsequence problem
- Dynamic Programming (Components, Applications and Elements)
- Find the Nth Fibonacci number | C++
- Longest Common Subsequence using Dynamic programming (DP)
- Longest Increasing Subsequence using Dynamic programming (DP)
- Find the maximum sub-array sum using KADANE'S ALGORITHM
- Non-intersecting chords using Dynamic Programming (DP)
- Edit Distance using Dynamic Programming (DP)
- Finding Ugly Number using Dynamic Programming (DP)
- Egg dropping problem using Dynamic Programming (DP)
- Wild card matching problem using Dynamic programming (DP)
- Compute sum of digits in all numbers from 1 to N for a given N
- Minimum jumps required using Dynamic programming (DP)
- Graph coloring problem's solution using backtracking algorithm
- Breadth First Search (BFS) and Depth First Search (DFS) Algorithms
- Travelling Salesman Problem
- Kruskal's (P) and Prim's (K) Algorithms
- Multistage graph problem with forward approach and backward approach algorithms
- Floyd Warshall algorithm with its Pseudo Code

- Backtracking (Types and Algorithms)
- 4 Queen's problem and solution using backtracking algorithm
- N Queen's problem and solution using backtracking algorithm
- Find the GCD (Greatest Common Divisor) of two numbers using EUCLID'S ALGORITHM
- Compute the value of A raise to the power B using Fast Exponentiation
- Implement First Come First Served (FCFS) CPU Scheduling Algorithm using C program
- Implementations of FCFS scheduling algorithm using C++
- Implementation of Shortest Job First (SJF) Non-Preemptive CPU scheduling algorithm using C++
- Implementation of Shortest Job First (SJF) Preemptive CPU scheduling algorithm using C++
- Implementation of Priority scheduling (Pre-emptive) algorithm using C++
- Implementation of Priority scheduling (Non Pre-emptive) algorithm using C++
- Implementation of Round Robin CPU Scheduling algorithm using C++
- Analysis of LRU page replacement algorithm and Belady's anomaly
- Branch and Bound
- Find the roots of a complex polynomial equation using Regula Falsi Method in C
- Sieve of Eratosthenes to find prime numbers
- Implementations of FCFS scheduling algorithm using C++
- Implementation of Shortest Job First (SJF) Non-Preemptive CPU scheduling algorithm using C++
- Implementation of Shortest Job First (SJF) Preemptive CPU scheduling algorithm using C++
- Implementation of Priority scheduling (Pre-emptive) algorithm using C++
- Divide and Conquer Paradigm (What it is, Its Applications, Pros and Cons)
- Implementation of Priority scheduling (Non Pre-emptive) algorithm using C++
- Implementation of Round Robin CPU Scheduling algorithm using C++
- Jump Search Implementation using C++
- Optimal Merge Pattern (Algorithm and Example)
- Introduction to Greedy Strategy in Algorithms
- Strassen's Matrix Multiplication in algorithms
- Huffman Coding (Algorithm, Example and Time complexity)
- Backtracking (Types and Algorithms)
- 4 Queen's problem and solution using backtracking algorithm
- N Queen's problem and solution using backtracking algorithm
- Graph coloring problem's solution using backtracking algorithm
- Tournament Tree and their properties
- Deterministic and Non Deterministic Algorithms
- Lower Bound Theory
- Non Recursive Tree Traversal Algorithm
- Line Drawing Algorithm
- Breadth First Search (BFS) and Depth First Search (DFS) Algorithms
- P and NP problems and solutions | Algorithms
- Travelling Salesman Problem
- 2 – 3 Trees Algorithm
- Kruskal's (P) and Prim's (K) Algorithms
- Algorithm for fractional knapsack problem
- Algorithm and procedure to solve a longest common subsequence problem
- Midpoint Circle Algorithm
- Multistage graph problem with forward approach and backward approach algorithms
- Floyd Warshall algorithm with its Pseudo Code
- Reliability design problem
- Removing consecutive duplicates from a string
- Fast Exponentiation using Bitmasking

Comments and Discussions!