Assuming standard algorithms, the difficulties are:
pow() : O( M(n * exponent) ) IsProbablePrime() : O( M(n) * n )
Where:
n is the number of digits in the operand.exponent is an exponent of a power function.M(n) is the runtime to multiply the digits nxn . I believe O(n^2) compared to Java 6.
Explanation for pow() :
For an input operand with n-characters long, increased to exp , the output will be approximately n * exp digits long. This is done by the binary power algorithm, where the operand is quadratized at each iteration. Thus, the complexity becomes:
O( M(n) + M(2*n) + M(4*n) + ... M(n * exp/2) ) = O( M(n * exp) )
This is a geometric sum, so the sum becomes O( M(n * exp) ) .
Explanation for IsProbablePrime() :
For a fixed number of Rabin-Miller iterations, each iteration has O(n) multiplication digits nxn . Therefore, the complexity becomes O( n * M(n) ) .
source share