1. Computer Science Engineering (CSE)
  2. Design and Analysis of Algorithms
  3. What is the GCD of a and b?
Q.

What is the GCD of a and b?

A. a + b
B. gcd (a-b, b) if a>b
C. gcd (a+b, a-b)
D. a – b
Answer» B. gcd (a-b, b) if a>b
Explanation: as per euclid’s algorithm, gcd (a, b) = gcd (a-b, b) if a > b or gcd (a, b) = gcd (a, b-a) if b > a.

Discussion