First solution. First we provide a proof that k≥n−1. Let T be the path where vi and vi+1 are adjacent for all 1≤i≤n−1. Let ω be a primitive root of unity of order n and let ai=ωi for all 1≤i≤n.
If f(X)=P(X,ωX), then for all 1≤i≤n−1 we have f(ωi)=P(ai,ai+1)=0. Since f(1)=P(an,a1)=0, f is non-zero and has at least n−1 roots. This means that degP≥degf≥n−1, proving k≥n−1.
It remains to prove that k=n−1 is sufficient i.e. for any tree T and any a1,a2,…,an we can find a polynomial P of degree at most n−1. For brevity, we call a two-variable polynomial A(X,Y) symmetric if A(X,Y)=A(Y,X).
We begin with the following observation. Suppose that A and B are two variable polynomials of degree at most d. Then we can find α∈C such that for any 1≤i,j≤n, A(ai,aj)+αB(ai,aj)=0 if and only if A(ai,aj)=B(ai,aj)=0. This means that we can "merge" two conditions of degree at most d into a condition of degree at most d (note that this produces a symmetric polynomial if the initial polynomials are symmetric).
For any integer t≥2, let a star of size t be a collection of t edges for which there is a vertex which belongs to all edges. We will prove the following claims.
Claim 1. Let G be a graph with vertices v1,v2,…,vn and E edges. Suppose that we can partition the edges of G into a number of stars. Then for any distinct complex numbers a1,a2,…,an we can find a symmetric polynomial P of degree at most E such that for all 1≤i,j≤n,i=j, P(ai,aj)=0 if and only if there is an edge between vi and vj in G.
Proof. We will first prove the claim when G consists of a star of size E≤n−1 and some isolated vertices. Without loss of generality, let v1v2,v1v3,…,v1vE+1 be the edges of G. Also let s1=a1+a2,s2=a1+a3,…,sE=a1+aE+1.
Consider merging the polynomials (X−a1)(Y−a1) and (X+Y−s1)(X+Y−s2)…(X+Y−sE) into a polynomial of degree at most E (which is of course symmetric). They both vanish at a pair ai,aj if and only if 1∈{i,j} and ai+aj∈{s1,s2,…,sE}. These two happen if and only if vi and vj are adjacent, so this produces a valid polynomial.
For the general case, let S1∪S2∪⋯∪Sk be the partition of the edges of G. For each 1≤i≤k, we can find a two variable polynomial Pi of degree at most ∣Si∣ which vanishes only at the edges of Si. Then we can let P=P1P2…Pk, which satisfies the claim as degP≤∣S1∣+∣S2∣+⋯+∣Sk∣=E, as desired.
Claim 2. Any tree Γ with odd number of vertices can be partitioned into stars of size 2.
Proof. We prove this by induction on the number of the vertices of Γ. The base case is clear, since Γ is a star of size 2 when Γ has three vertices.
For the inductive step, let Γ be a tree with 2m+1 vertices, where m≥2. Let u1u2…ut be a path of maximal length in Γ (of course, t≥3). Then any neighbour of u2 except for maybe u3 must have degree 1, otherwise we can delete u1 and insert two edges, contradicting the maximality of t. If degu2=2, we can form the star u1u2,u2u3 and apply the inductive hypothesis on Γ∖{u1,u2}. If degu2≥3, let u=u1,u3 be a neighbour of u2. Then create the star u1u2,uu2 and apply the inductive hypothesis on Γ∖{u,u1}. This proves the claim.
The case where n is odd becomes trivial, since T has n−1 edges. Assume that n is even. Without loss of generality, let degvn=1 and let vn be adjacent to vn−1.
Consider the graph T′ formed by deleting the edge vn−1vn from T (but not permuting the n vertices). Clearly, T′ consists of vn and a tree on v1,v2,…,vn−1. As n−1 is odd, the edges of T′ can be partitioned into stars of size 2 from Claim 2. From Claim 1 it follows that there is a symmetric polynomial Q(X,Y) of degree at most n−2 such that Q(ai,aj)=0 if and only if i,j≤n−1 and vi,vj are adjacent in T.
Let g(X) be the polynomial of degree n−1 such that g(a1)=g(a2)=⋯=g(an−1)=0 and g(an)=−Q(an−1,an)=−Q(an,an−1). Let P be the polynomial of degree at most n−1 obtained by merging F1(X,Y)=Q(X,Y)+g(X)+g(Y) and F2(X,Y)=Q(X,Y)(X+Y−s), where s=an+an−1. It is easy to see that P vanishes at each (ai,aj) for which vi,vj are adjacent in T.
Suppose that vi and vj are not adjacent in T. If i,j≤n−1, then F1(ai,aj)=Q(ai,aj)=0. If n∈{i,j}, then ai+aj=s and Q(ai,aj)=0, so F2(ai,aj)=0. Hence P(ai,aj)=0. This proves that P satisfies the required conditions, as desired.