Skip to main content

As I know java doesn't supportsJava doesn’t support tail recursion optimization in general, but you can test it for your case,Java implementation for it; if it doesn't supportsdoesn’t support it, a simple for loopfor-loop should be faster else they are same, otherwise recursion should be just as eachfast. On the other hand, but these are bit optimizationoptimizations, choose the onecode you think is easier and more readable. 

I should also note that the fastest GCD algorithm is not euclideanEuclid’s algorithm, Lehmer'sLehmer’s algorithm is a bit faster.

As I know java doesn't supports tail recursion optimization in general, but you can test it for your case, if it doesn't supports, simple for loop should be faster else they are same as each other, but these are bit optimization, choose the one you think is easier and more readable. I should note that fastest GCD algorithm is not euclidean algorithm, Lehmer's algorithm is a bit faster.

As I know Java doesn’t support tail recursion optimization in general, but you can test your Java implementation for it; if it doesn’t support it, a simple for-loop should be faster, otherwise recursion should be just as fast. On the other hand, these are bit optimizations, choose the code you think is easier and more readable. 

I should also note that the fastest GCD algorithm is not Euclid’s algorithm, Lehmer’s algorithm is a bit faster.

Source Link
user742
user742

As I know java doesn't supports tail recursion optimization in general, but you can test it for your case, if it doesn't supports, simple for loop should be faster else they are same as each other, but these are bit optimization, choose the one you think is easier and more readable. I should note that fastest GCD algorithm is not euclidean algorithm, Lehmer's algorithm is a bit faster.