edited by
743 views
1 votes
1 votes

edited by

1 Answer

Best answer
10 votes
10 votes
i loop is executing $\Theta(n)$ times.

j loop is executing $\Theta(\log n)$ times for each i. (So, time complexity must for code must be $\Omega(n \log n)$

But it is not straight forward to count the no of iterations of k loop as it depends on the value of j. So, we can see the values of j which goes like 1, 2, 4, ... n. So, no. of iterations of k loop (over all j values) will be $\sum_{j=0}^{\lg n} 2^j = 2^{\lg n +1} =  \Theta(n)$. And this is over all j loops (not including i). Including i loop we get time complexity as $\Theta\left(n^2 \right).$
selected by

Related questions

1 votes
1 votes
2 answers
1
akankshadewangan24 asked Sep 20, 2018
869 views
If t(n) and s(n) denotes the time and space complexity of an algorithm with input size n element then which one of the following is always true?S(n)=O(t(n)) correct H...
0 votes
0 votes
3 answers
2
Subham Nagar asked Mar 20, 2018
1,246 views
An array $'A'$ has $n$ distinct integers. What is the tightest time complexity to check $A[i]=i$ for some $i$. Consider all elements of array within range from $1$ to $n$...
0 votes
0 votes
0 answers
3
Kai asked Jan 29, 2017
438 views
Time complexity of the given program is?
2 votes
2 votes
1 answer
4