Linear Sum using Recursion in Java

Linear Sum, sum of the “n” array elements can be computed easily by looping through the elements, this can be solved using recursion also. Devise last array element every time and solve the similar problem for remaining “n-1” array elements, will devising add intermediate result . Algorithm or Recurrence relation for the Linear Sum problem can be as follows.

Algorithm or Recurrence relation


if n=1 then                     //base case
return a[0];
else                                //recursive case
return linearSum(a[n-1])+a[n-1];

Linear Sum using Recursion implementation in Java

Here is the implementation of linear sum using recursion in java



Leave a Comment