CREATE OWN LIBRARY


Description

Here the program is written to find the value of the below series 

 

 

If the denominator is even then the square of the denominator is calculated and the value of the term is added to the value of the series, if the denominator is odd, the cube of the term is calculated and the value of the term is subtracted from the value of the series.

 

For example, if the input is 2, the value of the series will be calculated as:

Algorithm

INPUT: Number of terms

OUTPUT: The value of the series upto n terms

PROCESS:

Step 1: [Taking the input]

               Read n

Step 2: [Calculating the value of the series]

               Set s<-0

               Set p<-2

               Set sign<-1

               [Calculating the value of the series]

               For i=2 to n repeat

                              Set s<-s+(sign×(1/ip))

                              Set p<-p+sign

                              Set sign<-sign×(-1)

               [End of ‘for’ loop]

               [Printing the result]

               Print "The sum of the series is: s"

Step 3: Stop.

Code

TIME COMPLEXITY:

for(i=2;i<=n;i++)-------------------------------------- O(n)

               {

                              s=s+(sign*(1/pow(i,p)));

                              p=p+sign;

                              sign=sign*(-1);

               }

 

The time complexity of this program is O(n) where ‘n’ is the number of terms of the series.

 

SPACE COMPLEXITY:

The space complexity of this program is O(1) as it requires a constant number of memory spaces for any given input.