Algorithms: Way of Solving well-specified computational problem.
OR
Sequence of operation for solving a specific problem.
Euclid's Algorithm:
Used to find Greatest Common Divisor(GCD) of two positive integers.
Consider two positive integers m and n , m>n.
Step 1: Divide m by n, and let the remainder be r
Step 2: if r = 0 the algorithm ends, n is the GCD.
Step 3: If r is not 0 then, Set m = n; and n = r, go back to step1 and continue till, r = 0.
Note: This is a recursive algorithms as it calls over and over.
/**
* This method takes two positive integers and finds their * GreatestCommonFactor(GCD) using
* Euclid's algorithm
* @param a
* @param b
* @return
*/
public int greatestCommonFactor(int a, int b){
if(b == 0) return a;
return greatestCommonFactor(b, a%b);
}
Recursion Algorithm:
Merge Sort: A recursive algorithm for sorting large set of data.We merge two unsorted arrays.
This is a merge sort diagram and flow structure.
For more details :
https://www.hackerearth.com/practice/algorithms/sorting/merge-sort/tutorial/
OR
Sequence of operation for solving a specific problem.
Euclid's Algorithm:
Used to find Greatest Common Divisor(GCD) of two positive integers.
Consider two positive integers m and n , m>n.
Step 1: Divide m by n, and let the remainder be r
Step 2: if r = 0 the algorithm ends, n is the GCD.
Step 3: If r is not 0 then, Set m = n; and n = r, go back to step1 and continue till, r = 0.
Note: This is a recursive algorithms as it calls over and over.
/**
* This method takes two positive integers and finds their * GreatestCommonFactor(GCD) using
* Euclid's algorithm
* @param a
* @param b
* @return
*/
public int greatestCommonFactor(int a, int b){
if(b == 0) return a;
return greatestCommonFactor(b, a%b);
}
Recursion Algorithm:
Merge Sort: A recursive algorithm for sorting large set of data.We merge two unsorted arrays.
This is a merge sort diagram and flow structure.
For more details :
https://www.hackerearth.com/practice/algorithms/sorting/merge-sort/tutorial/
You are welcome.
ReplyDelete