<p>Your question is not very different from set cover (it would be exactly set cover if you stopped as soon as you found a set containing $x$ rather than keeping going until you have determined $x$) and it's easy to adapt bad instances to set cover to show that the greedy algorithm can ask more questions than optimal by a logarithmic factor.</p>

<p>To see this, suppose that you have $n$ points in the plane, placed at the intersections of $k$ horizontal lines and a larger collection of vertical segments: $\lfloor k/3 \rfloor$ segments through triples of points on disjoint horizontal lines, $\lfloor k/4\rfloor$ segments through quadruples of points on, $\lfloor k/5\rfloor$ segments through five points, etc. Let $Q$ be the sets of points on each of these segments.</p>

<p><a href="https://i.sstatic.net/pkOir.png" rel="noreferrer"><img src="https://i.sstatic.net/pkOir.png" alt="enter image description here"></a></p>

<p>The greedy algorithm will begin by querying the vertical segments, in order from longest to shortest, because at each step this choice eliminates more points than taking any horizontal segment. Therefore, it uses a total of $(1-o(1))k\ln k$ tests in the worst case to find $x$. The optimal algorithm will take the horizontal segments first, taking $k$ steps to find a segment containing $x$ and at most $2k$ total to identify $x$. Since $n\approx k^2$, the factor $\tfrac{1}{2}\ln k$ by which greedy is bigger than optimal is $\Theta(\log n).$</p>

