Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are NOT allowed to use Arrays, Array, ArrayList (or any JCF class), or System.arraycopy(). Essentially, using any other class that solves your problems for

You are NOT allowed to use Arrays, Array, ArrayList (or any JCF class), or System.arraycopy().

Essentially, using any other class that solves your problems for you is forbidden.

Using any of these may result in a grade of zero.

You can use Arrays.toString() when testing your code

image text in transcribedimage text in transcribedimage text in transcribed

been in the news and all over the internet. When analyzing such data it is sometimes useful to identify where the (local) maximum values are located. We'll call these maximal values peaks in the data. More formally, if we have a sequence of numbers d0,d1,d2,,dn1, the peaks are identified as follows: 1. if n=thend0 is a peak, otherwise 2. d0 is a peak if d0>d1, 3. dn1 is a peak if dn2di+1 In the provided Peaks.java file, you will complete three static methods that relate to peaks in some data. public static int numPeaks(int [] data) public static int [] peaks(int [] data) public static int [] [] minmax(int [] data) The numPeaks (int [] ) will count and return the number of peaks in the input data. The peaks (int [] ) method will find and return the locations of all the peaks in input data. The minmax (int [] ) will find the maximum and minimum values in the input data and output these values and all positions of where they occur. The output format must be as follows: - the output array will have dimension 2 (that is, the length is 2) - the first element will correspond to the min value and the second will correspond to the max value in the input - each element in the output will be an array that has at least 2 values: the first is the value (either min or max ) and the next will be the positions in the input array where this value is located Here are some examples: int [] data1 ={1,1,4,15,3,1}; Peaks.numPeaks(data1) 1 Peaks.peaks(data1) [3] Peaks.minmax (data1) [[1,0,1,5],[15,3]] int [] data2 ={3,1,4,2,13,2,5}; Peaks.numPeaks(data2) 4 Peaks.peaks(data2) [0,2,4,6] Peaks.minmax (data2) [[2,3,5],[13,4]] int [] data3 ={1,4,4,1}; Peaks.numPeaks(data2) 0 Peaks.peaks(data2) [] Peaks.minmax ( data2) [[1,0,3],[4,1,2]] Note: we are not considering what might be described as plateaus in the data. A plateau occurs when a local maximum value is repeated one or more times consecutively (like the value 4 in the last example above). Note: all input to these methods will be an array with at least one number in it. That is, we will never pass an empty array or null as input to your methods. Note: peaks () must always return an array. Even if there are no peaks, it must return an array object (and not null). Aside: finding the peaks (which include the plateaus) in scientific data is very common. For example, analyzing data from various spectrometers in chemistry and physics labs often involves identifying the peaks in the data first. Tools like Matlab and Octave have built-in functions to find peaks similar to your peaks () method. In practise, it is more complicated though (you would be working with floating point numbers, you would have to deal with noise in the data, you would have more criteria for determining the peaks). public class Peaks \{ public static int numpeaks(int[] data)\{ // returns the number of "peaks" in the input data return -1; public static int [] peaks(int[] data)\{ // returns the locations of all peaks in the input data return new int[0]; public static int[][] minmax(int[] data)\{ // finds the min and max values (and all their locations) return new int[0][0]; \}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Databases With PostgreSQL From Novice To Professional

Authors: Richard Stones, Neil Matthew

2nd Edition

1590594789, 978-1590594780

More Books

Students also viewed these Databases questions

Question

2. What are your challenges in the creative process?

Answered: 1 week ago