algorithm - How can I find the complexity of this code segment? -


here's pseudocode of code segment i'm talking about,

temp = 1  repeat   = 1 n     temp = temp+1;    n = n/2; until n<=1 

i know outer loop (repeat) executes n times. loop? can taken recursive call n/2 ? how can apply master theorem here?

at first iteration of outer loop, inner loop executed n times. @ next iteration, inner loop executed n/2 times, , on...

so, have sum of geometric series n + n/2 + n/4 + ... i.e. 2*n or o(n).


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -