Advertisement
gopro2027

Reccurence Notes

Sep 26th, 2018
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. EQ: Sum of numbers in an array
  2.  
  3. 1. Define the problem
  4. let sum(arr,i) be the sum of numbers for arr[i] to the end of the array.
  5.  
  6. 2. Base conditions
  7. if i == arr.length-1 then return arr[i]
  8.  
  9. 3. recurence reations (sometimes it is not easy to find this, and makes reccurence hard)
  10. sum(arr,i) = sum(arr,i+1)+arr[i]
  11.  
  12. Code:
  13. void sum(arr,i)
  14. if (i == arr.length-1)
  15. retunr arr[i];
  16. return sum(arr,i+1)+arr[i];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement