stars and bars - represent the r identical object as r stars ******
you can divide them into boxes by placing bars in between stars so **|*|***
represents six objects split into three boxes with 2 in the first box, 1 in the second, and three in the third.
in general there will be $r$ stars , leaving $(r-1)$ positions to place the $(n-1)$ bars.
The total number of ways to position the bars is given by $\binom{r-1}{n-1}$
The technique you used is for placing identical objects into distinct boxes.
What matters here is which objects are in the same box. We consider cases.
Case 1: All five objects are placed in the same box.
Since the boxes are indistinguishable, this can be done in
$$\binom{5}{5} = 1$$
way.
Case 2: Four objects are placed in one box and the other object is placed in another box.
There are
$$\binom{5}{4} = 5$$
ways to choose which four objects are placed in the same box and one way to place the other object in another box.
Case 3: Three objects are placed in one box and the other two objects are placed in another box.
There are
$$\binom{5}{3} = 10$$
ways to choose which three objects are placed in the same box and one way to place the remaining two objects in another box.
Case 4: Three objects are placed in one box and one object each is placed in the other boxes.
There are
$$\binom{5}{3} = 10$$
ways to choose which three objects are placed in the same box. That leaves two objects which must be placed in the two empty boxes. Since those boxes are indistinguishable, there is only one way to place them in separate boxes.
Case 5: Two objects are placed in one box, two other objects are placed in another box, and the remaining box receives one object.
There are five ways to choose which object is placed by itself in a box. Place one of the remaining four objects in an empty box. There are three ways to choose which of the other objects will be placed in the box with it. The remaining two objects must be placed in the remaining box. Thus, there are
$$\binom{5}{1}\binom{3}{1} = 15$$
ways to distribute five distinct objects to three indistinguishable boxes in this case.
Total: The number of ways five distinct objects can be distributed to three indistinguishable boxes if boxes may be left empty is
$$\binom{5}{5} + \binom{5}{4} + \binom{5}{3} + \binom{5}{3} + \binom{5}{1}\binom{3}{1} = 1 + 5 + 10 + 10 + 15 = 41$$
so the answer stated in your book is wrong.
To compare my result with that of @sc_, case 1 is $S(5, 1)$, cases 2 and 3 total to $S(5, 2)$, and cases 4 and 5 total to $S(5, 3)$. If you check the table of values on the linked Stirling numbers of the second kind page, you will see that $S(5, 1) + S(5, 2) + S(5, 3) = 1 + 15 + 25 = 41$.
Best Answer
On a diagram like that you would use $n_1=n, n_2=n, \ldots, n_k=n, \ldots, n_r= n$
There would be $r$ distinct steps each with $n$ possible ways. That corresponds to selecting one of $n$ boxes to put a ball into, for $r$ balls.
The diagram would consist of $r$ lines, the starting point branching to $n$ points on the first line, each one with $n$ branches to the the next line, and each of those $n^2$ points starting $n$ branches to the third line, and each of those $n^3$ points branching $n$ times ... until each of the $n^{r-1}$ points on the penultimate line start $n$ branches to the last line, for a total of $n^r$ points on line $r$.
$$\underbrace{n_1\times n_2 \times \cdots \times n_r}_{\text{a term for each of $r$ balls}} = \underbrace{\quad n\times n\times \cdots \times n\quad}_{\text{each term is the count of boxes, $n$}} = n^r$$