Question: I need help with this lap in Java You will need to complete two recursive methods for this lab assignment. Write a recursive method to

I need help with this lap in Java

You will need to complete two recursive methods for this lab assignment.

  • Write a recursive method to sum the values in an integer array (the sumOfArray() in the provided ArraySumDriver.java file)
    • In addition, make it to be a generic method
  • Implement an additional recursive method to compute a Fibonacci number using the dynamic programming version.
  • I need help with this lap in Java You will need to

public class ArraySumDriver { private final static int ARRAY_SIZE = 6;

/** * @param args */ public static void main(String[] args) { int index = 0;

Integer[] myArray = new Integer[ARRAY_SIZE]; myArray[index++] = 13; myArray[index++] = 5; myArray[index++] = 12; myArray[index++] = 6; int sum = sumOfArray(myArray, 3); System.out.println(sum); myArray[index++] = 7; myArray[index++] = 1; sum = sumOfArray(myArray, 5); System.out.println(sum); } /** * Recursive method for generating sum of values in array * @param arr array of Integers * @param num index of array to sum all previous index values (including num) * @return sum of array values */ public static int sumOfArray(Integer[] arr, int num) { // Implement your code here return -999; // PLACE HOLDER }

}

Dynamic Programming Applied to Method factorial 0 0 0 1 1 1 0 1 2 3 3 4 5 6 24 0 0 0 0 0 0 6 24 0 0 0 0 7 8 : 6 7 8 0 0 0 The Array value 1. if (n == 0) return 1; index index index 0 11 0 2. If (value[n] != 0) return value[n]; 1 2 0 2 2 2 3. If (value[n-1] != 0) 3 4 4 5 5 120 4. { value[n] = n * value[n-1] 6 6 7 5. return value[n] 8 : 6. } // end of base cases Intialized After 4! Is After 5! ls State Calculated Calculated 7. else // use recursion Subsequent calculation of 1, 2, 3, 4, 5, 8. { value[n-1) = factorial(n-1)); or 6 factorial do not require recursive invocations 9. value[n] = n * value[n-1); 10. return value[n] } 49 Pearson Copyright 2019, 2015, 2012 Pearson Education, Inc. All Rights Reserved

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!