Class ArraySum

java.lang.Object
com.zybooks.dsaj.recursion.ArraySum

public class ArraySum extends Object
Demonstration of two recursive approaches to computing the sum of an array of integers.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    binarySum(int[] data, int low, int high)
    Returns the sum of subarray data[low] through data[high] inclusive.
    static int
    linearSum(int[] data, int n)
    Returns the sum of the first n integers of the given array.
    static void
    main(String[] args)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 integers
      n - 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 integers
      low - the index of the first integer in the range
      high - the index of the second integer in the range
      Returns:
      the sum of the integers from data[low] through data[high] inclusive
    • main

      public static void main(String[] args)