Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- EQ: Sum of numbers in an array
- 1. Define the problem
- let sum(arr,i) be the sum of numbers for arr[i] to the end of the array.
- 2. Base conditions
- if i == arr.length-1 then return arr[i]
- 3. recurence reations (sometimes it is not easy to find this, and makes reccurence hard)
- sum(arr,i) = sum(arr,i+1)+arr[i]
- Code:
- void sum(arr,i)
- if (i == arr.length-1)
- retunr arr[i];
- return sum(arr,i+1)+arr[i];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement