Joe - You are right. The condition is (x == y), not (y == 0) > I think that you have one recursive call too many in your > problem #2 > walkthrough shown below. I follow your explanation down to the > recursive call "return g( 2, 2)", but after that you have another > recursive call "return g( 2, 0)" that I don't think belongs > there. The > recursive call g( 2, 2 ) gives the base case, where x == y. > Therefore, > the only thing that should be after g( 2, 2 ) is return 2. Am I > correct, or in a state of deep confusion? > > Joe Weber > > > > Jeff Parker wrote: > > >[2] The recursive function g is defined as follows: > > > > int g(int x, int y) { > > if (x == y) > > return x; # Line 3 > > else if (x < y) > > return g(x, y - x); # Line 5 > > > > return g(y, x); # Line 7 > > } > > > > What does g(10,6) return? > > > > g(10,6) > > return g(6, 10) > ># line 7 > > return g(6, 4) > ># Line 5 > > return g(4,6) > ># Line 7 > > return g(4,2) > > return g(2,4) > > return g(2,2) > > return > >g(2,0) > > > >return 2 # Line 3 > > > >This is Euler's algorithm to find the Greatest Common Divisor. > >This is the oldest know description of an algorithm we know. > > > >- jdp > > > >