Skip to main content
4 of 6
fixed typos
François G. Dorais
  • 44.4k
  • 6
  • 150
  • 233

BigO of finding the GCD of a set S as a function of sum(S)

The algorithm to be used is:

  • Sort the set into assenting order
  • $x_1 = s_1$
  • $x_i = gcd(x_{i-1},s_i)$
  • $GCD = x_n$

What I'm looking for is expected run time as a function of $\sum_{i\in S}i$

As a starting point $|S| \leq \sum_{i\in S} i$ and gcd is $O(ln(n))$ so an upper bound should be $O(n\ln(n))$.

BCS
  • 205
  • 2
  • 8