Finding the time complexity

54 Views Asked by At

Can someone please help me to solve this problem.
Find a $\theta$ notation for the number of times $x=x+1$ is executed

i=1;
j=0;
while(j<n)do
    begin
    i=2i+1;
    j=j+i;
    x=x+1;
end
1

There are 1 best solutions below

0
On

Trace through the code and see for small $n$. Or even better, just run the code in your programming language of choice. Notice that the number of times will just be equal to the final value of $x$, if you initialize $x$ to 0. Try running it for various values of $n$ and see how it grows.