I have two snippets of code that I am having a lot of trouble with finding the closed form Summations and time complexities for:
x=0;
for(i=1;i< pow(2,N); i = 2*i + 2){
for(j=1;j
Here's a hint for the first one.
The first step is to indent the code better so you can see what's happening.
for (i = 1; i < pow(2,N); i = 2*i+2)
{ for(j = 1; j < N; j+1)
x = x +j;
}
For each value of i the j loop does (N-1) additions, so the number of additions required is N-1)*the number of different values of i. The values of i that the program uses are 1, 4, 10,..22.. stopping at the biggest term that's < 2^N.
The k'th value of i is 3*2^(k-1)-2. (You figure out where I got this.) Then the biggest value of k for which this term is < 2^N is.....You finish up.
murschech
Junior Poster in Training
60 posts since Dec 2004
Reputation Points: 21
Solved Threads: 1