@Sachin: When you use ^ as an operator in C, it is exclusive or. So
the sequence of k values will be

0
0 + 2^0 = 0 + 2 = 2
2 + 2^2 = 2 + 0 = 2
2 + 2^2 = 2 + 0 = 2
...

so the loop will never end if n > 2.

If ^ means "to  the power of," then the sequence of k values will be

0
0 + 2^0 = 0 + 1 = 1
1 + 2^1 = 1 + 2 = 3
3 + 2^3 = 3 + 8 = 11
11 + 2^11 = 11 + 2048 = 2059
2059 + 2^2059 = a number bigger than an int, but the part that doesn't
overflow = 2059.
2059
2059
...

so if k is an int, the loop never terminates if n > 2059.

Dave

On Aug 25, 12:46 pm, sachin sabbarwal <algowithsac...@gmail.com>
wrote:
> what will be the time complexity??
>
> sum=1
> for(k=0; k<n;  k = k+2^k)
>     sum=sum+sum;
> end
> print(sum);

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to