I promise this is the last Big O question
Big O Notation for following loops…
for (int i = n; i > 0; i = i / 2){
for (int j = 0; j < n; j++){
count++;
}
}
for (int k = 0; k < n; k++){
for (int m = 0; m < n; m++){
count++;
}
}
here is what i think im sure of.
the first set of nested loops has O(n*log2(n)) and the second set of nested loops is O(n^2). When adding these is it correct to drop the first term? and say that the overall Big O is O(n^2)?
Second question, when adding Big O notation for loops in series is always correct to drop the less significant terms?
The answer to both your questions is yes. You always drop smaller terms, as they are dominated by the larger terms for sufficiently large
n, and you only care about largenwhen doing Big O analysis.