Median of Medians in Java

前端 未结 5 1504
清歌不尽
清歌不尽 2020-12-03 09:11

I am trying to implement Median of Medians in Java for a method like this:

Select(Comparable[] list, int pos, int colSize, int colMed)
5条回答
  •  天命终不由人
    2020-12-03 10:04

    @android developer :

    for (i = 1 to n/5) do
        x[i] = select(S[i],3)
    

    is really

    for (i = 1 to ceiling(n/5) do
        x[i] = select(S[i],3)
    

    with a ceiling function appropriate for your data(eg in java 2 doubles) This affects the median as well wrt simply taking n/10, but we are finding closest to the mean that occurs in the array, not the true mean. Another note is that S[i] may have fewer than 3 elements, so we want to find the median with respect to length; passing it into select with k=3 won't always work.( eg n =11, we have 3 subgroups 2 w 5, 1 w 1 element)

提交回复
热议问题