1 votes 1 votes for(i=1; i<=n; i++) { for(j=i; j<=n; j++){ for(k=j+1; k<=n; k++){ printf("Hello"); } } } How many times print statement is executed for n=4 and what is the time complexity? Purnendu Sekhar asked Aug 14, 2017 • edited Aug 14, 2017 by Purnendu Sekhar Purnendu Sekhar 428 views answer comment Share Follow See all 4 Comments See all 4 4 Comments reply joshi_nitish commented Aug 14, 2017 i edited by joshi_nitish Aug 14, 2017 reply Follow Share 10 times for n=4 complexity will be $\sum \frac{r(r+1)}{2}$ = O(n3) 1 votes 1 votes Purnendu Sekhar commented Aug 14, 2017 reply Follow Share Thank you..I got it 0 votes 0 votes srestha commented Aug 14, 2017 reply Follow Share $= \sum_{i=1}^{n}\sum_{j=i}^{n}\sum_{k=j+1}^{n} 1 \\ = \sum_{i=1}^{n}\sum_{j=i}^{n}(n-j) \\ = \sum_{i=1}^{n}(n-i) + (n-(i+1)) + .....+ (n-n)\\ =\frac{1}{2}\sum_{i=1}^{n}(n-i)(n-i+1) \\ =\frac{1}{2}\sum_{i=1}^{n}(n^{2} +n+i^{2}-(2n+1)i)\\ = \frac{1}{2} \left( n^3 + n^2 + \sum_{i=1}^{n}i^2 - (2n+1). \sum_{i=1}^{n} i \right)\\ = \frac{1}{2} \left( n^3 + n^2 + \frac{n. (n+1). (2n+1)}{6} - (2n+1). \frac{n. (n+1)}{2} \right) \\ = \frac{1}{2} \left( n^3 + n^2 - \frac{n. (n+1). (2n+1)}{3} \right) \\ = \frac{n}{6} \left( 3n(n+1) - (n+1). (2n+1) \right) \\= \frac{n. (n+1)}{6} (n-1) \\ =\frac{(n-1)n(n+1)}{6}$ 2 votes 2 votes Hira Thakur commented Aug 17, 2017 reply Follow Share can you show the solution joshi_nitish. 0 votes 0 votes Please log in or register to add a comment.