3 Replies - 1828 Views - Last Post: 10 April 2010 - 08:35 PM

#1 polska03   User is offline

  • D.I.C Regular

Reputation: 5
  • View blog
  • Posts: 302
  • Joined: 28-November 09

recursive

Posted 10 April 2010 - 04:42 PM

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???

Is This A Good Question/Topic? 0
  • +

Replies To: recursive

#2 AdamSpeight2008   User is offline

  • MrCupOfT
  • member icon

Reputation: 2298
  • View blog
  • Posts: 9,535
  • Joined: 29-May 08

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?
Was This Post Helpful? 0
  • +
  • -

#3 Galois   User is offline

  • D.I.C Head

Reputation: 28
  • View blog
  • Posts: 207
  • Joined: 27-March 10

Re: recursive

Posted 10 April 2010 - 05:46 PM

Euclidean algorithm can be found all over the Internet, iterative or recursive.
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12800
  • View blog
  • Posts: 45,992
  • Joined: 27-December 08

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. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1