Let $\left(d_{1}, d_{2}, \ldots, d_{n}\right)$ be a sequence of integers.
(a) Prove that there is a tree of order $n$ with this degree sequence if and only if $d_{1}, d_{2}, \ldots, d_{n}$ are positive integers with sum $d_{1}+d_{2}+\cdots+d_{n}=2(n-1)$.
(b) Write an algorithm that, starting with a sequence $\left(d_{1}, d_{2}, \ldots, d_{n}\right)$ of positive integers, either constructs a tree with this degree sequence or concludes that none is possible.