Algorithms

Role of Algorithms - 

Algorithms are basically sets of instruction required to perform a task, representation of algorithm is called as program.
The process of encoding the program into machine and inserting it into machine making sure it is according to the machine's capabilities is called as programming.
The algorithm can be encompassed or summarized into "Specific instructions required to solve specific problems", One can simply follow the instruction in the algorithm to approach 
at the solution rather than knowing the whole concept required to solve the problem.
How does that helps in the case of the computers ?
As computer operates on limited memory and resource, it is very necessary to solve the problem efficiently and in the minimum consumption of resources possible,
algorithm exactly allows to solve that.

Study of Algorithm began as a separate branch in mathematics when Kurt Godel published - "Incompleteness Theorem" which reflected that any mathematical theorem containing 
traditional arithmetic system has certain statements whose truth value or falseness cannot be made certain completely and lies beyond the scope of algorithm provided.

There is need in computing to provide the solution that runs in less time and requires minimum amount of memory to be performed.
These factors can be encompassed into 'asymptotic notations', asymptotic notations are the functions that tells us the growth of a function according to the input size
and time taken.

Study of Algorithm began as a seperate branch in mathematics when Kurt Godel published - "Incompleteness Theorem" which reflected that any mathematical theorem containing 
traditional arithmetic system has certain statements whose truth value or falseness cannot be made certain completely and lies beyond the scope of algorithm provided.

There is need in computing to provide the solution that runs in less time and requires minimum amount of memory to be performed.
These factors can be encompassed into 'asymptotic notations', asymptotic notations are the functions that tells us the growth of a function according to the input size
and time taken.

Lets look at one example of an algorithm-
Algorithm for finding the GCD of two numbers-
1]Input two numbers in a and b.
2]Divide a and b and store the remainder in a variable called r.
3]If r is not zero, then assign a the value of b (a=b), assign b value of r (b=r), repeat the step two until remainder is zero and the value of GCD is b

CODE-
#include<iostream>
using namespace std;
int GCD(int m,int n)
{
    int R=m%n;
    if(R==0)
    {
        return n;
    }
    else
    {
        return GCD(n,R);
    }
}
int main()
{
    int a,b,r;
    cout<<"Enter the first number -"<<endl;
    cin>>a;
    cout<<"Enter the second number"<<endl;
    cin>>b;
    cout<<"GCD of "<<a<<" and "<<b<<" is "<<GCD(a,b);
    return 0;
}




Output -

Enter the first number -
15
Enter the second number
9
GCD of 15 and 9 is 3


The time complexity of this algorithm is O(log(min(a,b)).

                                                                                                                                                              




Comments