Arrays. Histograms, dividing array into subset and counting number of elements in each group. Java -
hi im confused abt method have create. have create histogram array num division categories i.e selecting reasonable integer range , step size numdivisons cover whole range of elements in array. @return array histogram in position contains * number of observations in division */
example: {1,3,4,5,10,15,17}.
if numdivisions=2 need divide range (1 17) 2 divisions. example, range 0 10 (not included) , 10 20. in case there 4 values in range 0 <10 , 3 values between 10 , 20.
histogram numdivisions=2 array {4,3}.
public int[] histogram(int numdivisions) can tell me best method of doing it? thanks
simple:
- get minimum , maximum elements of array
- take difference , divide num, obtaining "step"
- now iterate through array, placing number n in slot such * step <= n - min < (i+1) * step
Comments
Post a Comment