public class LargestSubsequence { static double naiveAlg (double[] X) { // INSERT YOUR CODE HERE. // The naive algorithm simply tries all possible contiguous subsequences. } static double fastAlg (double[] X) { // INSERT YOUR CODE HERE. } public static void main (String[] argv) { // Correctness tests. double[] A = {-1, 8, -2, 5, -3, -1, 2}; testCorrectness ("naiveAlg", A, 11); testCorrectness ("fastAlg", A, 11); double[] A2 = {-3, 1.5, -1, 3, -2, -3, 3}; testCorrectness ("naiveAlg", A2, 3.5); testCorrectness ("fastAlg", A2, 3.5); // Speed tests. testSpeed ("naiveAlg", 1000); testSpeed ("fastAlg", 1000); } // Run a correctness test. static void testCorrectness (String whichAlg, double[] A, double correctSum) { double sum; if (whichAlg.equalsIgnoreCase ("naiveAlg")) { sum = naiveAlg (A); } else { sum = fastAlg (A); } if (sum != correctSum) { System.out.println ("ERROR: " + whichAlg + " doesn't work"); } else { System.out.println ("Test 1 passed by " + whichAlg + ". Sum = " + sum); } } // Generate a random array of length problemSize and time the execution. static void testSpeed (String whichAlg, int problemSize) { double[] A = new double [problemSize]; for (int i=0; i