java中位数,中位数在Java中位数

该博客提供了一种在Java中实现中位数中位数选择算法的方案,用于在给定列表中找到指定位置的元素。算法首先将列表划分为大小为5的子集,然后找出每个子集的中位数,再从这些中位数中选择中位数的中位数,以此来分割列表并进行快速定位。这种方法避免了完全排序,提高了效率。
摘要由CSDN通过智能技术生成

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

Select(Comparable[] list, int pos, int colSize, int colMed)

list is a list of values of which to find a specified position

pos is the specified position

colSize is the size of the columns that I create in the first stage

colMed is the position in those columns that I use as the medX

I am not sure which sorting algorithm would be the best to use or how to implement this exactly..

解决方案

I don't know if you still need this problem solved, but http://www.ics.uci.edu/~eppstein/161/960130.html has an algorithm:

select(L,k)

{

if (L has 10 or fewer elements)

{

sort L

return the element in the kth position

}

partition L into subsets S[i] of five elements each

(there will be n/5 subsets total).

for (i = 1 to n/5) do

x[i] = select(S[i],3)

M = select({x[i]}, n/10)

partition L into L1M

if (k <= length(L1))

return select(L1,k)

else if (k > length(L1)+length(L2))

return select(L3,k-length(L1)-length(L2))

else return M

}

Good luck!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值