Skip to main content
6 of 6
changed title
Kevin H. Lin
  • 21k
  • 10
  • 116
  • 190

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

The algorithm to be used is:

  • Sort the set into ascending 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