0 votes 0 votes What is the time complexity? i=n; while(i>0) { k=1; for(j=1;j<=n;j+=k) k++; i=i/2; } a) O(n2) b) O(n logn) c) O(log2n) d) O(logn n1/2 Sambhrant Maurya asked Aug 3, 2018 • edited Aug 3, 2018 by srestha Sambhrant Maurya 173 views answer comment Share Follow See 1 comment See all 1 1 comment reply Anand. commented Aug 3, 2018 reply Follow Share outer loop will run for $\log n$ times calculating # itteration of inner loop $j=1$ $j=1+2$ $j=1+2+3$ $j=1+2+3+4$ $j=1+2+3+4+5$ till $1+2+3+4+...x $ becomes $n$ $\frac{x \times (x+1)}{2} =n$ $x\approx \sqrt(n)$ hence complexity$=O(\log n \sqrt(n))$ 0 votes 0 votes Please log in or register to add a comment.