For these questions we will try to find out number of times “count = count + 1;” gets executed.
i |
0 |
1 |
2 |
3 |
………... |
(n-1) |
value of j |
0 |
1 |
2 values(2,1) |
3
values (3,2,1)
|
………... |
(n-1)
values (n-1,n-2,….,1)
|
value of j indicates the number of times “count = count + 1;” gets executed for each value of i.
So, 0+1+2+3+…...(n-1) times
= $\frac{(n-1)*n}{2}$
=$\frac{(n^{2}-n)}{2}$
So, time complexity is $O(n^{2})$
And since each execution of j for loop increments count by 1 so value of count = $\frac{(n^{2}-n)}{2}$