Expanding binomials

A binomial is a polynomial with two terms. These terms may be univariate (just a single variable; e.g., $x + 3$ or $2x - 5$ or even $x^2 + 1$) or multivariate; e.g., $2x + 3y$, $x - y$, $xy - yz$, or $x^2 - y^3$.

Raising a binomial to a non-negative integer power can always be expanded so that the result is an equivalent polynomial that is a linear combination of terms:

$(x + 1)^2 = x^2 + 2x + 1$
$(x + 3y)^3 = x^3 + 9x^2y + 27xy^2 + 27y^3$
$(2x - yz)^4 = 16x^4 - 32x^3yz + 24x^2y^2z^2 - 8xy^3z^3 + y^4z^4$

Algorithm X.1: Expanding a simple binomial raised to a non-negative integer power

Input: a simple binormal (a polynomial with two terms, one of which is a number, and the other is a variable), and a non-negative integer $n$.
Output: an expanded polynomial.

Describe an algorithm for expanding a binomial raised to a non-negative integer.

Algorithm X.2: Expanding a binomial raised to a non-negative integer power

Input: a binormal (a polynomial with two terms, each of the terms is either a number, a variable, or a number multiplied by a variable), and a non-negative integer $n$.
Output: an expanded polynomial.