12
$\begingroup$

I'm interested on the following nice problem that is somewhat standard in CS, but I was surprised on the lack of references on the optimal algorithm to this problem.

Ana and Banana plays the following game: Banana creates a tree on vertices $1$, $2$, $\dots$, $n$ while not giving any information about it to Ana (except the fact that it has $n$ vertices $1$, $2$, $\dots$, $n$ and that it's a tree). After the graph was created, Ana is allowed to choose any two vertices $A$, and $B$ and ask Banana the value of $\text{dist}(A, B)$. Assuming that Banana always answers honestly, what is the minimum amount of queries required for Ana to find two vertices such that its distance is maximal in this graph regardless of how Banana creates this tree.

As the title says, we can by BFS show that we can find the diameter in $2n-4$ moves, the strategy is to simply start at a random vertex $A$, make queries to all the others vertices of the tree, pick the one vertex $X$ that maximizes the $\text{dist}(A, X)$ giving $n-1$ queries, then repeat the process with $X$ and notice that we don't need to make all the $n-2$ queries to find $B$ that maximizes $\text{dist}(B, X)$, as we can just notice that the information will be redundant.

The proof that this algorithm works can be given by contradiction and can be found here. Moreover, I have the heavy suspicion that $2n-4$ is the best possible. Let the minimum number be $f(n)$, then it is easy to see that $f(3) = 2$, and to prove that $f(4) = 4$, say that we have a graph with vertices $1$, $2$, $\dots$, then connect two vertices if Ana asks for their distance and label their edge with the distance. So, assume FTSOC that $f(4) = 3$, then we either have a vertex with degree $3$, or an "N" shape (notice that this graph can't be disconnected, so there are just two cases of tree to check). In the first case, put the label $1$, $2$, $1$ in some order, in case an "N" shape occurs, then label the middle diagonal with $2$. and the rest with $1$.

Update: It is possible to show the bound of $n$, re-imagine this problem as if B creates the tree as A makes queries, then B can always answer $1$ to a query of A if this query won't represent a cycle in the distance graph that I used in the above paragraph, and if it creates a cycle, B can just say the distance of the existing path. This shows that at least $n-1$ are necessary, I imagine that an approach can be made to show that achieving something like $n + \log n$ is possible.

Showing, however, that this is the best possible bound is very hard, the order of the queries matter, and so induction can't be applied very directly (I wouldn't rule out the possibility of some induction like argument). I'm thankful for a solution/references/improvements on this problem.

$\endgroup$
8
  • 1
    $\begingroup$ Is $n$ known to both players? And what exactly does "minimum amount of queries required to find" mean? If Ana is lucky, one query may suffice, if it happens to hit two vertices whose distance is $n-1$. So in that case no more than one query is "required". Do you mean the smallest number that is guaranteed to suffice, by some deterministic method and in every possible tree? $\endgroup$ Commented Sep 29 at 22:11
  • 1
    $\begingroup$ @JukkaKohonen More generally, we may consider the query complexity of a graph property. Alice has a graph $G$ and Bob is trying to compute some property of $G$, but Bob does not know $G$. Bob is limited to asking Alice questions of some specific form (in this case, he can pick any two vertices and ask for the distance between them). The question is how many queries does Bob need, if he is promised that the graph is a tree? As with other branches of complexity theory, we can ask for worst-case complexity or average-case complexity, but worst-case complexity is typically the default. $\endgroup$ Commented Sep 30 at 1:59
  • 1
    $\begingroup$ The OP's problem is a little unusual for two reasons: (1) Querying distances is not so typical; more typical is to query the existence or non-existence of an edge. (2) We are promised that the graph is a tree. Promise problems are typically less well-studied than problems where Alice's graph could be any graph. $\endgroup$ Commented Sep 30 at 2:01
  • 1
    $\begingroup$ Can't one do an exhaustive search with min-max and compute the exact values for small n? $\endgroup$ Commented Sep 30 at 6:27
  • 1
    $\begingroup$ It is possible to show that at least $n-1$ questions are required, say that each time that Ana asked a question Banana answered with $1$ if it doesn't create a cycle, and otherwise it just answers the path distances. $\endgroup$
    – Curious
    Commented Oct 10 at 23:25

0

You must log in to answer this question.

Browse other questions tagged .