java - Worst case Analysis On a loop -
I have written this loop but I am having trouble analyzing the complexity of time in its worst condition.
for (int i = 0) ; I and lieutenant; Primenzas Size () - 1; I ++) {Prime = Prime. Zest (I); If (prime; <= factor) {if (factor% prime == 0) {factor = factor / prime; divisors.add (prime); I = 0; } If break (factor & lieutenant; = 3); } And break; The most important scenario: the factor is the key.
That's why we'll always brake directions.
and the cycle will be implemented primeNumbers.size () bar. Now we should evaluate primeNumbers.size () . This is = O (n / ln n) . We ensure that the number of calculations will be reduced in the form (if factor% prime == 0) statement.
If we go there then it will mean that factor = p * m . So we O (p / Ln (p) + m / ln (m)) = O ((p * ln (m) + m / ln (p)) / (ln ( m) * ln (p))) & lt; O ((p * m) / (ln (m) * ln (p))) & lt; O ((p * m) / (ln (m) + ln (p))) = O (p * m / ln (m * p)) = < Code> O (n / lnn) . >> By dividing this way we reduce the number of calculations.
Comments
Post a Comment