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:

  1. get minimum , maximum elements of array
  2. take difference , divide num, obtaining "step"
  3. now iterate through array, placing number n in slot such * step <= n - min < (i+1) * step

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -