Menu

[solved]-Values Locations Peaks Plateaus Data Usually Much Important Simply Knowing Many Peaks Pro Q39020561

The values and locations of the peaks (and plateaus) in data areusually much more important than simply knowing how many peaksthere are. In this problem, you will find the values and locationsof all the peaks. Create a class called FindPeaks with the singlestatic method

2 Peak Analysis II 30 marks] The values and locations of the peaks (and plateaus) in data is usually much more important than

public class Peaks{

  /** Finds the number of “peaks” in the input dataarray.

    * <p>

    * A value in the input data array is apeak if it is strictly

    * larger than all adjacent (immediateneighbour) values in the

    * data array.

    * <p>

    * Examples:

    * int[] data1 = {1,3,2,1,0,0};

    * numberOfPeaks(data1) ==> 1 (3 isthe only peak)

    * int[] data2 = {4,3,6};

    * numberOfPeaks(data2) ==> 2 (4 and 6are peaks)

    * int[] data3 = {2,2};

    * numberOfPeaks(data3) ==> 0 (thereare no peaks)

    *

  *

    * @param data is an array of one or moreintegers.

    *

    * @return the number of “peaks” in theinput data array.

    */

   public static int numberOfPeaks(int[]data){

        int peaks =0;

        if(data.length== 1)

        return 1;

        if(data[0] >data[1])

        peaks++;

        if(data[data.length-1]> data[data.length-2])

        peaks++;

        for(int i=1;i<data.length-1; i++){

            if(data[i]>data[i-1]&&data[i]>data[i+1])

            peaks++;

        }

        

        returnpeaks;

  }

    

    /** basic testing… you should be doingmuch more testing on your own! */

    public static void main(String[]args){

        // basictesting

        int[] data1 =new int[]{25};

        int expected1 =1;

        display(1,data1, expected1);

        int[] data2 =new int[]{1,3,2,3,-10,4};

        int expected2 =3;

        display(2,data2, expected2);

    }

    /** helper method to print test case*/

    public static void display(int number,int[] data, int expected){

        System.out.print(“example ” + number + “: “);

        System.out.print(“expected = ” + expected);

        int actual =numberOfPeaks(data);

        System.out.print(“, actual is ” + actual);

        if( actual ==expected){

            System.out.println(“[pass]”);

        }else{

            System.out.println(“[fail]”);

        }

    }

    

}

2 Peak Analysis II 30 marks] The values and locations of the peaks (and plateaus) in data is usually much more important than simply knowing how many peaks there are. In this problem you will find the values and locations of all the peaks. Create a class called FindPeaks with the single static method public static int[] [] findPeaks (int data) The method returns a 2-dimensional array of integers that correspond to the values and locations (in the data array) of all the peaks. The order of the peaks in the output array should correspond to the order of the peaks in the data. For example, the first peak in the input data willl be the first peak in the output array. Consider the following code: int int poaks 13,6,7,5,3,-1,1}; FindPeaks.findPoaks (data) // array from problom 1 data The peaks variable, after calling findPeaks (data), will be equivalent to the following array int ans 7, 1 12, 6 //peak values //peak locations sver Here peaks [0] CO] is the value of the first peak which is located at index position peaks [1] [0] in the input array data. The second peak’s value/location is contained in peaks [0] [1]/peaks [1] [1]. Here peaks [0] contains all the values and peaks [1] contains their corresponding index positions in the data Note that the size of the returned array depends on the actual input data. For example, the data [3] has a single peak, the data [2,2,2] has no peaks and the data [3,2,3] has two peaks Show transcribed image text 2 Peak Analysis II 30 marks] The values and locations of the peaks (and plateaus) in data is usually much more important than simply knowing how many peaks there are. In this problem you will find the values and locations of all the peaks. Create a class called FindPeaks with the single static method public static int[] [] findPeaks (int data) The method returns a 2-dimensional array of integers that correspond to the values and locations (in the data array) of all the peaks. The order of the peaks in the output array should correspond to the order of the peaks in the data. For example, the first peak in the input data willl be the first peak in the output array. Consider the following code: int int poaks 13,6,7,5,3,-1,1}; FindPeaks.findPoaks (data) // array from problom 1 data The peaks variable, after calling findPeaks (data), will be equivalent to the following array int ans 7, 1 12, 6 //peak values //peak locations sver Here peaks [0] CO] is the value of the first peak which is located at index position peaks [1] [0] in the input array data. The second peak’s value/location is contained in peaks [0] [1]/peaks [1] [1]. Here peaks [0] contains all the values and peaks [1] contains their corresponding index positions in the data Note that the size of the returned array depends on the actual input data. For example, the data [3] has a single peak, the data [2,2,2] has no peaks and the data [3,2,3] has two peaks

Expert Answer


Answer to The values and locations of the peaks (and plateaus) in data are usually much more important than simply knowing how man… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *