Order Of Growth complicated for loops
For the following code fragment, what is the order of growth in terms of N? int sum = 0; for (int i = 1; i <= N; i = i*2) for (int j = 1; j <= N; j = j*2) for (int k = 1; k <= i; k++) sum++; I have figured that there is lgN term, but I am stuck on evaluating this part : lgN(1 + 4 + 8 + 16 + ....). What will the last term of the sequence be? I need the last term to calculate the sum. You have a geometric progression in your outer loops, so there is a closed form for the sum of which you want to take the log: 1 + 2 + 4 + ... + 2^N = 2^(N+1) - 1 To be precise, your sum is 1 + ... + 2^(floor(ld(N)