0
可能重複:
How to calculate or approximate the median of a list without storing the list選擇算法查找平均
我想用C#的算法來找到使用選擇/快速排序中值適用。但我不想排序整個數組以獲得中位數。
我可以做到嗎?
可能重複:
How to calculate or approximate the median of a list without storing the list選擇算法查找平均
我想用C#的算法來找到使用選擇/快速排序中值適用。但我不想排序整個數組以獲得中位數。
我可以做到嗎?
維基百科在Selection Algorithm上的條目給出了各種替代方案,包括中位數的中醫方法,這似乎符合您的要求。特別是,它具有O(n)的最壞情況性能。
你爲什麼不想排序整個數組?我認爲這是強制排序整個數組,因爲它是找到確切的中位數的關鍵點(不猜猜可能的中位數).. – Abbas
特別是發佈的鏈接不是[標籤:C#],但是該算法可以很容易地應用。 –
@阿巴斯排序整個陣列非常昂貴! –