While studying for coding interviews, I came up with a very neat example that I want to share with everyone. The question is to code a program that finds the greatest common divisor given two positive integers without invoking multiplication, division, and modulus operators.

The easiest way perhaps is to use Euclidean algorithm but that is just too slow. So, the following is a bit faster algorithm called binary GCD:

The code above is my variant of binary gcd found in here. It is a bit harder to read but perhaps a bit faster though.

## No comments:

## Post a Comment