Question: Making a Histogram in Java public static int[] makeHistogram(double[] data, int numBins, double min, double max) Create a histogram for a data set given as

Making a Histogram in Java public static int[] makeHistogram(double[] data, int numBins, double min, double max)

Create a histogram for a data set given as an array of double values. The method returns an array arr of length numBins such that arr[i] contains the count of values from the data set that are in the range for the ith "bin." A number x is counted in one of the bins as follows:

Bin 0: min <= x < min + binSize

Bin 1: min + binSize <= x < min + 2 * binSize

Bin 2: min + 2 * binSize <= x < min + 3 * binSize

...

Bin n - 1: min + (n - 1) * binSize <= x < max

where n = numBins and binSize = (max - min) / numBins. It can be assumed that max > min and numBins > 0. Values in the data that are less than min, or greater than or equal to max, are ignored. Note: The bin index is always (x - min) / binSize, truncated down to the next lowest integer.

Example: if nums is the array [18.0, 15.0, 8.0, 16.0, 14.0, 19.0], then for the call

makeHistogram(nums, 4, 2.0, 24.0);

binSize is (24.0 - 2.0)/4 = 5.5, so the bins are

Bin 0: 2.0 <= x < 7.5

Bin 1: 7.5 <= x < 13.0

Bin 2: 13.0 <= x < 18.5

Bin 3: 18.5 <= x < 24.0

In this case the method returns the array [0, 1, 4, 1].

Parameters:

data - the data set

numBins - number of bins for the histogram

min - lower bound (inclusive) for numbers to be included in the histogram

max - upper bound (exclusive) for numbers to be included in the histogram

Returns:

array whose ith cell contains the number of data values in bin i

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!