Prime Factorization Time Complexity

AI Thread Summary
The discussion centers on the time complexity of prime factorization algorithms, particularly the simple method of dividing a number by integers up to its square root. While the initial assumption was that this method could yield a time complexity of sqrt(n) log(n), participants clarify that the complexity should be viewed in terms of the number's representation size, leading to an exponential complexity of O(2^n n). The conversation highlights that although prime factorization is generally exponential, it is also recognized as subexponential with algorithms like the number field sieve achieving L(1/3) complexity. Participants agree on the importance of understanding the representation size in determining algorithm efficiency. The thread concludes with a realization of the underlying complexities involved in prime factorization.
gchadwick
Messages
2
Reaction score
0
While I know the time complexity for all known prime factorization algorithms is exponential, I can't seem to get this results for a very simple algorithm.

First assume we're doing this with numbers that are simply the product of two primes (the kind you get when working with RSA and others) a very simple way to do it is to simple divide the number you're trying to factorize, n by every number between 2 and sqrt(n) and seeing which two leave no remainder. If we then say that the division has a time complexity of o(a) where a is the number of digits we can work out the time complexity of factorization by a simple sum, log(n) + log(n) + log(n) + ... + log(n) (where log(n) will be the number of digits in n) the sum will have sqrt(n) terms in giving sqrt(n) log(n) however that is clearly the wrong result, so can anyone tell me where I'm going wrong? I'm sure it's something obvious I just can't see it.
 
Physics news on Phys.org
gchadwick said:
While I know the time complexity for all known prime factorization algorithms is exponential

Are you sure about that? If you're correct then I have the same stumbling block as you, because even an algorithm that tests all numbers 1 to N would only have a run time of NlogN
 
If you're correct then I have the same stumbling block as you, because even an algorithm that tests all numbers 1 to N would only have a run time of NlogN]
That is an exponential algorithm: the complexity of number theoretic algorithms is usually described in terms of the size of the representation of the numbers involved, rather than the size of the numbers themselves.

It takes n = lg N bits to store the number N, and so this algorithm runs in time:

O(2^{\mathop{\text{lg}} N} \mathop{\text{lg}} N)<br /> = O(2^n n)

and is thus exponential.


That said, prime factorization is known to be subexponential: The number field sieve is an L(1/3) algorithm. See Wikipedia's or Mathworld's page for reference.
 
Last edited:
  • Like
Likes WWGD
Ahh that makes sense, I knew it was something obvious, thanks :)
 

Similar threads

Back
Top