简体   繁体   English

求中位数的下界

[英]Lower Bound of finding the median

Assume we're given a list of n numbers and we want to find a number that is greater than or equal to the median. 假设我们得到了一个由n个数字组成的列表,并且我们想找到一个大于或等于中位数的数字。 I want to learn the lower bound for the worst case complexity of this problem. 我想了解此问题的最坏情况复杂性的下限。 I know that the lower bound of finding the median is 3(n-1)/2. 我知道找到中位数的下限是3(n-1)/ 2。 But will it be the same when we want to find a number that is greater than or equal to the median. 但是当我们想要找到一个大于或等于中位数的数字时,会是一样的。

I think the largest element of the first half of the list(+1) will have this feature. 我认为列表(+1)的前半部分中最大的元素将具有此功能。 If You check n/2+1 element and You store the greatest one, there could be at most n/2-1 element greater than your median-candidate. 如果您检查n / 2 + 1个元素并存储最大的一个,则最多有n / 2-1个元素大于中位数候选人。 So, the chosen number will be in the top half of the numbers, which means: it is greater than or equal to the median. 因此,所选数字将位于数字的上半部分,这意味着:大于或等于中位数。

So You can find it in n/2+1 . 因此,您可以在n/2+1找到它。

You need: 你需要:

worst case: n/2 comparsions and n/2+1 assignments. 最坏的情况:n / 2个比较和n / 2 + 1个分配。

best case: n/2 comparsions and 1 assignment. 最佳情况:n / 2个对比和1个作业。

Edit: Answer to Your comment: Edit:回答您的评论:

Yes. 是。 If n is an even number, any random element will be greater than or equal to the median with probability at least 0.5 . 如果n是偶数,则任何随机元素都将大于或等于中位数,且概率至少0.5 Why "at least 0.5"? 为什么要“至少0.5”? There might be test cases, where nearly all of the number are equal to the median. 可能会有一些测试案例,其中几乎所有数字都等于中位数。 In those cases, the probability will be higher. 在那些情况下,可能性会更高。 If You want to know the correct probability, You have to check all the elements. 如果您想知道正确的概率,则必须检查所有元素。 In other test cases with diferent numbers, any random element would be in the top half of the ordered list with probability 0.5. 在其他具有不同编号的测试案例中,任何随机元素都将以0.5的概率位于有序列表的上半部分。

If n is odd, a random number will have this feature with the probability > 0.5. 如果n为奇数,则随机数将具有此功能,概率> 0.5。 It's beacause n/2-0.5 elements are less than the median and n/2+0.5 elements are >= median ( in a common test case). 这是因为n/2-0.5元素小于中位数,而n/2+0.5元素> =中位数(在常见的测试案例中)。 If You'd like 0.5 to be the minimal probability, You should do some modification. 如果您希望0.5为最小概率,则应进行一些修改。 I have an idea with no proof, maybe somebody will coorect me if it doesn't work: Chose 2 random values from the list. 我有一个没有证据的想法,如果有人行不通的话,也许有人会帮我选一个:从列表中选择2个随机值。 The smaller will be a valid solution with at least 0.5 probability . 较小者将是具有至少0.5概率的有效解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM