Vahid Kharazi
Vahid Kharazi

Reputation: 6033

Number of trees with N nodes and depth M

How many trees do exist with N nodes and depth M? I would like to know the number of any kind of trees (simple, binary, etc.) that can be made with N nodes and depth M.

I've been trying to find a formula for it, but I had not succeeded so far. Any suggestions? Thanks in advance.

Upvotes: 2

Views: 2070

Answers (1)

Rubens
Rubens

Reputation: 14778

Varying the number of nodes from the root to the depth "m", considering only one path, you can have "m" nodes, and thus "m" different trees -- if you exclude any i-th node from the root level to the level "m". you'll be excluding the entire path from i to m.

Now, considering you can have "n" nodes inserted in breadth-first fashion, you would have the combination of the "n" nodes, since each node may differ from one another. This gives you all the combinations, of "n" nodes, "k" by "k", for every possible "k", whick is the same of 2^n.

Mixing the combinations with the different number of levels, you would have various combinations for each level, since each tree structure may represent a different tree. All the combinations would involve the number of combinations of "n" nodes for each of the "m" levels.

I really don't know how to reach the final formula from this, but I would say the value you want is something close to (2^n . m!), considering that, for each possible combination of "n" nodes in a given level, there are also a set of combinations of these nodes in the m different levels.

Just to state clear, I'm not sure of how to calculate this pricisely, this is the farthest I can reach intuitively.

Reference to affirm k-combinations summed for all k's.

Upvotes: 1

Related Questions