Time complexity Analysis for loop: -


why time complexity, o(n) instead of o(nlogn)? wouldn't have multiply complexity of outer loop of inner loop?

    int fun(int n){     int count = 0;     (int = n; > 0; /= 2)         (int j = 0; j < i; j++)             count += 1;     return count;     } 

in first iteration of loop inner loop covers half of n. next iteration covers quarter, eighth, , forth. can represent coefficients function below. can see it's infinite series sums one. entire function o(n)

infinite geometric series of 1 on 2 n


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -