Height and Nodes
Understanding the relationships between the number of nodes, height, and possible tree structures is fundamental in tree-based algorithms and data structures. Here are the key concepts, formulas, and visual examples for general trees:
Number of Trees (Catalan Formula)
The number of distinct rooted ordered trees (general trees) that can be formed with n
nodes is given by the Catalan number:
For example:
- For n = 3:
- For n = 4:
All possible rooted ordered trees with 3 nodes (A, B, C)
Number of Trees with Labelled Nodes
If all nodes are labelled (distinct), the number of possible trees is:
Maximum and Minimum Height of a Tree
- Maximum height of a tree with
n
nodes isn-1
(a path/tree where each node has only one child). - Minimum height (for a perfectly balanced tree) is where $k` is the maximum degree (children per node).
Perfectly balanced k-ary tree (height = ⌈log_k n⌉)
Relationship Between Height and Nodes
If Height is Given
- Minimum nodes for height
h
: (path/tree) - Maximum nodes for height
h
in a k-ary tree:
If Number of Nodes is Given
- Minimum height for
n
nodes in a k-ary tree: - Maximum height for
n
nodes:
Summary Table
Property | Formula |
---|---|
Number of trees (unlabelled) | |
Number of trees (labelled) | |
Max height (n nodes) | |
Min height (n nodes, k-ary) | |
Min nodes (height h) | |
Max nodes (height h, k-ary) | |
Min height (n nodes, k-ary) | |
Max height (n nodes) |
Key Points
- The Catalan number counts the number of possible rooted ordered tree structures (unlabelled).
- For labelled nodes, multiply by for all possible arrangements.
- Height and node relationships are useful for analyzing tree balance and efficiency.
- For k-ary trees, adjust formulas using (max children per node).