I'm given the pseudocode of an algorithm:
1 for i=1 to n //n times
2 j=2^i //n times
3 while j>=2 //2+3+....? times
4 j=j/2 //1+2+....? times
Where 'to' means less than or equal to, and where '^' means power of.
I'm quite the sure that the first two lines run n times, however I'm not quite sure how to compute the other two lines.
I know that line 3's first two values would be 2... then 3, but I'm not sure what to do next there.
Same goes along with line 4, the first two values being 1.. then 2, but then I have no idea how to continue.
I'm told that the answer is O(n^2)
, where I have to add up all the lines to get the actual result.
Any ideas?