寻找一个数组的中值? [英] Finding the median value of an array?
本文介绍了寻找一个数组的中值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否有可能找到一个数组的中值?例如,假设我有九号的数组。将有可能找到这个阵的中间槽?
I was wondering if it was possible to find the median value of an array? For example, suppose I have an array of size nine. Would it possible to find the middle slot of this array?
推荐答案
假设数组的 X 的排序是长度的 N 的:
Assuming the array x is sorted and is of length n:
如果n是奇数则位数为x [(N-1)/ 2]。结果,
如果n是偶数比位数为(x [N / 2] +×[(N / 2)-1])/ 2
If n is odd then the median is x[(n-1)/2].
If n is even than the median is ( x[n/2] + x[(n/2)-1] ) / 2.
这篇关于寻找一个数组的中值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文