VOOZH about

URL: https://www.geeksforgeeks.org/dsa/sum-array-elements-using-recursion/

⇱ Sum of array elements using recursion - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Sum of array elements using recursion

Last Updated : 10 Sep, 2025

Given an array of integers, find sum of array elements using recursion. 

Examples:

Input: arr = [1, 2, 3]
Output: 6
Explanation: 1 + 2 + 3 = 6

Input: arr = [15, 12, 13, 10]
Output: 50
Explanation: 15 + 12 + 13 + 10 = 50

We have discussed iterative solution in this Post Sum of elements in a given array. In this Post we will discuss a recursive Solution.

Approach:

Illustration:

Given A = [1, 2, 3, 4, 5], the problem is solved recursively by breaking it down step by step. Each step reduces the array size, summing the last element with the sum of the remaining elements until the base case is reached.

👁 sum
recursive solution explanation

Output
15

Time Complexity: O(N), where N is the length of the array.
Auxiliary Space: O(N), due to recursive function calls stored in the call stack.

We can optimize the above recursive solution using tail recursion. Please refer Tail recursion for sum of array for details.


Comment
Article Tags: