Follow Up: Yoak: Batteries, and the Problem of the Week

{ Hi, Steve here. Jeff asked me to post a solution and I’m more than happy to oblige. It’s a fun puzzle with some nice maths to explore. I learnt a lot about graph theory and a new theorem (new to me), Turan’s theorem. More on that later. }

In Yoak: Batteries, and the Problem-of-the Week Jeff posed a great problem from Stan Wagon’s Problem of the Week.

You have eight batteries, four good and four dead. You need two good batteries to work the device; if either battery is dead then the device shows no sign of life. How many tests using two batteries do you need to make the device work?

In some similar sounding puzzles we might change the tests depending on the results we get as we go along. That doesn’t work here. We will stop if any test succeeds, we only carry on as long as the tests fail. We never get any information that we could use to choose our next test. That means we can choose the combinations we are going to use before we start our tests.

There are two ways of posing this problem. The one we have used is to make the device work. The other is to identify two working batteries which requires one less test.

Another problem is to find all four working batteries (which laciermaths neatly dealt with in the comments) and yet another is to find the most efficient approach which minimises the average number of tests.

The following seven combinations are guaranteed to make the device work.



Any six of these tests will identify two working batteries, for example our tests could be:


If all of these tests fail then at most one battery from {1,2,3} can work and at most one battery from {4,5,6} can work. As we know there are four good batteries we can deduce that both 7 and 8 are working batteries.

So we have an answer to the problem, six tests are sufficient to identify two good batteries and seven tests are sufficient to work the device.

But hold on a minute! We haven’t yet shown that there isn’t an answer with fewer tests.

I came up with a proof but I won’t repeat it here because Jim Schmerl gave a much better one to POW. The better proof works for any number of batteries with any number being good.

It says: With n batteries and r good batteries then the best solution is to split the batteries into r-1 groups of roughly equal size and then test each pair within each group.

Let’s consider our seven tests again.

Here n is 8 and r is 4. We split the batteries into r-1 = 3 groups and test each pair in each group. At least one group has two good batteries so this will definitely give a solution.

These sorts of diagrams are called graphs. A graph is just a set of vertices connected by edges. A graph with v vertices and all possible edges is called Kv. Our solution consists of K3, K3 and K2.

Now how do we show that this is minimal. Well we have some clever tricks.

The figure above is certainly a solution but it isn’t minimal.

7 has three edges and 8 has just one edge. We can reduce the number of edges by a procedure I call ‘Make 7 like 8’. The procedure involves:

1.    Remove all edges from 7.

2.    Connect 7 to the same vertices as 8.

3.    Connect 7 to 8.

That procedure gives:

We now have 11 edges instead of 12.

If we start with a solution then the ‘Make a like b’ procedure will give another solution. Why is this?

  • If the four good batteries include both 7 and 8 then they will be tested as we test the pair 7 and 8.
  • If the four good batteries do not include 7 then they are tested in the original solution and so will be tested in the new solution. We have only changed tests that include 7.
  • If the four good batteries include 7, but not 8, then they will be tested. The equivalent group, replacing 7 with 8, is tested. For example consider {1,4,6,7}. The equivalent group is {1,4,6,8}. We know this is tested as it doesn’t involve 7 and so is tested in the original solution. But 7 connects to the same vertices as 8 so {1,4,6,7} is tested in the new solution.

We can repeat this trick as often as we like. You might like to play around with it, start with a solution with a ridiculous number of edges and see how far you can reduce it by repeating this trick.

The number of edges connected to a vertex, a, is called the degree of a which is written d(a). The procedure ‘Make a like b’ will reduce the number of edges if d(a) > d(b) + 1.

We can therefore make the following claim:

Claim 1: In an optimal solution the degree of any two vertices will differ by no more than one.

So far so good but we need to go a bit further. We can use the same trick to show the following:

Claim 2: In an optimal solution if a-b and b-c then a-c (where a-b means there is an edge between a and b).

This means the solution splits the batteries into groups where each pair within a group is tested.

Proof of Claim 2:

Suppose there is a chain a-b-c but there is no edge between a and c (so a-c is not true). We can always reduce the number of edges.

Case 1: If d(b) > d(a) we ‘Make b like a’. This reduces the number of edges by at least one, we remove the b-c edge.

Case 2: Similarly if d(b) > d(c) we ‘Make b like c’.

Case 3: Otherwise we have d(b) <= d(a) and d(b) <= d(c). We ‘Make a like b’ and then ‘Make c like b’. These two procedures will also reduce the number of edges by at least one.

To illustrate this lets go back to our example. We left it like this.


We have the chain 1-3-5 but not 1-5. d(3) > d(1) so we ‘Make 3 like 1’. That gives:

Now we have the chain 4-5-6 but not 4-6. As d(4) <= d(5) and d(6) <= d(5) we have the third case. First ‘Make 4 like 5’ and then ‘Make 6 like 5’.

What our two claims show is that an optimal solution will split the batteries into roughly equal groups (the degree of any two vertices can differ by no more than one), each pair within a group is tested.

It only remains to show that we should use three groups.

More than three groups is not a solution, we could have one good battery in each group.

The other possibilities are to have one group, K8, which has 28 edges or to have two groups, K4 and K4, which has 12 edges.

So having three groups, with 7 edges, is optimal.

In the general solution we should have as many groups as possible which is r-1.


So this proves the general solution we have before: With n batteries and r good batteries then the best solution is to split the batteries into r-1 groups of roughly equal size and then test each pair within each group.


This is equivalent to Turan’s theorem.

For an optimal solution we need to consider the ‘complement graph’. This just means the graph with an edge precisely where our solution graph doesn’t have one. As our solution has 7 edges and there are 28 possible edges the complement graph has 21 edges. Such a graph is called a Turan graph.

The Turan graph can be got by splitting the vertices into r-1 groups and then connecting each pair which are not in the same group.

Since each group of four vertices in the solution graph contains at least one edge the same four vertices in the complement graph are missing an edge. In other words the complement graph does not contain K4 , it is K4-free.

Turan’s theorem says the graph with n vertices with the most edges which is Kr-free is the Turan graph, exactly the complement of our solution graph.

RSS feed for comments on this post · TrackBack URL

Leave a Comment

You must be logged in to post a comment.

The Math Factor Podcast Website

Quality Math Talk Since 2004, on the web and on KUAF 91.3 FM

A production of the University of Arkansas, Fayetteville, Ark USA

Download a great math factor poster to print and share!

Got an idea? Want to do a guest post? Tell us about it!

Heya! Do us a favor and link here from your site!