Why is the number of terms in in the expansion of $(x_1+x_2+....+x_r)^n$ equal to $\binom{n+r-1}{r-1}$? I am self-studying combinatorics and came across this theorem. Can anyone show me how to prove the theorem? I would like to understand why it is that way.

The number of terms in the expansion of $(x_1+x_2+....+x_r)^n$, after the like terms combined, is $$\binom{n+r-1}{r-1}$$ or $$\binom{n+r-1}{n}$$

 A: The terms in the expansion are precisely the monomials of the form $$x_1^{e_1} \cdots x_r^{e_r}$$ such that $\sum_{k = 1}^r e_k = n$.  The number of such monomials is equal to the number of $r$-tuples $$(e_1, \ldots, e_r)$$ such that $\sum_{k = 1}^r e_k = n$ where each $e_i \geq 0$ and $e_i \in \mathbb{N}$.  Thus, showing that the number of terms is $\binom{n+r-1}{r-1}$ is equivalent to proving that the number of these tuples is $\binom{n+r-1}{r-1}$.
This can be proved using the "stars and bars" method.  Let us determine the number of $r$-tuples whose entries sum to $n$.  The idea is to break a sequence of $n$ stars into bins separated by $r - 1$ bars.  The bars and stars can appear in any order.  The number of stars that appears before the first bar is the value of the first element of the tuple.  In general, for $0 < k < r$ the $k$th element of the tuple is equal to the number of stars between the $k - 1$th and $k$th bars.  For $k = r$ (the last element), the $k$th element of the tuple is the number of stars after the last bar.  For example,
$$**|***|*|$$ corresponds to the tuple $(2, 3, 1, 0)$ or the monomial $x_1^2 x_2^3 x_3$ in the case where $n = 6$ and $r = 4$.
Now we just need to figure out how many ways there are to make a sequence of $n$ stars and $r - 1$ bars.  To do this, we start with a sequence of $n$ stars and calculate the number of ways to insert $r - 1$ bars.
$$** \cdots *$$
We argue that the number of ways to insert the bars is equal to the number of ways to choose a subset of size $r - 1$ from $\{0, \ldots, n + r - 1\}$.  To show this, we define a bijection between the numbers of ways to insert the bars and the number of $r - 1$ element subsets of $\{0, \ldots, n + r - 1\}$ as follows.  Let $A$ be such a subset and remove the smallest number $i$ from $A$.  Then insert the first bar into the sequence of stars so that it is preceded by exactly $i$ stars.  Then inserting the second bar into the sequence so that there are exactly $j$ symbols (either stars or bars) before it.  Continuing in this manner until $A$ is empty, we obtain a sequence of $n$ stars and $r - 1$ bars.  Moreover, by considering the process in reverse, we see that the mapping between the set of all sequences of $n$ stars and $r - 1$ bars and $r - 1$ element subsets of $\{0, \ldots, n + r - 1\}$ is a bijection.  The number of such subsets is $\binom{n + r - 1}{r - 1}$.  This proves that the number of terms in $$(x_1+x_2+....+x_r)^n$$ is also $\binom{n + r - 1}{r - 1} = \binom{n + r -1}{n}$.
