Question #186502

Solve the following time complexity

T(n) = āˆ‘ āˆ‘ 1


š‘–

š‘—=0

š‘›āˆ’1

š‘–=1



Expert's answer

Given,

T(n)=Ī£i=1i=nĪ£j=1nāˆ’1(1)T(n)=\Sigma_{i=1}^{i=n} \Sigma_{j=1}^{n-1} (1)

We know that,

Ī£j=1nāˆ’1(1)=(nāˆ’1)\Sigma_{j=1}^{n-1} (1)=(n-1)

So complexity of this step will be O(n)O(n)

Now again,

Ī£i=1i=n(nāˆ’1)\Sigma_{i=1}^{i=n}(n-1)

=Ī£i=1i=n(n)āˆ’Ī£i=1i=n(1)=\Sigma_{i=1}^{i=n}(n)-\Sigma_{i=1}^{i=n}(1)

=n(nāˆ’1)2āˆ’n=\frac{n(n-1)}{2}-n

=n22āˆ’n2āˆ’n=\frac{n^2}{2}-\frac{n}{2}-n


=n22āˆ’3n2=\frac{n^2}{2}-\frac{3n}{2}

So the complexity of the steps will be as per the below-

=12O(n2)āˆ’32O(n)=\frac{1}{2}O(n^2)-\frac{3}{2}O(n)

Hence the required final complexity will be =O(n2)=O(n^2)


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS