• edited by
1,516 views
1 1 vote

1 Answer

Best answer
10 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
Position:
Show:

Related questions

1 1 vote
2 2 answers
1.8k
1.8k views
akankshadewangan24 asked Sep 20, 2018
1,779 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 0 votes
3 3 answers
3.4k
3.4k views
Subham Nagar asked Mar 20, 2018
3,401 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 0 votes
0 0 answers
760
760 views
Kai asked Jan 29, 2017
760 views
Time complexity of the given program is?
2 2 votes
1 answers 1 answer
1.9k
1.9k views
Tushar Shinde asked Jan 24, 2016
1,882 views
Which of the following statement is true?Binary insertion sorting (insertion sort that uses binary search to find each insertion point) requires $O (n \log n)$ total oper...