retagged by
2,004 views
0 votes
0 votes

 

 

retagged by

2 Answers

0 votes
0 votes
For purpose of solving I am assuming that n=2$^{c}$ where c>1

1) outer loop or i$^{th}$ loop will execute (log n) times

2) middle loop or j$^{th}$ loop will execute (log n)+1 times

3) now for last loop or K$^{th}$ loop will run for :

$\sum_{k=1}^{log n+1}  \left ( \frac{n}{2}+1-k \right )$

 

Eg:

for n=8, 1$^{st}$ loop will execute 3 times

now 2$^{nd}$ will  execute  (log n +1) i.e 4 times

and 3$^{rd}$ loop will execute 10 times as per formula

 

we can simplify $\sum_{k=1}^{log n+1}  \left ( \frac{n}{2}+1-k \right )$ as = $\frac{n}{2} - \left ( 1+2+3...log n \right )$

since -(1+2+3...log n )  is negligible we will omit in result

so final answer is (log n)*((log n)+1)*($\frac{n}{2}$)= O(n* (log n)$^{2}$)

 Answer is B

Related questions

0 votes
0 votes
1 answer
1
0 votes
0 votes
3 answers
2
1 votes
1 votes
2 answers
3
srestha asked Aug 17, 2018
1,060 views
What will be TC here?Ans given $O(n^{2})$ , while I am getting $O(n)$
1 votes
1 votes
2 answers
4
HeadShot asked Aug 8, 2018
1,575 views