Solve the following time complexity
T(n) = โ โ 1
๐
๐=0
๐โ1
๐=1
Given,
"T(n)=\\Sigma_{i=1}^{i=n} \\Sigma_{j=1}^{n-1} (1)"
We know that,
"\\Sigma_{j=1}^{n-1} (1)=(n-1)"
So complexity of this step will be "O(n)"
Now again,
"\\Sigma_{i=1}^{i=n}(n-1)"
"=\\Sigma_{i=1}^{i=n}(n)-\\Sigma_{i=1}^{i=n}(1)"
"=\\frac{n(n-1)}{2}-n"
"=\\frac{n^2}{2}-\\frac{n}{2}-n"
"=\\frac{n^2}{2}-\\frac{3n}{2}"
So the complexity of the steps will be as per the below-
"=\\frac{1}{2}O(n^2)-\\frac{3}{2}O(n)"
Hence the required final complexity will be "=O(n^2)"
Comments
Thank you so much it's help me alot
Leave a comment