  Among all trees on $n$ vertices with a given degree sequence, how do we
maximise or minimise the sum over all adjacent pairs of vertices $x$ and $y$ of
$f(\mathrm{deg} x, \mathrm{deg} y)$? Here $f$ is a fixed symmetric function
satisfying a 'monotonicity' condition that \[
  f(x, a) + f(y, b) > f(y, a) + f(x, b) \quad \mbox{for any $x > y$ and $a >
b$} . \] These functions arise naturally in several areas of graph theory,
particularly chemical graph theory.
  Wang showed that the so-called 'greedy' tree maximises this quantity, while
an 'alternating greedy' tree minimises it. Our aim in this paper is to solve
the inverse problem: we characterise precisely which trees are extremal for
these two problems.
