I have to design a recursive version of the euclidean algorithm.
The Euclidean algorithm finds the GCD of 2 possible intergs X and Y.
As long as the value of neither X nor Y is 0, continue dividing the larger of the values by the samller and assigning X and Y the avlues of the divior and remainder respectivly. The finals value of X is the GCD
function gcd is:
input: integer x, integer y such that x >= y and y > 0
1. create new variable called remainder
2. begin loop
1. if y is zero, exit loop
2. set remainder to the remainder of x/y
3. set x to y
4. set y to remainder
5. repeat loop
3. return x
end gcd
is this correct???
recursive
Page 1 of 13 Replies - 1828 Views - Last Post: 10 April 2010 - 08:35 PM
Replies To: recursive
#2
Re: recursive
Posted 10 April 2010 - 05:31 PM
Recursion is what you get when the body of a method calls its self.
So does your algorithm, do that?
So does your algorithm, do that?
#3
Re: recursive
Posted 10 April 2010 - 05:46 PM
Euclidean algorithm can be found all over the Internet, iterative or recursive.
#4
Re: recursive
Posted 10 April 2010 - 08:35 PM
In fact, you do not have to go far for a recursive example, as I have written a Java snippet for Euclidean GCF Using Recursion. Feel free to check it out and use it as a model.
Page 1 of 1

New Topic/Question
Reply



MultiQuote







|