1 votes 1 votes Please find the time complexity of the following code:-int i,s1; i=1,s1=1; while(s1<=n) { i++; s1+=s1+i; printf("Hope"); } Algorithms algorithms time-complexity + – Devshree Dubey asked Apr 27, 2018 • edited Apr 27, 2018 by Devshree Dubey Devshree Dubey 4.4k views answer comment Share Follow See all 0 reply Please log in or register to add a comment.
2 votes 2 votes ........................ abhishekmehta4u answered Apr 27, 2018 abhishekmehta4u comment Share Follow See all 16 Comments See all 16 16 Comments reply Show 13 previous comments rajatmyname commented May 2, 2018 reply Follow Share @ankitgupta.1729 thanks bro 1 votes 1 votes rohan devaki commented Feb 28, 2022 reply Follow Share from 1+3+6+ 10 + k =n k(K+1)(K+2) ____ = n 6 how did this k(k+1)(k+2 )/6 come from the previous step? 0 votes 0 votes ankitgupta.1729 commented Mar 16, 2022 reply Follow Share @rohan devaki $1+3+6+10+15+….\text{till some finite number of terms}$ $1+(1+2)+(1+2+3)+(1+2+3+4)+(1+2+3+4+5)+….\text{till some finite number of terms}$ $\Sigma_{n=1}^{n=k}\;\left( \Sigma_{p=1}^{p=n}\; p\right)$ $\Sigma_{n=1}^{n=k}\;\left( \frac{n(n+1)}{2}\right)$ $\Sigma_{n=1}^{n=k}\;\left( \frac{n^2+n}{2}\right)$ $\frac{1}{2}\left(\Sigma_{n=1}^{n=k} (n^2) + \Sigma_{n=1}^{n=k} (n)\right)$ $\frac{1}{2}\left(\frac{k(k+1)(2k+1)}{6} + \frac{k(k+1)}{2}\right)$ $\frac{k(k+1)}{4}\left(\frac{2k+1}{3}+1\right)$ $\frac{k(k+1)}{4}\left(\frac{2k+4}{3}\right)$ $\frac{k(k+1)(k+2)}{6}$ 0 votes 0 votes Please log in or register to add a comment.