The counterfeit Coin Problem

Don't exceed me, or else!

So we have this collection of N coins and we know that all but one of the coins have the same weight and that the counterfeit coin is say heavier than the other. We have to find a weighing plan that will minimize the probability that the total number of weighings required for the indentification of the the counterfeit coin will exceed a given value c.

This is the most difficult version of the Counterfeit Coin Problem that we examine. We therefore suggest that if you have not done it already, you should read the material on the other two versions before you proceed. We also assume that you are familiar with the notion of conditional probabilities and conditional expectation.

Ovserve that in this version of the problem we assume that Chance is represented by Mother Nature, which in turn is represented by Prof. Laplace. Hence all the coins yet to be inspected are equally likely to be the counterfeit coin.

So far so good!

The DP approach to this problem is as follows: we start with two innocent looking definitions:

f(n,k) :=
the probability that the total number of weighing will exceed c under an optimal policy given that n coins are left for inspection and that k weighings have already been conducted.
f(n,k | s) :=
the probability that the total number of weighings will exceed c under an optimal policy given that n coins are left for inspection, that k weighings have already been conducted and that we decide to put s coins on each side of the scale in the current weighing.

Then clearly, the following must be true:

f(0,k) =
k <= c
f(1,k) =
k <= c
f(n,k) =
k > c
f(n,k) =
f(n,k | s) , for some s in D(n), n>1.

The first two observations are trivial so let us examine the last two, starting with the third one. It says the obvious: if we are to do the best we can given m>1 coins given that we have already conducted k > c weighings, then clearly we have already exceeded the critical value c and therefore the probability is 1 that we shall exceed it at the end of the process.

The last observation is more subtle. It argues that given the situation (n,k,c) we shall have to do two things. Firstly we shall have to put some coins on the scale, say, s of them on each side, and then we shall have to do the best we can with the situation we shall face after we complete the this weighing. Of course, this does not help us much because we do not know the magic value of s for which the above equation is valid.

On second thought we observe that the magic value of s can simply be determined by enumeration, namely by evaluating f(n,k|s) for all s and then choosing the smallest value.

In other words, the above innocent looking definitions entail the following

f(n,k) =
min { f(n,k | s) : s in D(n) }, n>1.

All we have to do now is find a way of expressing the value of f(n,k|s) in terms of values of f(m) for values of m < n. For this purpose it would be instructive to re-examine the following picture

This is just a reminder that there are only three places to place the coins: A coin is either on the left-hand side of the scale or the right-hand side of the scale or off the scale. And since the first two events are equivalent from our point of view, we can manage with the following two events:

The following table summarises the situation with regard to the two events that can be generated by (n,s,k):

The two events that can be generated by (n,k,s)

EventProbability of eventProbability of failure*

CFC is on the scale



CFC is off the scale



CFC = "Counterfeit Coin" ; "failure" = Identifying the counterfeit coin in no more than c weighings.

In short, f(n,k|s) is equal to the expected value of f(n',k+1) where n' is the number of coins left for inspection after the current weighing. n' is a random variable that can take two possible values, namely either s or n-2s, with probabilities 2/n and (n-2s)/n, respectively. Thus,

f(n,k|s) =
(2s/n)f(s,k+1) + ((n-2s)/n)f(n-2s)

If we then combine (1) and (2), we obtain the following DP functional equation:

f(n,k) =
min { (2s/n)f(s,k+1) + ((n-2s)/n)f(n-2s,k+1) : s in D(n) } , n > 1 , (k <= c)

It can be translated into English as follows:

If we have n>1 coins to inspect then the best we can do is put s coins on each side of the scale and the do best we can with regard to the coins that will be left for inspection after the weighing. The optimal value of s is determined by computing the conditional probability of excedent for all feasible values of s according to Prof. Laplace's probabilities.

Observe that we are interested in computing the value of f(N,0).

The DP algorithm we use to solve the problem can thus be stated as follows:


  • Step 1: Initialization
        f(n,c+1) = 1, for all n=0,1,2,3,...,N

  • Step 2: Iteration
    For k = c,c-1,...,0 - in this order - DO:
       f(0,k)=f(1,k) = 0
       For n = 2,...,N determine the value of f(n,k) according to (1)-(3).
       Namely, compute
    f(n,k) =
    min { (2s/n)f(s,k+1) + ((n-2s)/n)f(n-2s,k+1) : s in D(n) }

The algorithm produces a report consisting of a table whose rows represent n and whose columns represent k. The entries are the values of f(n,k). The sets of optimal solutions for the (n,k) pairs are also presented in the table. The elements of these sets are enclosed within curly brackets.

The following is a small table generated for the pair (n=5, c=2).

n\c 012
00 , {}0 , {}0 , {}
10 , {}0 , {}0 , {}
20 , {1} 0 , {1}1 , {1}
30 , {1} 0 , {1}1 , {1}
40 , {1,2}1/2 , {1} 1 , {1,2}
50 , {1,2}3/5 , {1}1 , {1,2}

To illustarte how the algorithm works, let us pretend that we have already computed the values of f(n,k) for all n=0,1,2,3 and k=0,1,2. We shall now compute the value of f(4,1) according to (4).

f(4,1) =
min { (2s/4)f(s,1+1) + ((4-2s)/4)f(4-2s,1+1) : s in D(4) }
min { (2s/4)f(s,2) + ((4-2s)/4)f(4-2s,2) : s in {1,2} }
min { (2/4)f(1,2) + (2/4)f(2,2) , (4/4)f(2,2) + (0/4)f(0,2) }
min { (1/2)0 + (1/2)1 , 1 + (0/4)f(0,2) }
min { 0 + 1/2 , 1 + 0 }
min { 1/2 , 1 }
1/2 ,   D*(4,2)={1}

where D*(n) denotes the set of optimal values of s found while computing f(n,k). In due course there will be a facility to display the details of the right-hand side of (4) for any (n,k) pair.

Give it a try!

[Front page of Counterfeit Coin Problem ]