# Splitting a binary tree as evenly as possible gives the most balanced samples at every sample size

Pick a set of tips from a binary tree, one that splits in two at each fork, and trace them back to their common ancestor. How often does the resulting sample split as evenly as possible at every fork? To judge how large that fraction is in a particular tree, we need to know the largest fraction possible in a tree of its size. The answer was known in the limit of very large binary trees. That limit leaves room for a different tree to do better at any finite size.

We prove that one rule gives a tree that attains the maximum for every sample size $k$ from 1 to the total number of tips $n$. Split the tips into two groups whose sizes differ by at most one, and repeat within each group. The key is how to balance an uneven tree without losing balanced samples. Moving one tip toward balance can lose copies of the shape we want. Regrouping whole branches lets us balance the tree while keeping at least as many copies.

## What counts as a balanced sample?

A rooted binary tree starts at a root and has two children at each fork. The tips, also called leaves, have no children. Left and right do not matter. A sample is a subset of distinct leaves. To see its shape, keep the paths from the chosen leaves to their lowest common ancestor, the first point they all share when traced back toward the root. Wherever just one child remains, remove that fork by contracting the path. Each subset counts once, even if many subsets give the same shape.

Write $E_n$ for the tree built by splitting $n$ leaves as evenly as possible at every fork. It is called the *even tree* even at odd sizes: $E_7$ splits into $E_3$ and $E_4$. A copy of the target shape $E_k$ in a host tree is a sample whose shape is $E_k$. Since every host with $n$ leaves offers the same number of samples of size $k$, maximizing the number of copies also maximizes their fraction.

Czabarka, Székely and Wagner showed that, for fixed $k$, the fraction of samples shaped like $E_k$ in $E_n$ approaches the largest possible limiting fraction as $n$ grows. Their [Conjecture 1, p. 8](https://arxiv.org/pdf/1601.07149) states: “For every $n\ge k$, $E_n$ has the largest number of copies of $E_k$ among all binary trees with $n$ leaves.” For four-leaf samples, [Coronado and colleagues](https://arxiv.org/abs/1803.01651) proved that $E_n$ is the unique maximizer for $n\ge4$. Our result proves the binary conjecture in full. It also settles the case $d=2$ of [Conjecture 1.1 of Dossou-Olory and Wagner](https://ajc.maths.uq.edu.au/pdf/81/ajc_v81_p001.pdf), who asked the question for trees with between two and $d$ children per fork.

## Counting copies at a fork

Let $A(n,k)$ be the number of copies of $E_k$ in $E_n$. For $1\le k\le n$, our theorem says this is the exact maximum. To compute it, let $p=\lfloor n/2\rfloor$ and $q=\lceil n/2\rceil$ be half the host size rounded down and up. These are the sizes of its two branches. The target branches likewise have sizes $r=\lfloor k/2\rfloor$ and $s=\lceil k/2\rceil$. A copy either lies wholly in one host branch or uses both. Write $C(n,k)$ for the number that use both, or *cross* the root. For $n\ge k\ge2$,
$$
 A(n,k)=A(p,k)+A(q,k)+C(n,k),\qquad
 C(n,k)=A(p,r)A(q,s)+{\bf1}_{r\ne s}A(p,s)A(q,r).
 \tag{1}
$$
Each product counts ways to choose one target branch on each side. The indicator $\mathbf{1}_{r\ne s}$ includes the second product only when reversing the target sizes gives a different assignment. The same rule counts copies when we join any two trees under a new root: use each tree's own counts on the right.

The starting counts are $A(n,1)=n$ and $A(n,k)=0$ for $n<k$. We allow an empty branch $E_0$. Joining it to a tree leaves that tree unchanged, and there is one empty sample, so $A(n,0)=1$. To shrink $E_n$ by one leaf, follow the larger child at each fork (either child at a tie) and delete the leaf reached. The result is $E_{n-1}$. All copies in that smaller tree are therefore present in the larger one: $A(n,k)$ never decreases with $n$, and it is positive for $n\ge k$.

## Two ways to balance the root

Consider a root whose branches are even trees of sizes 1 and 6. The six-leaf branch itself gives one copy of $E_6$. Move one leaf toward the smaller branch and rebuild both branches as even trees of sizes 2 and 5. Now there are no copies: neither branch holds six leaves, and a copy crossing the root needs three on each side.

Instead, keep the branches one level below the children intact. Write $(x,y)$ for the sizes of the two branches of the smaller child and $(z,w)$ for those of the larger child, listing the smaller grandchild first in each pair. Treat a single leaf as $(0,1)$. Exchange two grandchildren so that the new pairs are $(x,w)$ and $(z,y)$. If the original children are even trees, each original pair differs in size by at most one. The new pairs then have totals that differ by at most one, so the root is balanced.

We used (1) to compare the moves on every unbalanced root split with even children through 150 host leaves. For the exchange, we counted copies before making any further changes to the children.

Table 1. Changes in the number of copies on the same 537,573 starting configurations. Each row covers $4\le k\le n\le150$ and all smaller branch sizes $1\le a<\lfloor n/2\rfloor$.

| Balancing move | Fewer copies | Same count | More copies |
|---|---:|---:|---:|
| Transfer one leaf and rebuild the two even branches | 215,287 | 92,486 | 229,800 |
| Exchange two grandchild branches | 0 | 292,824 | 244,749 |

The exchange never lost a copy in this count. The proof that it works at every size rests on a comparison between two ways to place samples of sizes $i<j$ in branches of sizes $x\le z$. Subtract the number of choices with the larger sample in the smaller branch from the number with the larger sample in the larger branch:
$$
 D(x,z;i,j)=A(x,i)A(z,j)-A(x,j)A(z,i).
 \tag{2}
$$
Where the counts are positive, $D\ge0$ means that the ratio $A(n,j)/A(n,i)$ does not decrease as the host grows. If we arrange the counts in a table with host sizes as rows and sample sizes as columns, (2) is a two-by-two minor of the table. When every such difference is nonnegative, the table has *total nonnegativity of order two*, also called the TP2 property.

The proof proceeds one target size at a time. For target size $K$, the first lemma shows that the exchange works if (2) is nonnegative for sample sizes through $\lceil K/2\rceil$. The second lemma gives the needed comparison from the result for smaller targets. This is why we prove the maximum at every host size before increasing the target size.

## Lemma 1. Why exchanging grandchildren preserves copies

Fix $K\ge4$. Suppose even hosts maximize the counts for all smaller targets at all host sizes. Suppose also that $D(x,z;i,j)\ge0$ whenever $0\le x\le z$ and $0\le i<j\le\lceil K/2\rceil$. Then $E_n$ attains the maximum for $E_K$ at every $n\ge K$.

To prove this, increase the host size $n$ by induction. For $n<K$ there are no copies. For a host of size $n$, first replace its children by even trees of their respective sizes $a\le b$. Copies wholly inside a child cannot decrease, because the claim for $K$ already holds at smaller host sizes. Copies crossing the root cannot decrease either, because the target branches are smaller targets. The four grandchildren now have sizes
$$
 x=\lfloor a/2\rfloor,\quad y=\lceil a/2\rceil,\quad
 z=\lfloor b/2\rfloor,\quad w=\lceil b/2\rceil .
$$
This includes $a=1$, with parts $E_0$ and $E_1$. We compare the counts before and after changing the pairs from $(x,y),(z,w)$ to $(x,w),(z,y)$.

Two sample sizes at a fork are *compatible* if one is zero or if they differ by at most one. In the first case the fork disappears when the sample is traced back. When both sides are occupied, their sizes must differ by at most one for the fork to split evenly. For sample sizes $i,l,j,m$ in the four grandchildren, let $T(i,l;j,m)$ equal 1 if all three pairs $(i,l),(j,m),(i+l,j+m)$ are compatible, and 0 otherwise. This tests both child forks and the root. In any copy, the sample within each occupied grandchild must itself be even: it forms a branch of the induced even tree, or the whole tree if the rest is empty. Once these samples are even, $T$ tells us exactly whether they fit together to make $E_K$.

Group the assignments of sample sizes summing to $K$ by allowing two independent swaps: between positions $x,z$ and between positions $y,w$. Start with $i<j$ at $x,z$ and $l<m$ at $y,w$. The assignment to $(x,y,z,w)$ is then $(i,l,j,m)$, with weight $A(x,i)A(y,l)A(z,j)A(w,m)$. Its change in count is this weight times the change in the compatibility test. Swapping $i,j$ reverses the sign of that change, as does swapping $l,m$; doing both restores its sign. Summing over the four assignments gives the following contribution to the new count minus the old:
$$
 [T(i,m;j,l)-T(i,l;j,m)]\,D(x,z;i,j)D(y,w;l,m).
 \tag{3}
$$
Ties contribute zero by the same symmetry. To see the sign of the bracket, consider the old grouping. If $i+l>0$, its two occupied sides cannot be compatible because $j+m\ge i+l+2$. If $i=l=0$, both groupings simply test compatibility of $j,m$. Thus the bracket is nonnegative. When it is positive, both new children are occupied and split the sample evenly between them. No grandchild sample can then exceed $\lceil K/2\rceil$. Both differences in (3) are nonnegative by hypothesis, since $x\le z$ and $y\le w$. Summing over assignments proves that the exchange cannot lose copies.

The new child sizes $x+w$ and $y+z$ differ by at most one: their difference is $(w-z)-(y-x)$, and both terms are 0 or 1. Replace the children by even trees once more, using the same induction as before. The result is $E_n$.

## Lemma 2. How the advantage of a larger branch grows

We can compare any two sample sizes by comparing consecutive sizes first. For $n\ge t$, write $S(n,t)=A(n,t+1)/A(n,t)$. We need this ratio to increase as the host grows. The proof gives a lower bound on how much it increases. That margin lets us first count only copies crossing the root, then account for the ones we left out.

Suppose the even host maximizes the counts for all even targets of sizes $1,\ldots,t+1$ at every host size. Then for $t\ge1$ and $n\ge t+2$,
$$
 \frac{S(n,t)}{S(n-1,t)}\ \ge\ 1+\frac{1}{2nt}.
 \tag{4}
$$

### Large hosts and the finite base check

First split a uniformly chosen leaf of $E_{n-1}$ into two sibling leaves. Each old $k$-leaf copy gives at least one copy in the new tree. If the sample used the split leaf, it gives two, because we can choose either sibling. The expected number obtained this way is $(1+k/(n-1))A(n-1,k)$. Conversely, deleting a uniformly chosen leaf of $E_n$ preserves a fraction $1-k/n$ of its copies on average. Comparing each expected count with the maximum at the resulting host size gives, for either $k=t$ or $k=t+1$ and $n>k$,
$$
 1+\frac{k}{n-1}\ \le\ \frac{A(n,k)}{A(n-1,k)}
 \ \le\ \frac{n}{n-k}.
$$
Use the lower bound for $t+1$ and the upper bound for $t$. The left side of (4) is at least
$$
 \frac{(n+t)(n-t)}{n(n-1)}
 =1+\frac{n-t^2}{n(n-1)} .
 \tag{5}
$$
This proves (4) for $n\ge2t^2$.

For $1\le t<32$ we checked the remaining range, including the endpoint: $t+2\le n\le2t^2$. We built $A$ using (1), set $u=A(n-1,t)A(n,t+1)$ and $v=A(n,t)A(n-1,t+1)$, and tested (4) in the integer form $2nt(u-v)\ge v$. Among the 20,305 pairs the minimum of $2nt(u-v)/v$ was 6, attained at $(n,t)=(5,3)$.

An independent count reproduced these inequalities by assigning each copy to its lowest common ancestor. That is the unique fork the copy crosses with all its leaves below the fork. We summed the crossing counts at these forks over all depths. At depth $d$ the $2^d$ branch sizes are the floor and ceiling of $n/2^d$, allowing empty positions below singletons. Their sum $n$ fixes how often each size occurs. Each depth therefore needs only counts for smaller targets.

### Smaller hosts with larger samples

It remains to prove (4) for $t\ge32$ and $t+2\le n<2t^2$. Use strong induction on $t$: assume the conditional statement of Lemma 2 for smaller sample sizes. Put $h=\lfloor t/2\rfloor<t$. Our assumption that even hosts maximize counts through $t+1$ includes sizes through $h+1$, so we may use (4) at $h$ for every host size at least $h+2$.

First bound the fraction of copies we miss by counting only those crossing the root. For a target of size $k\ge2$ whose count is maximized by the even host at every size, this fraction in a host of size $s\ge k$ is $e(s,k)=1-C(s,k)/A(s,k)$. We have
$$
 0\le e(s,k)\le 4\,2^{-k}.
 \tag{6}
$$
To see why, let $b=\lceil s/2\rceil$. If $b<k$, neither child can hold a copy. Otherwise replace every leaf of $E_b$ with a pair of sibling leaves. Each old copy yields $2^k$ copies by choosing one sibling from each pair it uses. When $2b=s+1$, delete a leaf that preserves at least the average fraction $1-k/(2b)\ge1/2$ of these copies. For either parity of $s$, the maximum at size $s$ is thus at least $2^{k-1}A(b,k)$, even if the constructed tree is uneven. By assumption $E_s$ attains that maximum. Its two children together hold at most $2A(b,k)$ copies, giving (6).

Now compare the crossing counts for the two target sizes. For $s=n-1,n$, put $G(s)=C(s,t+1)/C(s,t)$; both counts are positive in this range. Let $X=S(\lfloor s/2\rfloor,h)$ and $Y=S(\lceil s/2\rceil,h)$ be the ratios for the two children. Dividing the crossing counts from (1) gives
$$
 G(s)=
 \begin{cases}
 X+Y,&t=2h,\\
 XY/(X+Y),&t=2h+1 .
 \end{cases}
 \tag{7}
$$
Going from $n-1$ to $n$ increases one child size from $b-1$ to $b=\lceil n/2\rceil$. The other child has one of those two sizes. Write $u=S(b-1,h)$ and $v=S(b,h)$. If $u>0$, induction gives $v/u\ge1+1/(2bh)$. The inputs in (7) change from $(u,u)$ to $(u,v)$ or from $(u,v)$ to $(v,v)$. For either formula in (7), the factor by which $G$ grows is one of
$$
 (u+v)/(2u),\qquad 2v/(u+v).
$$
The latter is smaller, giving $G(n)/G(n-1)\ge1+1/(4bh+1)$. If $u=0$, the condition $n\ge t+2$ forces $t=2h$ and $n=2h+2$. The sum in (7) then doubles, so the bound still holds.

Finally, restore the copies confined to one side of the root. The full ratio is $S(s,t)=G(s)(1-e(s,t))/(1-e(s,t+1))$. By (6), its gain from $n-1$ to $n$ is at least the gain in $G$ times $(1-4\,2^{-t})(1-4\,2^{-(t+1)})\ge1-8\,2^{-t}$. Using $4bh+1\le(n+1)t+1\le5nt/4$ gives
$$
 \frac{S(n,t)}{S(n-1,t)}
 \ \ge\ (1+4/(5nt))(1-8\,2^{-t})
 \ \ge\ 1+4/(5nt)-16\,2^{-t}
 \ \ge\ 1+1/(2nt).
$$
In the last step, $n\le2t^2$ and $2^t\ge(320/3)t^3$ for $t\ge32$, as can be checked at 32 and then by taking successive ratios. This proves (4) in the remaining range: below the quadratic threshold the missing fraction falls exponentially in $t$, and above it (5) already suffices.

## Proof that the even tree attains every maximum

For every $1\le K\le n$, we claim that $E_n$ attains the maximum number of copies of $E_K$ among rooted binary trees with $n$ leaves. Induct on $K$. Up to size three, every subset of the prescribed size gives the even shape. For $K\ge4$, we therefore assume the maximum has been proved for each smaller target at every host size. In particular this covers sizes through $\lceil K/2\rceil<K$, so Lemma 2 gives (4) for $1\le t<\lceil K/2\rceil$.

Each ratio $S(n,t)$ starts at zero for $n=t$, is positive for $n=t+1$ and increases thereafter. For $1\le i<j\le x\le z$, multiplying the ratios for $t=i,\ldots,j-1$ gives $A(n,j)/A(n,i)$ at $n=x$ and at $n=z$. In the range of columns just proved, each factor is at least as large at $z$, so $D(x,z;i,j)\ge0$. If $x<j$, the term subtracted in (2) is zero. If $i=0$, (2) is nonnegative because the count never decreases with host size. This provides every comparison required for the exchange in (3). Lemma 1 now gives the maximum for $K$, completing the induction. Formula (1) thus computes the exact maximum for every finite size by counting in the even tree alone.

## Checks against individual tree shapes

We generated every unordered binary tree shape through 21 leaves by joining every unordered pair of smaller shapes with the required total size. At each host size (676,157 shapes at size 21), the largest count from the join rule matched $A(n,k)$ for every $k$.

We also checked the join rule's counting model directly using the 399 binary tree shapes through eleven leaves in the [tree-shape appendix of Brosch and Puges](https://arxiv.org/src/2404.12838v3). For each of their 555,263 nonempty leaf subsets we pruned the unselected leaves, contracted vertices with just one child and compared the resulting unordered shape with the even tree of the same size. The even host attained every maximum in this census.

The theorem identifies a tree that attains the maximum. It leaves open the general question of which other trees tie it, and the conjecture for trees with more than two children per fork.

## References

É. Czabarka, L. A. Székely and S. Wagner. [Inducibility in binary trees and crossings in random tanglegrams](https://arxiv.org/abs/1601.07149). Theorem 5 and Conjecture 1.

A. A. V. Dossou-Olory and S. Wagner. [Further results on the inducibility of $d$-ary trees](https://ajc.maths.uq.edu.au/pdf/81/ajc_v81_p001.pdf). Australasian Journal of Combinatorics 81 (2021), 1–24. Conjecture 1.1.

T. M. Coronado, A. Mir, F. Rosselló and G. Valiente. [A balance index for phylogenetic trees based on rooted quartets](https://arxiv.org/abs/1803.01651). Theorem 17.

D. Brosch and D. Puges. [Getting to the root of the problem: sums of squares for limits of trees](https://doi.org/10.1007/s10107-025-02305-1). Finite extremal question and tree-shape appendix.
