Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7980539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:06:18+00:00 2026-06-04T10:06:18+00:00

I have this weird kind of error. I am trying implement basic Euclidean algorithm

  • 0

I have this weird kind of error.

I am trying implement basic Euclidean algorithm using the BigInteger class as shown. When i run it, it throws StackoverFlowError, while if i debug it, it runs through correctly and gives me the correct answer.

I seriously dont understand the difference during debug and normal run.

      static BigInteger gcd(BigInteger a, BigInteger b) {
        if (a.equals(BigInteger.ZERO)) {
            return b;
        } else if (b.equals(BigInteger.ZERO)) {
            return a;
        }
        BigInteger max = a.max(b);
        BigInteger min = a.min(b);
        return gcd(max.subtract(min), min);
      }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T10:06:19+00:00Added an answer on June 4, 2026 at 10:06 am

    This is not the Euclidean algorithm for GCD. The correct GCD algorithm can be easily stated as a recursive procedure because the number of iterations is in practice small. But this incorrectly implemented algorithm can run for millions of iterations, e.g. if ‘a’ is 1,000,000 and ‘b’ is 1, which results in one million recursive calls.

    (However, the call is a tail recursive call so a good Java implementation would actually optimize away the stack frame. However, it seems this does not happen here. Although for some unknown reason the debugger version could implement tail call optimization, though that sounds odd.)

    In the actual algorithm, the recursive step is (a % b, b) instead of (a – b, b). Google for “euclid GCD algorithm”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is kind of weird problem. I have been using HttpWebRequest for a long
This is kind of a weird problem, but I have to create a search
I'm having this very weird where i'm using rmtree(C:\myfolder); and it's throwing some kind
I have this weird issue with special characters. In JSP, I am using field
I have this weird problem with setting up cookies with PHP. Everything worked fine
this seems to be weird but it really happened. I have this code working
This is a weird problem I have started having recently. My team is developing
This could be weird, Have you ever come across a blog which you wanted
This is pretty weird. I have my Profiler open and it obviously shows that
This one is weird, I have a page that consists of a html table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.