Solving the Mystery of the Poisoned Wine Bottle: O(log n) Solution

  • Thread starter suki2
  • Start date
  • Tags
    Mystery
In summary, the evil king has n bottles of wine, and a spy has just poisoned one of them. Unfortunately, they do not know which one it is. The poison is very deadly; just one drop diluted even a billion to one will still kill. Even so, it takes a full month for the poison to take effect. To determine which wine bottle was poisoned in just one month's time, the evil king decides to swear off the sauce. This requires testing each of the n bottles, but fortunately there is an algorithm that can do this in O(log n) testers.
  • #1
suki2
1
0
An evil king has n bottles of wine, and a spy has just poisoned one of
them. Unfortunately, they do not know which one it is. The poison is very deadly; just one drop diluted even a billion to one will still kill. Even so, it takes a full month for the poison to take effect. Design a scheme for determining exactly which one of the wine bottles was
poisoned in just one month's time while expending O(log n) taste testers.
 
Physics news on Phys.org
  • #2
You need log base 2 of n testers (round up).

Nobody tests bottle 1
Tester A tests all bottles that are a multiple of 2.
Tester B tests all bottles that are a multiple of 4, as well as the 1 bottle before that bottle
Tester C tests all bottles that are multiples of 8, as well as all 3 bottles before that bottle
Tester D tests all bottles that are multiples of 16, as well as all 7 bottles before that bottle

etc.

So you get something that looks like:

1 - nobody
2 - A
3 - B
4 - AB
5 - C
6 - AC
7 - BC
8 - ABC
9 - D
10 - AD
11 - BD
12 - ABD
13 - CD
14 - ACD
15 - BCD
16 - ABCD
17 - E
18 - AE
19 - BE
20 - ABE
...

Each bottle will have a unique combination of testers that die after a month is up. If (for example) bottle 13 is poisoned, testers C and D will die. If bottle 16 is poisoned, A, B, C, and D die. If bottle 1 is poisoned, nobody dies.


DaveE
 
Last edited:
  • #3
You can keep dividing the set in half, maybe making a rule that in the case of an odd numbered set the extra bottle goes in the first half. Each taster is then assigned to taste all the bottles in the first half of each subgroup.

That is, taster 1 tastes the first N/2 bottles. Taster 2 tastes the first N/4 bottles in each of the 2 groups of N/2 bottles. Keep going until someone is tasting every other bottle. In the end you'll get a tree, with each bottle. This demands that you use at most int(log2(N)) + 1 tasters.

Very similar in spirit to how many bits does it take to represent a number from 1 to N. Here, the "bi"t of information is poison or no poison (die or live).
 
  • #4
Evil king just swears off the sauce?

Restate the question as it is incomplete, not sure what O is?
J
 
  • #5
denverdoc said:
Evil king just swears off the sauce?

Restate the question as it is incomplete, not sure what O is?
J

"O" is notation for "worst case" in algorithmic analysis, and is called "Big Oh" notation. It's a way of telling *very* roughly what the worst case efficiency of the algorithm is. So you take the highest power term, strip it of any constants, and that's the notation.

So let's say I develop an algorithm for, I dunno, figuring out the shortest path between two nodes on a map of N nodes. If my algorithm always takes 3*N^2+1.5N+1 iterations, the "O" notation would be O(N^2). If my algorithm takes between 1 and N+1 iterations, "O" notation would be O(N). If it took 2N+5, it'd be O(N) again.

So O(log n) testers means that it takes at most some function of log n testers. You could easily devise an algorithm that took O(n) testers-- just have one tester for each bottle, and see who dies. But is there a better solution with worst case O(log n) testers?

DaveE
 
  • #6
"An" answer

The answer can be ONE:biggrin:
 
  • #7
didn't it say an evil king? let him die ;)

good job daveE i think that will be the best method
 
  • #8
Just had this on a test

I gave the first combination answer (which is what I'm sure the teacher wanted).

I also gave an alternate solution. This one:
You could easily devise an algorithm that took O(n) testers-- just have one tester for each bottle, and see who dies.
The teacher specifically clarified that "expending" tasters means that they'd die. So in that case, the above solution is O(1) which is of course better than O(lgn).
 
  • #9
denverdoc said:
Evil king just swears off the sauce?

Restate the question as it is incomplete, not sure what O is?
J

When I see the O, I think of "On the Order of" so a function 4x^4+x^2+1 is On the order of N^4, or O(N^4). Basically like a comparison of magnitude/order of magnitude for a function.
 
  • #10
Healey01 said:
When I see the O, I think of "On the Order of" so a function 4x^4+x^2+1 is On the order of N^4, or O(N^4). Basically like a comparison of magnitude/order of magnitude for a function.
If you correct this to:

so a function 4x^4+x^2+1 is On the order of x^4, or O(x^4).

I'll delete this message.
 

Related to Solving the Mystery of the Poisoned Wine Bottle: O(log n) Solution

1. How does the O(log n) solution work in solving the mystery of the poisoned wine bottle?

The O(log n) solution in solving the mystery of the poisoned wine bottle involves dividing the possible number of bottles into half with each iteration. This helps to narrow down the search space and find the poisoned bottle efficiently.

2. What is the significance of O(log n) in this problem?

O(log n) represents the time complexity of the solution, where n is the number of bottles. This means that the solution has a logarithmic time complexity, making it more efficient than other solutions with higher time complexities such as linear or quadratic.

3. How does the O(log n) solution compare to other solutions in terms of time complexity?

The O(log n) solution is more efficient than solutions with higher time complexities, such as linear or quadratic. It is also more efficient than a brute force approach, which would have a time complexity of O(n). This makes the O(log n) solution the most optimal solution for solving the mystery of the poisoned wine bottle.

4. Can the O(log n) solution be applied to other similar problems?

Yes, the O(log n) solution can be applied to other similar problems that involve searching for a specific item in a sorted list or array, where the search space can be divided into half with each iteration. This approach is known as a binary search and is commonly used in computer science.

5. Are there any limitations to the O(log n) solution in solving the mystery of the poisoned wine bottle?

The O(log n) solution assumes that the bottles are labeled with consecutive numbers and that the poison is evenly distributed among all the bottles. If these assumptions are not met, the solution may not work effectively. Additionally, the O(log n) solution may not be suitable for small numbers of bottles as the time complexity may not make a significant difference compared to other solutions.

Similar threads

Replies
16
Views
2K
Replies
39
Views
7K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
923
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • General Discussion
3
Replies
78
Views
9K
  • General Discussion
Replies
9
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
11K
  • Sci-Fi Writing and World Building
Replies
6
Views
2K
  • Math Proof Training and Practice
2
Replies
67
Views
10K
Back
Top