N-ary Tree
An n-ary tree is a rooted tree in which each node can have at most n children. This generalizes the binary tree concept to any number of children.
- If
n = 2, it’s a binary tree. - If
n = 3, each node can have 0, 1, 2, or 3 children.
Structure of an N-ary Tree (n = 3 Example)
Types of N-ary Trees
- Full N-ary Tree – Every internal node has exactly
nchildren. - Complete N-ary Tree – All levels except possibly the last are full; last level filled left to right.
- Perfect N-ary Tree – All internal nodes have exactly
nchildren, and all leaves are at the same depth.
Number of Possible N-ary Trees – Catalan Generalization
For full n-ary trees (every internal node has exactly n children), the generalized Catalan number gives the number of structurally distinct trees with m internal nodes:
Where:
- = number of internal nodes
- Total nodes =
Example: For a full ternary tree () with internal nodes:
Number of Labelled Full N-ary Trees
If nodes are labelled (distinct), the number is:
Where:
- = generalized Catalan number
- = total nodes
Max and Min Number of Nodes Given Height
Let = height (number of edges from root to deepest leaf).
- Max Nodes (Perfect N-ary Tree):
- Min Nodes (Full N-ary Tree):
If not strict:
Example: For and : Max:
Min (full):
Min (non-full):
Max and Min Height Given Number of Nodes
Let = total nodes.
- Min Height (Perfect N-ary Tree):
- Max Height: If full: If not full:
Internal and External Nodes (Full N-ary Tree)
For a full n-ary tree:
Where:
- = external nodes (leaves)
- = internal nodes
Also:
Example: For , internal nodes:
Total nodes:
Summary Table for N-ary Tree
| Concept | Formula |
|---|---|
| Generalized Catalan Number (full) | |
| Labelled full n-ary trees | |
| Max nodes for height | |
| Min nodes for height (full) | |
| Min nodes for height (non-full) | |
| Min height for nodes | |
| Max height for nodes (full) | |
| Max height for nodes (non-full) | |
| Full n-ary tree relation |