Solution:
a. f(n)=n−3.
- Asking n−4 questions is not enough since the n−4 people queried might be sitting in a consecutive string, in which case the n−4 answers allow one to sit n−2 people in the same positions as yesterday, but there is still an ambiguity among the two remaining ones.
- Let us show that n−3 questions suffice. Among the 3 people who are not queried, at least 2 must sit next to people who have been queried. If exactly 2 do, then both these people must be neighbours of the third, so that the neighbours of everybody are known and we are done. If all 3 unqueried people sit next to a queried person, then at least one of them has two queried neighbours, and again it follows that the neighbours of everybody are known, so that we are done.
b. g(n)=n−1−⌈3n⌉(=n−1−⌊3n+2⌋=⌊32n⌋−1=⌈32n−5⌉).
Say there is a link between two people if and only if they are neighbours. There are in total n links, which we all need to identify. By asking a person for his neighbours, we can discover at most two new links. More precisely, if at any point we query a participant who has not yet been pointed as a neighbour, we discover exactly two new links (we call this a type-0 query). If we query a participant who has been pointed once as a neighbour, we will discover exactly one new link (we call this a type-1 query). Of course, querying a participant who has already been pointed twice provides no information (and we assume in the rest of this solution that it never happens).
First note that, since f(4)=1, we also have g(4)=1. We now prove the formula for g(n) for n≥5.
- Let us show that n−1−⌈3n⌉ questions suffice. Our strategy consists in making sure that the first ⌈3n⌉ queries are type-0. Let us show that this is always possible. A type-0 query requires a participant that hasn't been queried or pointed before. Since the number of those participants decreases by three at most after each query, we see that it is always possible to perform ⌈3n⌉ type-0 queries first. During this phase we discover 2⌈3n⌉ links.
The remaining queries will be either type-0 or type-1, and each of them discovers at least one new link. We perform them until n−1 links have been discovered, after which we are done (the last link can be deduced without query). The number of queries in this second phase is therefore at most n−1−2⌈3n⌉, and the total is at most ⌈3n⌉+(n−1−2⌈3n⌉)=n−1−⌈3n⌉.
- We now show that n−2−⌈3n⌉=g^(n) questions are not enough.
(i) Consider the pool of unqueried and unpointed participants; each type-0 must query this pool. Since, from the point of view of the questioner, all elements of the pool are undistinguishable, we can assume that each type-0 query asks the second leftmost participant in the pool (except if there is only one element left in the pool). One can then check that the pool, which starts as a string of n contiguous participants, will stay contiguous after each type-0 and type-1 query. Furthermore, using our assumption, we see that each type-0 query removes three participants from the pool. Therefore there can be at most ⌈3n⌉ type-0 queries in the scenarios corresponding to our assumption.
(ii) Assume there are k type-0 queries. Since there are g^(n) queries, the number of discovered links is equal to 2k+(g^(n)−k)=g^(n)+k=n−2+k−⌈3n⌉. If k is strictly less than ⌈3n⌉, we discover strictly less than n−2 links, which is clearly insufficient (indeed, there are at least three missing links, and one can check that whatever the configuration of the missing links, there are always several orders compatible with the discovered links).
(iii) We now analyze the remaining case with k=⌈3n⌉ type-0 queries, in which we discover n−2 links. On the one hand, if the missing links are disjoint, there are always two orders compatible with the discovered links (for example when n=7 and links are missing between the (4,5) and (7,1) pairs of neighbours, the two orders are 1−2−3−4 5−6−7 and 1−2−3−4 7−6−5). On the other hand, a situation where the two missing links would be adjacent would allow the identification of the correct order. However, this never happens in the scenarios corresponding to the assumption we made in (i). Indeed, two adjacent missing links imply that some participant is unqueried and unpointed at the end of the process. Since we perform k=⌈3n⌉ type-0 queries (the maximum), the reasoning from (i) shows that the pool of unqueried and unpointed participants is empty at the end of the process, which contradicts the existence of two adjacent missing links.