-1

We are given n bolts and n nuts of different sizes, where each bolt exactly matches one nut. 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.

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.

Ami Tavory
  • 74,578
  • 11
  • 141
  • 185
J Doe
  • 1
  • 1

1 Answers1

0

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. 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. 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.

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}. In fact, even if you have a magic method that works only for e.g. 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. 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. So you need at least k log n comparisons.

So now we have an lower bound of max(n/2, k log n). We don't care about factors, so let's have 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.

mcdowella
  • 19,301
  • 2
  • 19
  • 25
  • Still a little confused, I get that we could sort them to the kth place in time klogn, but why isn't that enough? If such a decision tree existed, wouldn't we be guaranteed to get from root to leaf in klogn comparisons, and thus be guaranteed to avoid the sotuation where the last bolt checked is the one that matches? – J Doe Oct 07 '16 at 15:22
  • In deriving k log n, I have started by making the problem easier: you pretty much have all the bolts laid out before you labelled and in sorted order (which you cannot do in this problem because you cannot compare bolts to each other). So with this approach it should be no surprise that k log n is optimistic, and for small k is beaten by the bound of n/2 I get by considering a simple strategy for an adversary who wants to delay the time of the first match as far as possible. – mcdowella Oct 07 '16 at 17:55