Class BasicRecursion
java.lang.Object
|
+--BasicRecursion
- public class BasicRecursion
- extends java.lang.Object
Class BasicRecursion contains a single method to sum the elements of an
array using a recursive algorithm. The algorithm uses a "tail recursion"
style, which goes basically like this:
Base case:
If there are no (more) elements in the array, return a sum of zero.
Recursive step:
Otherwise, return the sum of the first element of the array plus the
recursive sum of the rest (i.e., tail) of the array.
Method Summary |
int |
sumArray(int[] numbers,
int position)
Return the sum of the elements in the given numbers array, starting at
the given index position. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
BasicRecursion
public BasicRecursion()
sumArray
public int sumArray(int[] numbers,
int position)
- Return the sum of the elements in the given numbers array, starting at
the given index position. If the position is past the end of the array,
return 0.