You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
functionprimeFactors(n){// Print the number of 2s that divide nwhile(n%2==0){console.log(2);n=n/2;}// n must be odd at this point. So we can skip one element// (Note i = i +2)for(vari=3;i*i<=n;i=i+2){// While i divides n, print i and divide nwhile(n%i==0){console.log(i);n=n/i;}}// This condition is to handle the case when n is a prime number// greater than 2if(n>2){console.log(n);}}
This function has Big-O =
In your book you put it sqrt(x) only, but inside of the for loop there is another loop while, that has Big-O = log (x). Am I correct?
The text was updated successfully, but these errors were encountered:
This function has Big-O =
In your book you put it sqrt(x) only, but inside of the
for
loop there is another loopwhile
, that has Big-O = log (x). Am I correct?The text was updated successfully, but these errors were encountered: