Algorithms

2 flashcards · Programming Languages · by omprakash201194

  1. Algorithm ?

    The term algorithm is used in computer science to describe a finite, deterministic, and effective problem-solving method suitable for implementation as a computer program.

  2. Euclid’s algorithm for finding the greatest common divisor of two numbers Compute the greatest common divisor of two nonnegative integers p and q as follows: If q is 0, the answer is p. If not, divide p by q and take the remainder r. The answer is the greatest common divisor of q and r

    public static int gcd(int p, int q) { if (q == 0) return p; int r = p % q; return gcd(q, r); }