简体   繁体   English

找到找到 k 对的时间复杂度的下限

[英]Finding lower bound on time complexity of finding k pairs

We are given n bolts and n nuts of different sizes, where each bolt exactly matches one nut.我们有 n 个不同尺寸的螺栓和 n 个螺母,其中每个螺栓与一个螺母完全匹配。 Our goal is to find the matching nut for each bolt.我们的目标是为每个螺栓找到匹配的螺母。 The nuts and bolts are too similar to compare directly;螺母和螺栓太相似无法直接比较; however, we can test whether any nut is too big, too small, or the same size as any bolt.但是,我们可以测试任何螺母是否太大、太小或与任何螺栓尺寸相同。

Prove that in the worst case Ω(n + k log n) nut-bolt comparisons are required to find k matching pairs.证明在最坏的情况下需要进行 Ω(n + k log n) 螺母螺栓比较才能找到 k 个匹配对。

I'm thoroughly stumped on how to do this, I figure a 3-ary decision tree with for this would need n^k nodes, thus giving klog(n) for the height of the tree, but I can't figure out where the +n comes from.我对如何做到这一点感到非常困惑,我认为一个三元决策树需要 n^k 个节点,从而为树的高度提供 klog(n),但我不知道在哪里+n 来自。

Here is a very loose answer that might form the basis of a proper proof:这是一个非常松散的答案,可能构成正确证明的基础:

Suppose that you have to ask me (your adversary) every time you want to test a new nut or a new bolt and I hand you a new nut or a new bolt.假设您每次要测试新螺母或新螺栓时都必须问我(您的对手),而我递给您一个新螺母或新螺栓。 Before you start I sort the nuts and bolts into matching pairs, then divide the pairs into two heaps, each of size n/2.在开始之前,我将螺母和螺栓分类成匹配的对,然后将这些对分成两堆,每堆大小为 n/2。 For the first n/2 steps I hand you a nut from the first heap, or a bolt from the second heap, depending on what you ask for.对于前 n/2 个步骤,我会从第一个堆中给您一个螺母,或者从第二个堆中取一个螺栓,具体取决于您的要求。 So I can always delay you from finding any matches until you have made at least n/2 matching attempts, because until I run out of one of the heaps, you will never get a nut and bolt that match.因此,我总是可以延迟您找到任何匹配项,直到您至少进行了 n/2 次匹配尝试,因为在我用完其中一个匹配项之前,您将永远无法获得匹配项。

Your life is not made any harder if I label the bolts in order of size, because you can always choose to ignore this information.如果我按尺寸顺序标记螺栓,您的生活不会变得更难,因为您总是可以选择忽略这些信息。 Now if you can find k matches in time less than k log n, for all possible k and n >= k, then you can solve the problem of sorting n numbers using only comparisons, where the numbers are known to be the set {1,2,3...n}.现在,如果您可以在小于 k log n 的时间内找到 k 个匹配项,对于所有可能的 k 并且 n >= k,那么您可以解决仅使用比较对 n 个数字进行排序的问题,其中已知数字为集合 {1 ,2,3...n}。 In fact, even if you have a magic method that works only for eg k<=3 and all n, you can still do this low-comparison sort by repeatedly finding 3 matches between the set of (unlabelled) nuts that remain and the set of (labelled) bolts.事实上,即使你有一个只对 k<=3 和所有 n 有效的魔法方法,你仍然可以通过在剩余的(未标记的)坚果集和剩余的坚果集之间重复找到 3 个匹配来进行这种低比较排序(标记的)螺栓。 So if you can find matches with fewer than k log n comparison, you can sort numbers known to be {1,2...n} with fewer than n log n comparisons - but the usual information-theoretic lower bound on sorting numbers still holds here.因此,如果您可以找到少于 k log n 比较的匹配项,您可以使用少于 n log n 比较对已知为 {1,2...n} 的数字进行排序 - 但排序数字的常用信息理论下界仍然在这里举行。 So you need at least k log n comparisons.所以你至少需要 k log n 比较。

So now we have an lower bound of max(n/2, k log n).所以现在我们有一个下界 max(n/2, k log n)。 We don't care about factors, so let's have max(n, k log n).我们不关心因素,所以让我们有 max(n, k log n)。 But (a + b) / 2 <= max(a, b) <= a + b for a,b >= 0 so again neglecting factors we can turn this into n + k log n.但是 (a + b) / 2 <= max(a, b) <= a + b for a,b >= 0 所以再次忽略因素我们可以把它变成 n + k log n。

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

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