retagged by
223 views

1 Answer

Best answer
3 votes
3 votes

See for 

i = 1 , j runs 1 time 

i = 2 , j runs 2 times

i = 4 , j runs 4 times

..

So like this we will have logn terms till we reach i = n as i is doubled everytime..

So 

T(n)  =  1 + 2 + 4 ...............logn terms

        =  1(2logn - 1) / (2-1)

        =   O(n)

Hence the time compexity of above code is O(n)..

selected by

Related questions

0 votes
0 votes
0 answers
2
0 votes
0 votes
1 answer
3
NeelParekh asked Jul 27, 2023
277 views
If an array is split in the form of increasing and decreasing order then what is TC to find minimum element in the array?
2 votes
2 votes
1 answer
4
h4kr asked Dec 30, 2022
466 views
What is the correct time complexity in $\theta()$ ?