0

I'm trying to understand the time complexity of the following code in terms of n.

Pseudocode for trial division:

Pseudocode for trial division

I understand that the time complexity of the algorithm is O(sqrt(N)). However, can someone explain how the person in the link below came up with O(e^(n/2)). In other words, what's the mathematical relationship between N and n? Thanks.

Time complexity explanation:

Time complexity explanation

D.W.
  • 167,959
  • 22
  • 232
  • 500

1 Answers1

2

The integer $N$ takes $\log_2 N$ bits to write down. Set $n = \log_2 N$. Then $N = 2^n$, so $\sqrt{N} = 2^{n/2}$.

I'd guess they are using the natural logarithm (to base $e$), which is where they get $e$ instead of $2$. That's a bit odd but I suppose it is valid.

See also Complexity of multiplication and Precise runtime of the algorithm to find number of digits in an integer.

D.W.
  • 167,959
  • 22
  • 232
  • 500