|
+10
I think the argument can be modified to get $$$n + O(\log n)$$$ total queries. At each stage of the binary search, define a potential to be the number of candidates that we have so far for the root, i.e., the sum of the sizes of all sub-trees that we binary search on. Suppose we have narrowed down the root to one of $$$k$$$ sub-trees of sizes $$$x_1 \geq x_2 \geq \dots x_k$$$ and that $$$x_1 + x_2 + \dots x_k = m$$$ . In our algorithm, we choose the smallest prefix whose sum is at least $$$m/4$$$ and query if the root is in one of these subtrees. To analyze the query complexity, let's consider the following cases. Case 1: $$$x_1 \leq m/2$$$ . In this case, the subset that we query has total size at least $$$m/4$$$ (by definition) and at most $$$m/2 + m/4 \leq 3m/4$$$. Hence, regardless of where the root lies, the number of potential candidates reduces to $$$3m/4$$$. Case 2: $$$x_1 \geq m/2$$$ In this case, we check whether the root is in the sub-tree $$$x_1$$$. If the answer is false, then we are down to at most $$$m/2$$$ candidates. If the answer is true, then in the next query we will be in Case 1 after centroid decomposition of the root at $$$x_1$$$. Hence, after every two binary searches, the number of candidates reduces by a factor of $$$3/4$$$. This leads to at most $$$n + 2 \cdot \log_{4/3} n$$$ queries which is at most $$$n + 48$$$ for $$$n \leq 1000$$$. (Sigh, the $$$48$$$ is much larger than I was hoping and sadly not dramatically different from $$$58$$$). I modified your submission and added an assert and this passes all cases. For analysis, I suspect the $$$1/4$$$ factor is optimal, because we only have a guarantee of at most $$$1/2$$$ after centroid decomposition, so using say a different factor $$$\lambda$$$ the best we could get is $$$\max(\lambda, 1/2 - \lambda)$$$ which is minimized at $$$\lambda = 1/4$$$. Not sure if the constant can be made better. |