Question #186962

Solve the following time complexities

a) T (n)= n∑ n∑ 1

i=1 j=1

b) T(n) = n-1 ∑ n∑ c

i= 0 j= i+1

c) T(n) = n ∑ 1

i= 1


1
Expert's answer
2021-04-29T23:53:23-0400

a) T(n)=nΣnΣ1T(n)=n\Sigma n\Sigma 1

We know that,

Σ1=n\Sigma 1= n

So, Σn×n=Σn2\Sigma n\times n=\Sigma n^2

Here first term of series n, will be functioning as the constant,

So, Σn2=n(n+1)(2n+1)6\Sigma n^2 = \frac{n(n+1)(2n+1)}{6}


T(n)=n(2n3+n2+2n2+n6)\Rightarrow T(n)=n( \frac{2n^3+n^2+2n^2+n}{6})


T(n)=2n4+3n3+n26\Rightarrow T(n)=\frac{2n^4+3n^3+n^2}{6}


T(n)=n43+n32+n26\Rightarrow T(n)=\frac{n^4}{3}+\frac{n^3}{2}+\frac{n^2}{6}

Hence the complexity of the given terms will be

=O(n4)+O(n3)+O(n2)=O(n^4)+O(n^3)+O(n^2)

Hence the complexity of the terms will be O(n4)O(n^4)


b) T(n)=(n1)ΣnΣcT(n)= (n-1)\Sigma n \Sigma c

Here c is constant,

Σc=cΣ1=cn\Sigma c = c\Sigma1 = cn

Σn(cn)=cΣn2=cn(n+1)(2n+1)6\Sigma n(cn)=c\Sigma n^2 =c\frac{n(n+1)(2n+1)}{6}


=c(n1)(n2+n)(2n+1)6=\frac{c (n-1)(n^2+n)(2n+1)}{6}


=c(n1)(2n3+n2+2n2+n)6=\frac{c(n-1)(2n^3+n^2+2n^2+n)}{6}


=c(2n4+3n3+n22n33n2n)6=\frac{c(2n^4+3n^3+n^2-2n^3-3n^2-n)}{6}


=c(2n4+n32n2n)6=\frac{c(2n^4+n^3-2n^2-n)}{6}

Hence, the respective time complexity of the given function,

=O(n4)+O(n3)O(n2)+O(n)=O(n^4)+O(n^3)-O(n^2)+O(n)

Hence the complexity of the given function will be O(n4)O(n^4)

c)

T(n)=nΣ1T(n)=n\Sigma 1

=n×n=n\times n

=n2=n^2

Hence, the time complexity of the given function 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!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS