You have 6 coins of distinct weights and a beam balance with two pans. You devise an algorithm that identifies the second lightest coin with complete certainty with at most M weighings.
What is the minimum possible value of M ?
Consider trying this problem first.
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
This is also the method I ended up using.
I'm willing to accept the idea that it's mostly clear you need to know the lightest to know the second lightest. (Proving this seems interesting!)
That said, it isn't clear that the specific algorithm you mentioned to find the lightest is the best one to use as a basis for finding the second lightest. I.e., how do we know that there is not another 5-step algorithm to the lightest that only takes 1 more step to find the second lightest?
Log in to reply
How indeed. I'm looking forward to an actual proof myself, as these problems aren't my specialty, but I didn't want to see the problem without any solution I guess. The idea is that you need enough measurements to form the four relations (assuming E is second-lighest, F is lightest): A>E>F, B>E>F, C>E>F, and D>E>F.
Proving that you'll also know the lightest is easy. Suppose coin A is the second-lightest, and we don't know the lightest coin: it has two (or more) possibilities, B and C.
First, observe that no matter what the lightest coin is, we must have compared A with it. Otherwise, we can flip A and it in the position, and we can't tell the difference, but now A is the lightest coin, contradiction. Thus we must have compared A with at least one of B and C. WLOG we have compared A with B. Now, if B is heavier than A, then B can't be the lightest coin. And if B is lighter than A, then B must be the lightest coin (since we assumed A is the second-lightest), which means C can't be the lightest. Either way we get a contradiction: we assumed B and C are both possibly the lightest, but as it turns out, one of them can't be the lightest.
Note that the generalization to third-lightest and more is different. You'll know which coins are lighter than A and which are heavier, but not necessarily the order among them. The reason this gives the lightest coin if we assume A is the second-lightest is because there is only one lighter coin than A. If A is the third-lightest (and thus there are two lighter coins than A), we can't tell which of the two is actually the lightest.
Well if we have already obtained that B>D then the debate for the second lightest is between D & E which would require 1 comparison . That gives the answer to be 6
Log in to reply
Right you are; I'll edit to reflect worst-case scenario.
Minimal values of M (or, at least, the minimal values I've come up with), depending on the total number of coins:
1:0
2:1
3:3
4:4
5:6
6:7
Does this pattern continue?
Log in to reply
What pattern? ⌊ 2 3 ( n − 1 ) ⌋ ? Definitely not; the correct number is n + ⌈ lo g 2 n ⌉ − 2 (except for n = 1 , in which there is no second-lightest).
(By the way, I haven't actually managed to prove that this is the smallest possible. But it's definitely achievable, and it looks like it should be smallest. So take it as a conjecture.)
I don't understand why M=6 is not the good answer : if I start as for the sample problem, I can know the 3 lightest coins (we can suppose A,B and C without loss of generality) with 3 weighings. Then I can compare all pairs (A&B, A&C and B&C) with 3 other weighings, wich allow me to know the order of the 3 lightest coins, and in particular the second lightest coin. Then M=3+3=6. Where is the mistake? Thank you in advance!
Log in to reply
How do you know the 3 lightest coins after 3 weighings?
If you try to compare A<D, B<E, C<F, it's possible that the actual order from lightest to heaviest is A, D, B, E, C, F. Your three coins A, B, C are not the lightest three.
The smart-alec’s solution: you can do it in five taking note of the discrepancies in weighings. Fix A and weigh the other five against it, then observe how much each is displaced and you have the exact order of lightness.
I am not totally convince with your algorithim. Let us take as values wheight A=2 and B =1; C=5 and D=4; E=6 and F =3 Following your algorithim you discard A the second lightest up front.In my opinion you need 9 test like a sorting procedure.
Log in to reply
In this case, we'd get A>B, C>D, E>F, then D>B, F>B, telling us B is the lightest. Then we know the second-lightest must be one of A, D, or F. We test and get D>A and F>A, so A is second-lightest.
nice solutions. i am disappointed. i thought in the correct direction and then changed. thanks for the nice solutions.
Let the six coins be A , B , C , D , E , F , and start by weighing A v D , B v E and C v F . Suppose that A < D , B < E and C < F . The second lightest coin is either the middle coin of A , B , C or else the coin originally weighed against the lightest coin of A , B , C (in other words, if A < B < C , the second lightest coin could be D ). We can determine the order of A , B , C in three weighings - suppose that A < B < C . One more weighing of B v D tells us whether B or D is the second lightest coin. We can determine the second lightest coin in 7 weighings.
Since we do not know the weights of the various coins, there is no advantage to be gained by comparing the weights of groups of coins, so we must always simply compare one coin with another. For any algorithm, let us see where we have got to after the first three weighings.
I agree with "Since we do not know the weights of the various coins, there is no advantage to be gained by comparing the weights of groups of coins, so we must always simply compare one coin with another.", but I'm wondering if there is some (relatively simple) way to formalize this?
Log in to reply
A few examples sort this out. If we consider a set-up with four weights, and weigh A B v C D , A C v B D and A D v B C :
With such different outcomes/deductions from the same sets of experiments, we cannot hope to gain information from weighing the coins in groups. Of course, if we knew the exact weights of the coins, we could probably adopt a more efficient strategy...
This is one of only two solutions that even considered proving that 7 weighings are necessary, and the only one that actually went on to prove it (the other one didn't know how to prove it). Others were only proving it's sufficient (by finding an algorithm). That's why you got an upvote from me.
6 coins are A, B, C, D, E, and F.
Divide them into 2 groups: A, B, C / D, E, F.
Compare A and B, then compare heavier one between the 2 and C. The heaviest coin be expelled, and I've made 2 tries.
Do the same work with D, E, and F. Now, Here are 4 coins left, with 4 tries in total.
Now, compare 3 coins out of 4. with 2 tries, I may expel the heaviest coin. And since I know the relative weight of lighter 2 coins, now compare the heavier one of the two and F. Finally, expel the heavier one.
I have 2 lightest coins, knowing which is heavier. And therefore total tries are 2 × 2 + 2 + 1 = 7 .
That doesn't work... e.g. 1st A>B, A>C. Expel A. 2 tries. 2nd D>E, D>F. Expel D. 4 tries. 3rd (B,C,E) To find and expel heaviest: B>C, B>E, expel B. 6 tries. Now we have (C,E,F). And know nothing about relative weights of C and E... C>E and then C>F. 8 tries. We know nothing about the relative weights of E and F. E>F. 9 tries. So E. This solution doesn't work.
Instead of expelling heaviest, finding and keeping the lightest works: 1st A<B, A<C. Keep A. 2 tries. 2nd D<E, D<F. Keep D. 4 tries. 3rd A<D. A is lightest. 5 tries. 4th 2nd lightest is either B, C or D. So compare. B<C, B<D. 7 tries.
Log in to reply
I agree with "That doesn't work"
On the last step, if you compare b and c and b and d and b>c and b>d, then you still don't know which is second lightest and have to take an eighth try to compare c and d. So I don't think that works either
Log in to reply
Was this problem SO hard that led us to a contradiction? I'm just getting more and more confused.
If we designate the minimum value of M , for x ≥ 2 coins, as m ( x ) , then for any integer y ≤ x ,
m ( x + y ) ≤ m ( x ) + y + 1
(which establishes the bound that Ivan Koswara already gave, m ( x ) ≤ x + ⌈ lo g 2 x ⌉ − 2 , and in particular m ( 6 ) ≤ 7 , but I have not found a way to prove minimality).
P r o o f .
Step (1): Test any y distinct pairs of coins, and set aside the heavier coin from each test.
Step (2): Take the x coins that have not been set aside, and perform the appropriate m ( x ) tests to determine which out of those coins is the lightest and which is the second lightest, and designate them as CoinA and CoinB respectively.
Step (3): CoinA is the lightest out of all x + y coins, and the second lightest must be either CoinB or the coin (if there was one) that was tested against CoinA in Step (1), so testing these two coins against each other completes the task.
I think it should be ≥ , not ≤ . This is because in step (3), you are finding the lightest coin out of y + 1 coins (CoinB + y that you set aside in step (1)). This can be done in no less than y + 1 steps. In the worst case scenario, i.e. when you literally compare every one of the y + 1 coins, this takes y ( y + 1 ) / 2 steps. So using this procedure, we establish the bound m ( x ) + y + 1 ≤ m ( x + y ) ≤ m ( x ) + y ( y + 1 ) / 2 . This, by the way, gives you the minimality you were looking for.
The only issue now is to show that this procedure does in fact yield the minimum m ( x ) .
Upvote for generalizing it and for recognising you need to prove necessary and sufficient number of weighings (even though you haven't proven both).
Problem Loading...
Note Loading...
Set Loading...
Consider coins A, B, C, D, E, F. Knowing which coin is second-lightest inherently requires that you know which coin is the lightest (this isn't immediately obvious but easy to convince yourself). As shown in the sample problem, this requires at least five moves: make three comparisons and form winners and losers piles, let's say A>B, C>D, E>F, then make two comparisons within the losers pile, let's say B>F and D>F, showing F is the lightest. Then the second-lightest must be one of B, D, or E; two more comparisons will reveal the answer.