Package com.zybooks.dsaj.recursion
Class ArraySum
java.lang.Object
com.zybooks.dsaj.recursion.ArraySum
Demonstration of two recursive approaches to computing the sum of an array of integers.
-
Constructor Summary
-
Method Summary
-
Constructor Details
-
ArraySum
public ArraySum()
-
-
Method Details
-
linearSum
public static int linearSum(int[] data, int n) Returns the sum of the first n integers of the given array.- Parameters:
data
- array of integersn
- how many integers from the beginning of the array to sum- Returns:
- the sum of the first n integers of data
-
binarySum
public static int binarySum(int[] data, int low, int high) Returns the sum of subarray data[low] through data[high] inclusive.- Parameters:
data
- array of integerslow
- the index of the first integer in the rangehigh
- the index of the second integer in the range- Returns:
- the sum of the integers from data[low] through data[high] inclusive
-
main
-