Given an $n$ level tree with $b$ branches at each node, how many unique paths are there from the root to the leaves?

296 Views Asked by At

I have a tree where, at each node, it splits into $b$ branches for a total number of $n$ levels.

I enumerate the paths from the root to the leaf nodes. For example, if $n = b = 2$ then I have the following paths from the root node to the leaf nodes:

{1,1}, {1,2}, {2,1}, {2,2}. (there are $n^b$ leaf nodes)

However, I'm only interested in paths that have unique sets, regardless of order. In the example I gave above, {1,2} and {2,1} are equivalent. I'm only interested in the elements.

For $n = 2, b = 3$, I have:

{1,1,1}, {1,1,2}, {1,2,1}, {1,2,2}, {2,1,1}, {2,1,2}, {2,2,1}, {2,2,2}

Where the bold sets represent the unique results.

Unless I've made a mistake in my enumeration, I've worked out the the first few examples by hand to try and get some insight into the problem:

$n$, $b$, unique results:
1, $k$, 1 (for arbitrary $k$)
2, 1, 2
2, 2, 3
2, 3, 4
3, 1, 3
3, 2, 6
3, 3, 10

How do I work out what the closed form is for the result I'm looking for given arbitrary $n$ and $b$?

1

There are 1 best solutions below

1
On BEST ANSWER

You’re looking for the number of distinct multisets of cardinality $n$ whose elements all come from a set of cardinality $k$. This is sometimes written $\left(\!\!\left(k\atop n\right)\!\!\right)$ and is given by the formula

$$\left(\!\!\left(k\atop n\right)\!\!\right)=\binom{k+n-1}n=\binom{k+n-1}{k-1}\;.$$

The linked article has a reasonably clear derivation of the formula.