Challenging Math problem for the SMART PEOPLE HELP ~~~PLEASE

DDCSpeed

Golden Member
Nov 30, 2000
1,494
0
0
Need help for math. Call me dumb or stupid....I dont care but please help me do this math problem.


suppose you have a pile of n coins, and that you know that one of them is counterfeit and the rest are genuine. Suppose you also know that the counterfeit coin is lighter than the others. You have a balance scale: you can put any number of coins on each side of the scale and it will tell you whether the two sides weigh the same and, if they do not, which side is heavier.

a) show that any algorithm that solves this problem must use at least log3 N weighting.
b) Describe an algorithm for finding the fake coin that uses at most log3 N weightings.

 

amnesiac

Lifer
Oct 13, 1999
15,781
1
71
I got C's in calc II and III and then only because there were 3 people left in each class (the other 10 dropped it). Wish I could help you..
 

piku

Diamond Member
May 30, 2000
4,049
1
0
The only thing I can think of split up the pile in half (if its odd keep one out) and see which one is lighter - then take the lighter pile and split that in half, and repeat until the coin is found.

That isn't the answer that you need, but it would work I think :D
 

Pretender

Banned
Mar 14, 2000
7,192
0
0
you could probably use math induction, but being that I did not-so-well in precalc this year, I'm not voluntering here.

There was a trivia thread on a similar topic a few days ago about this, using 8 coins, but one was heavier than the rest. The solution was 2 weighings, and went like this:

put 3 on each side. If equal, then measure the remaining 2, and the heaviest is the one
If unequal, take the heavier side, and weigh 2 of the 3 coins. If equal, then the 3rd is the one. If unequal, it's the heavier of the 2.

In your case, you should probably replace lightest for heaviest, and find some way to generalize the problem. Sorry I can't be of more help
 

DDCSpeed

Golden Member
Nov 30, 2000
1,494
0
0
thanx for the help i received so far. It is getting more clear but what does log 3 N mean?
 

StormRider

Diamond Member
Mar 12, 2000
8,324
2
0
The only thing I can think of split up the pile in half (if its odd keep one out) and see which one is lighter - then take the lighter pile and split that in half, and repeat until the coin is found.

That isn't the answer that you need, but it would work I think


Yes, that would work but it's only a log2 N algorithm. We had similar types of questions when I was a TA, but unfortunately, I don't remember the method to use to show that the lower bound for any algorithm must use log3 N weighings (in fact, my intuition tells me the lower bound is log2 N weighings).
 

StormRider

Diamond Member
Mar 12, 2000
8,324
2
0
It is getting more clear but what does log 3 N mean?

log 3 N == the number you raise 3 to get N.

So, log3 9 is equal to 2.

 

StormRider

Diamond Member
Mar 12, 2000
8,324
2
0
Okay, now I understand why it is log3 N. Well, an algorithm that finds the counterfeit coin in (at most) log3 N weighings is the following:

1) Divide the N coins into 3 piles -- each with approximately N/3 coins. You will always be able to have 2 of the piles with the same number of coins.

2) Weigh the 2 piles with equal amount of coins. If one pile weighs less then pick that pile and repeat the process. If both are equal then pick the 3rd pile and repeat the process.

3) Eventually you will reach a pile with only 1 coin and that is the counterfeit.

Here's an example with 9 coins. We can construct 3 piles -- each with 3 coins each.

Now weigh the 1st two piles. Say the 1st pile weighs the least. We know the counterfeit coin is in the 1st pile. Take that pile and divide it into 3 new piles (each consisting of 1 coin). Weigh the first two coins. If they are equal then we know that the 3rd coin is the counterfeit.

So, it'll take 2 weighings to figure it out which is exactly what log3 9 is equal to. And this is a worst case scenerio.

I still haven't figured out how to prove that log3 N is a lower bound for any algorithm (this is what part a is asking for).

 

VRoOMdesigns

Guest
Aug 2, 2000
806
0
0
This is a classic question for consulting job interviews. A solution for n=12 can be found here.

Cut and pasted below:

<<

Practice Question #5

You have 12 balls. All of them are identical except one, which is either heavier or lighter than the rest. The odd ball is either hollow while the rest are solid, or solid while the rest are hollow. You have a scale, and are permitted three weighings. Can you identify the odd ball and determine whether it is hollow or solid?

This is a pretty complex question, and there are actually multiple solutions. First, we'll examine what thought processes an interviewer is looking for, and then we'll discuss one solution. (This question is reportedly in use at McKinsey, incidentally.)

Start with the simplest of observations. The number of balls you weigh against each other must be equal. Yeah, it's obvious, but why? Because if you weigh, say three balls against five, you are not receiving any information. In a problem like this, you are trying to receive as much information as possible with each weighing.

For example, one of the first mistakes people make when examining this problem is that they believe the first weighing should involve all of the balls (six against six). This weighing involves all of the balls, but what type of information does this give you? It actually gives you no new information. You already know that one of the sides will be heavier than the other, and by weighing six against six, you will simply confirm this knowledge. Still, you want to gain information about as many balls as possible (so weighing one against one is obviously not a good idea). Thus, the best first weighing is four against four.

Secondly, if you think through this problem long enough, you will realize how precious the information gained from a weighing is: You need to transfer virtually every piece of information you have gained from one weighing to the next. Say you weigh four against four, and the scale balances. Lucky you! Now you know that the odd ball is one of the unweighed four. But don't give into the impulse to simply work with those balls. In this weighing, you've also learned that the eight balls on the scale are normal. Try to use this information.

