Tree Height And Nodes Calculator
Work out tree height and nodes instantly with clear inputs, formula shown and shareable results.
About Tree Height And Nodes Calculator
A perfect b-ary tree of height h has bᵏ nodes at level k, so the total is the geometric sum (b^(h+1) − 1)/(b − 1). The deepest level alone holds bʰ leaves.
Formulas
Total nodes
N = (b^(h+1) − 1) / (b − 1)
Leaves
L = bʰ
Worked example
With the default values below, Tree Height And Nodes Calculator returns Total nodes of 121. Change any input above and every figure here is recalculated in your browser.
Inputs used
- Branching factor (children per node)accepts 1–50
- 3
- Height (root is level 0)accepts 0–40
- 4
Results
- Total nodes
- 121
- Leaf nodes
- 81
- Internal nodes
- 40
- Nodes at the deepest level
- 81
Step by step
- 1Values used
- 2Total nodes
- 3Leaves
- 4Total nodes= 121
- 5Leaf nodes= 81
- 6Internal nodes= 40
- 7Nodes at the deepest level= 81
Assumptions and limits
- The result is derived only from the 2 inputs listed above. Anything not among them is not part of the calculation.
- In particular, this calculator does not take inflation, tax, fees or charges or compounding frequency into account.
- Figures are rounded for display to whole numbers, so totals built from several rounded parts can differ slightly from the unrounded arithmetic.
How these calculators are built and tested is described on the Methodology page. If a figure looks wrong, please report it.
Frequently Asked Questions
A ternary tree of height 4?
(3⁵ − 1)/2 = 121 nodes, of which 81 are leaves.
Why does search take O(log n)?
Because n grows exponentially with height, so the height — and hence the search depth — grows only logarithmically with n.
Related Calculators
You might also need
- Binary Tree Nodes CalculatorAlso in Discrete Math, Logic & Number Theory
- Bitwise AND OR XOR CalculatorAlso in Discrete Math, Logic & Number Theory
- Minimum Spanning Tree CalculatorAlso in Discrete Math, Logic & Number Theory
- Discrete Logarithm CalculatorAlso in Discrete Math, Logic & Number Theory
- Set Union And Intersection CalculatorAlso in Discrete Math, Logic & Number Theory
- Adjacency Matrix CalculatorAlso in Discrete Math, Logic & Number Theory
