I apologize if this is a duplicate question (believe me, I've searched). This question is a part of an ungraded class warm-up exercise.
Question:
Using induction, prove that for all positive integers $x$ and $y$, that $g(x,y)$ computes the GCD of $x$ and $y$:
$$g(x,y) = \left\{\matrix{x & \text{ if }~~~x=y\\g(x-y,y) & \text{ if }~~~ x>y\\g(x,y-x) & \text{ if }~~~x Edit: Apparently, knowing how to do this problem is a prerequisite for the class, which is stressing me out because I have never encountered an induction proof like this, and I really don't want to drop the class if I don't have to.
Since this is a piecewise function, the base case confuses me. Am I supposed to do three separate base cases here? Also, the fact that this is recursive is not helping.
The first thing I would do is the base case where x and y equals 1, so: gcd(1,1) = 1 since x=y.
From there I don't really know where to go.
No comments:
Post a Comment