Skip to content

Conversation

@Nugine
Copy link

@Nugine Nugine commented May 12, 2019

Another implemention of exgcd

Copy link
Owner

@EbTech EbTech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!

I prefer not to merge in duplicate functionality, though I might be persuaded otherwise. As for why recursive vs iterative, all else being equal I appreciate the stack frame saving benefit of iteration. However, in this case the recursion is relatively shallow, while the iterative solution costs us in terms of code size and number of mutable variables.

@Nugine
Copy link
Author

Nugine commented May 24, 2019

Reference:
http://anh.cs.luc.edu/331/notes/xgcd.pdf
http://math.cmu.edu/~bkell/21110-2010s/extended-euclidean.html

The iterative version is based on a algorithm different from the recursive version. For the purpose of education, I prefer to maintain both of them.
In fact, The two versions have the same time complexity. Iteration does save time and memory, although the improvement is not obvious.

@EbTech EbTech force-pushed the master branch 5 times, most recently from 96920d7 to 8148cf2 Compare June 1, 2019 08:32
@Nugine Nugine closed this Jun 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants