Sum of n terms of a sequence
If nth term of a sequence is given by Tn=an3+bn2+cn+d where a, b, c, d are constants then sum of n terms.
Sn = a*Σ(n3)+b*Σ(n2)+c*Σ(n)+Σ(d)
where Σ represent summation.
Let us find some of this series. So,
Sn = T1+T2+T3+T4+ ... +Tn T1 = a(1)3+b(1)2+c(1)+d T2 = a(2)3+b(2)2+c(2)+d T3 = a(3)3+b(3)2+c(3)+d ... ... Tn = a(n)3+b(n)3+c(n)+d
adding these all terms,
Sn = T1+T2+T3+ ... +Tn = a((1)3+(2)3+(3)3+ ... +(n)3)+b((1)2+(2)2+(3)2+ ... +(n)2)+c(1+2+3+ ... +n)+d(1+1+1+ ... +1)
Sn = a*Σ(n3)+b*Σ(n2)+c*Σ(n)+dn
Similarly if we have been nth term for any higher order or lower order term in the format.
Tn = a1np+a2np-1+a3np-2++ ... +apn1+ap+1
Sn = a1Σ(np)+a2Σ(np-1)+a3Σ(np-2)+ ... +apΣ(n)+nap+1
where p, a1, a2, …… are some constants.
nth term is given as,
Tn = n2+n+1
Sn = Σ(Tn) Sn = Σ(n2)+Σ(n)+Σ(1) Sn = (n(n+1)(2n+1))/6+n(n+1)/2+n
Σ(n2) = (n(n+1)(2n+1))/6, Σ(n) = (n(n+1))/2, Σ(1) = n
Thus we can find sum of any sequence if its nth term is given. This article is helpful in finding time complexity of equations when time complexity is given as function of n and we have to find the time complexity for the whole algorithm.
The given code above finds summation of sequence for 3 terms in which,
Tn = n4+n+1
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.