<p>(This is a standard counterexample for set cover. Its geometric realization, and the figure, are taken from my manuscript "<a href="https://11011110.github.io/blog/2017/07/26/forbidden-configurations-in.html" rel="noreferrer">Forbidden Configurations in Discrete Geometry</a>". Probably you could get the inapproximability ratio up to $\ln n$ by using hard instances for set cover but I think the geometry of this example makes it easier to understand.)</p>

<p>On the other hand, suppose that the optimal strategy for your problem takes $k$ questions in the worst case, and consider the specific sequence of at most $k$ questions that this strategy would follow against a greedy adversary (one that always chooses the answer that leaves the most remaining elements). One of these questions must eliminate at least $n/k$ elements at the time it is asked by the optimal strategy, and would eliminate at least as many elements if it is asked immediately, as the first question. So, at each step, the greedy algorithm also eliminates at least $n'/k$ elements, where $n'$ is the number of remaining elements. Therefore, its total number of steps is $\bigl(1+o(1)\bigr)k\ln k$. That is, the $\ln k$ approximation ratio that one could presumably prove by using worst-case set cover instances in place of the geometric example above is tight.</p>

CC BY-SA 3.0
2017-08-15T04:22:43.300Z
Why would the greedy algorithm need to eliminate at least $n'/k$ elements in each step? I don't think this holds.
domotorp
CC BY-SA 3.0
2017-08-15T05:07:15.387Z
Because there is exists a choice that would eliminate at least that many elements (the one from the optimal strategy against the greedy adversary) and the greedy algorithm will always choose something that eliminates at least as many.
David Eppstein
CC BY-SA 3.0
2017-08-15T05:35:13.607Z
I agree that this is true for the first step of the greedy algorithm, but in a later step we have no control over what elements remain at that step, and I don't see why there is such a question.
domotorp
CC BY-SA 3.0
2017-08-15T05:45:57.030Z
OK, now I remember how this goes. It must be used that a question from the optimal strategy eliminates at least $n'/k$ elements from any set of $n'$ elements, and thus so must the greedy, and all the calculations go as you wrote.
domotorp
CC BY-SA 3.0
2017-08-14T21:14:58.393Z
2017-08-14T22:03:33.743Z
2017-08-14T22:03:33.743Z
David Eppstein
<p>No. There's a huge literature on the topic, called combinatorial search theory, you can read more about these types of questions there.
The simplest example that I could think of is the following.</p>

<p>Suppose that you want to find an edge of a graph, and you can ask whether a given vertex is incident to the hidden edge, or not.
Now take the following bipartite graph.
It contains a perfect matching on $100+100$ vertices.
Moreover, it also contains $10$ degree $10$ vertices that are connected to $10$ different vertices each, all on the same side.
So one side of the graph has $100$ vertices, all degree $2$, the other $110$, of which $100$ have degree $1$, the other $10$ degree $10$.</p>

<p>In this case, the greedy algorithm would first query the degree $10$ vertices, and then the rest, taking about $110$ steps.
If instead it started with querying the $100$ vertices of degree $2$, it would be done in $101$ steps.</p>

CC BY-SA 3.0
2017-08-14T15:59:23.837Z
2017-08-14T15:59:23.837Z
domotorp
<p>The game of twenty questions can be generalized in the following way.</p>
<blockquote>
<p>Let <span class="math-container">$\Omega$</span> be a finite set and <span class="math-container">$\mathcal Q$</span> a collection of subsets of <span class="math-container">$\Omega$</span>, called the <em>questions</em>. A point <span class="math-container">$x\in\Omega$</span> is chosen unknown to the player, who then has the ability to iteratively choose a set <span class="math-container">$Q\in\mathcal Q$</span> and be told whether or not <span class="math-container">$x\in Q$</span>. The player's goal is to determine <span class="math-container">$x$</span>.</p>
<p>In order for the game to be solvable, <span class="math-container">$\mathcal Q$</span> is assumed to have the property that every <span class="math-container">$x\in\Omega$</span> can be realized as the intersection of some collection of elements of <span class="math-container">$\mathcal Q$</span> or their complements.</p>
</blockquote>
<p>What we want is a strategy to solve this game with <strong>optimal worst-case running time</strong>.</p>
<p>At any point in the game, we can assign to each question a pair of integers - the number of possibilities that will remain depending on whether the answer is yes or no. Assign to each question a score which is the larger of these two integers, and always pick the question with minimal score. This is the &quot;greedy&quot; strategy.</p>
<p><strong>Does the greedy strategy always have optimal worst-case running time?</strong></p>

<gt.game-theory><combinatorial-game-theory>
Can generalized twenty questions be solved by a greedy algorithm?
Jack M
# Can generalized twenty questions be solved by a greedy algorithm?

(Asked by: username_0 on 2017-08-14)

The game of twenty questions can be generalized in the following way.

> Let $\Omega$ be a finite set and $\mathcal Q$ a collection of subsets of $\Omega$, called the *questions*. A point $x\in\Omega$ is chosen unknown to the player, who then has the ability to iteratively choose a set $Q\in\mathcal Q$ and be told whether or not $x\in Q$. The player's goal is to determine $x$.
>
> In order for the game to be solvable, $\mathcal Q$ is assumed to have the property that every $x\in\Omega$ can be realized as the intersection of some collection of elements of $\mathcal Q$ or their complements.

What we want is a strategy to solve this game with **optimal worst-case running time**.

At any point in the game, we can assign to each question a pair of integers - the number of possibilities that will remain depending on whether the answer is yes or no. Assign to each question a score which is the larger of these two integers, and always pick the question with minimal score. This is the "greedy" strategy.

**Does the greedy strategy always have optimal worst-case running time?**

**Tags:** gt.game-theory, combinatorial-game-theory


---

## 2 answers

### Answer by username_2 on 2017-08-14. Score: 6 | Accepted answer

No. There's a huge literature on the topic, called combinatorial search theory, you can read more about these types of questions there.
The simplest example that I could think of is the following.

Suppose that you want to find an edge of a graph, and you can ask whether a given vertex is incident to the hidden edge, or not.
Now take the following bipartite graph.
It contains a perfect matching on $100+100$ vertices.
Moreover, it also contains $10$ degree $10$ vertices that are connected to $10$ different vertices each, all on the same side.
So one side of the graph has $100$ vertices, all degree $2$, the other $110$, of which $100$ have degree $1$, the other $10$ degree $10$.

In this case, the greedy algorithm would first query the degree $10$ vertices, and then the rest, taking about $110$ steps.
If instead it started with querying the $100$ vertices of degree $2$, it would be done in $101$ steps.


---

### Answer by username_1 on 2017-08-14. Score: 6

Your question is not very different from set cover (it would be exactly set cover if you stopped as soon as you found a set containing $x$ rather than keeping going until you have determined $x$) and it's easy to adapt bad instances to set cover to show that the greedy algorithm can ask more questions than optimal by a logarithmic factor.

To see this, suppose that you have $n$ points in the plane, placed at the intersections of $k$ horizontal lines and a larger collection of vertical segments: $\lfloor k/3 \rfloor$ segments through triples of points on disjoint horizontal lines, $\lfloor k/4\rfloor$ segments through quadruples of points on, $\lfloor k/5\rfloor$ segments through five points, etc. Let $Q$ be the sets of points on each of these segments.

[![enter image description here](https://i.sstatic.net/pkOir.png)](https://i.sstatic.net/pkOir.png)

The greedy algorithm will begin by querying the vertical segments, in order from longest to shortest, because at each step this choice eliminates more points than taking any horizontal segment. Therefore, it uses a total of $(1-o(1))k\ln k$ tests in the worst case to find $x$. The optimal algorithm will take the horizontal segments first, taking $k$ steps to find a segment containing $x$ and at most $2k$ total to identify $x$. Since $n\approx k^2$, the factor $\tfrac{1}{2}\ln k$ by which greedy is bigger than optimal is $\Theta(\log n).$

(This is a standard counterexample for set cover. Its geometric realization, and the figure, are taken from my manuscript "[Forbidden Configurations in Discrete Geometry](https://11011110.github.io/blog/2017/07/26/forbidden-configurations-in.html)". Probably you could get the inapproximability ratio up to $\ln n$ by using hard instances for set cover but I think the geometry of this example makes it easier to understand.)

On the other hand, suppose that the optimal strategy for your problem takes $k$ questions in the worst case, and consider the specific sequence of at most $k$ questions that this strategy would follow against a greedy adversary (one that always chooses the answer that leaves the most remaining elements). One of these questions must eliminate at least $n/k$ elements at the time it is asked by the optimal strategy, and would eliminate at least as many elements if it is asked immediately, as the first question. So, at each step, the greedy algorithm also eliminates at least $n'/k$ elements, where $n'$ is the number of remaining elements. Therefore, its total number of steps is $\bigl(1+o(1)\bigr)k\ln k$. That is, the $\ln k$ approximation ratio that one could presumably prove by using worst-case set cover instances in place of the geometric example above is tight.

> **Comments:**
> **username_2**: Why would the greedy algorithm need to eliminate at least $n'/k$ elements in each step? I don't think this holds.  
> **username_1**: Because there is exists a choice that would eliminate at least that many elements (the one from the optimal strategy against the greedy adversary) and the greedy algorithm will always choose something that eliminates at least as many.  
> **username_2**: I agree that this is true for the first step of the greedy algorithm, but in a later step we have no control over what elements remain at that step, and I don't see why there is such a question.  
> **username_2**: OK, now I remember how this goes. It must be used that a question from the optimal strategy eliminates at least $n'/k$ elements from any set of $n'$ elements, and thus so must the greedy, and all the calculations go as you wrote.  

---

