FOR FREE YEAR SOLVED


Description

The program is written to find the value of the series: 

 

 

The number of terms is taken as input. For loops are used here to find the value of the series.

 

For example, if the given input is 2, the value will be:

Algorithm

INPUT: Number of terms

OUTPUT: The value of the series

PROCESS:

Step 1: [Taking the input]

               Read n [number of terms]

Step 2: [Finding the value of the series]

               Set s<-0

               [Finding the sum of the series]

               For i=1 to n repeat

                              Set f<-1

                              For j=1 to i repeat

                                             Set f<-f×j

                              [End of ‘for’ loop]

                              Set s<-s+ii/f

               [End of ‘for’ loop]

               [Printing the sum of the series]

               Print "The sum of the series is: s"

Step 3: Stop.

Code

TIME COMPLEXITY:

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

               {

                              f=1;

                              for(j=1;j<=i;j++)

                                             f=f*j;

                              s=s+pow(i,i)/f;

               }

 

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.