Time complexity

What will be the time complexity for each step in this snippet?

for(i=1; i<n; i=i+i)
{ for(j=0; j<log i; j++)
{ x++; } }

// for i = 1 while is less than n; i = i + i;
what is n?
Last edited on
n can be any natural number given by the user like 2,3,6,10,100 , etc.
It doesn't matter what n is. What matters is n→infinity.

The outer loop's time complexity is O(n), right? (i=1..n)

The inner loop's time complexity is dependent on n → j=0..log(n) → O(log n).

Nested loops multiply, so your complexity is O(n log n).
Topic archived. No new replies allowed.