| re: Time Complexity
While I agree with others here that its your homework and asking someone else for the answer is not the same as "research", I am big on trying to get people to think for themselves. Going to a calculator to solve 2+2 is why store clerks can't give change now days.
So I might suggest... Look at the formula, walk through it and think for yourself. This is not a process of quantum string theory; its a darn simple loop.
for(int i=0; i<n; i*=2){
/* O(1) steps
}
First it won't compile because you have started comments in the second line without ending the comments, so the closing brace is still a comment.
Second... What is the initialization of the loop saying?
'Start with i equal to zero, continue as long as i is less than n, for each iteration double the value of i'
Third.. Walk through the loop in your head. See it. Seeing what the code is doing to to values/variable is vital to coding. If you don't see it you can't write it or fix it. What will happen when i is 2, 3, 4?
|