Finally, remember that consultants love that out-of-the-box thinking. Most people who work through this problem consider only weighing a number of balls against each other, and then taking another set and weighing them, etc. This won't do. There are a number of other types of moves you can make - you can rotate the balls from one scale to another, you can switch the balls, etc.
Let's look at one solution:

For simplicity's sake, we will refer to one side of the scale as Side A, and the other as Side B.

Step 1: Weigh four balls against four others.

Case A: If, on the first weighing, the balls balance
If the balls on our first weighing balance we know the odd ball is one of those not weighed, but we don't know whether it is heavy or light. How can we gain this information easily? We can weigh them against the balls we know to be normal. So:

Step 2 (for Case A): Put three of the unweighed balls on Side A; put three balls that are known to be normal on Side B.

I. If on this second weighing, the scale balances again, we know that the final unweighed ball, is the odd one.

Step 3a: Weigh the final unweighed ball (the odd one) against one of the normal balls. With this weighing, we determine whether the odd ball is heavy or light.

II. If on this second weighing, the scale tips to Side A, we know that the odd ball is heavy. (If it tips to Side B, we know the odd ball is light, but let's proceed with the assumption that the odd ball is heavy.) We also know that the odd ball is one of the group of three on Side A.

Step 3b: Weigh one of the balls from the group of three against another one. If the scale balances, the ball from the group of three that was unweighed is the odd ball, and is heavy. If the scale tilts, we can identify the odd ball, because we know it is heavier than the other. (If the scale had tipped to Side B, we would use the same logical process, using the knowledge that the odd ball is light.)

Case B: If the balls do not balance on the first weighing
If the balls do not balance on the first weighing, we know that the odd ball is one of the eight balls that was weighed. We also know that the group of four unweighed balls are normal, and that one of the sides, let's say Side A, is heavier than the other (although we don't know whether the odd ball is heavy or light).

Step 2 (for Case B): Take three balls from the unweighed group and use them to replace three balls on Side A (the heavy side). Take the three balls from Side A and use them to replace three balls on Side B (which are removed from the scale).

I. If the scale balances, we know that one of the balls removed from the scale was the odd one. In this case, we know that the ball is also light. We can proceed with the third weighing as described in step 3b from Case A.

II. If the scale tilts to the other side, so that Side B is now the heavy side, we know that one of the three balls moved from Side A to Side B is the odd ball, and that it is heavy. We proceed with the third weighing as described in step 3b in Case A.

III. If the scale remains the same, we know that one of the two balls on the scale that was not shifted in our second weighing is the odd ball. We also know that the unmoved ball from Side A is heavier than the unmoved ball on Side B (though we don't know whether the odd ball is heavy or light).

Step 3: Weigh the ball from Side A against a normal ball. If the scale balances, the ball from Side B is the odd one, and is light. If the scale does not balance, the ball from Side A is the odd one, and is heavy.

Whew! As you can see from this solution, one of the keys to this problem is understanding that information can be gained about balls even if they are not being weighed. For example, if we know that one of the balls of two groups that are being weighed is the odd ball, we know that the unweighed balls are normal. Once this is known, we realize that breaking the balls up into smaller and smaller groups of three (usually eventually down to three balls) is a good strategy - and an ultimately successful one.

>>
 

Jothaxe

Golden Member
Apr 5, 2001
1,274
0
0
Hmm... this is an interesting problem.


I believe you have correctly identified the algorithm that part b) is looking for.

However, I think there may be a mistake in the way the problem is stated.

For example, if we start out with 8 coins, it still takes 2 full weighings to determine the fake coin. But log3 8 < 2. Since there is no such thing as a fractional use of the scale, you would be required to find the coin in one weighing which is not possible for 8 coins.

The only way this issue is avoided is if N is limited to perfect powers of 3. Is this the case? Or is there perhaps some part of the problem that you havent given us?


Also, unless I am being naive, the requests in parts a) and b) seems a little strange. Part a) says that any algorithm must use at least log3 N weighings. But then part b) says to find an algorithm that does at least this well. If part a) is correct then part b) should only be asking for an algorithm that does exactly log3 N weighings at best. For cases where log3 N is irrational, I am pretty sure you have to round it up to the next integer. This is the best possible algorithm as far as I can tell.


I will fiddle around with part a) more and try to come up with a proof for it.

-jothaxe
 

Jothaxe

Golden Member
Apr 5, 2001
1,274
0
0
Ok, I think I can give a quick proof for part a) now:

To simplify things, I am going to consider the case that N is a power of 3. I believe the proof can easily be generalized for other values of N.

First, assume that there exists an algorithm that can sort through the coins in less than log3 N weighings.

Since an algorithm that does log3 N must eliminate exactly 2/3 of the coins in each weighing, this means that our hypothesized algorithm leaves less then 1/3 of the coins after each weighing.

In order to be left with a pile that holds strictly less then 1/3 of the coins, we are forced to divide the coins into more than 3 distinct piles. However, the scale allows for no more than 3 piles because we can only put any given coin 1) on the right side of the scale, 2) on the left side of the scale, or 3) off the scale.

This gives us a contradiction, because we can't have a number of piles that is both greater than 3 but also less than or equal to 3. This means our assumption was incorrect so we can say that there is no algorithm better than log3 N.


Note: This proof is pretty sketchy, but I think it is the right way to approach the problem. I am sure I could be more rigorous, but I dont have time to think about it more right now.

-jothaxe
 

DDCSpeed

Golden Member
Nov 30, 2000
1,494
0
0
Thank you all for helping me. I think i got the ideas that you guys give me. Thanks a lot to all that helped. ANANDTECH RULES