  Let $\lambda_1,\dots,\lambda_n$ be the eigenvalues of a graph $G$. For any
$k\geq 0$, the $k$-th spectral moment of $G$ is defined by
$\M_k(G)=\lambda_1^k+\dots+\lambda_n^k$. We use the fact that $\M_k(G)$ is also
the number of closed walks of length $k$ in $G$ to show that among trees $T$
whose degree sequence is $D$ or majorized by $D$, $\M_k(T)$ is maximized by the
greedy tree with degree sequence $D$ (constructed by assigning the highest
degree in $D$ to the root, the second-, third-, \dots highest degrees to the
neighbors of the root, and so on) for any $k\geq 0$. Several corollaries
follow, in particular a conjecture of Ili\'c and Stevanovi\'c on trees with
given maximum degree, which in turn implies a conjecture of Gutman, Furtula,
Markovi\'c and Gli\v{s}i\'c on the Estrada index of such trees, which is
defined as $\EE(G)=e^{\lambda_1}+\dots+e^{\lambda_n}$.
