a) T(n)=nΣnΣ1
We know that,
Σ1=n
So, Σn×n=Σn2
Here first term of series n, will be functioning as the constant,
So, Σn2=6n(n+1)(2n+1)
⇒T(n)=n(62n3+n2+2n2+n)
⇒T(n)=62n4+3n3+n2
⇒T(n)=3n4+2n3+6n2
Hence the complexity of the given terms will be
=O(n4)+O(n3)+O(n2)
Hence the complexity of the terms will be O(n4)
b) T(n)=(n−1)ΣnΣc
Here c is constant,
Σc=cΣ1=cn
Σn(cn)=cΣn2=c6n(n+1)(2n+1)
=6c(n−1)(n2+n)(2n+1)
=6c(n−1)(2n3+n2+2n2+n)
=6c(2n4+3n3+n2−2n3−3n2−n)
=6c(2n4+n3−2n2−n)
Hence, the respective time complexity of the given function,
=O(n4)+O(n3)−O(n2)+O(n)
Hence the complexity of the given function will be O(n4)
c)
T(n)=nΣ1
=n×n
=n2
Hence, the time complexity of the given function will be O(n2)
Comments