Binary search tree, number of nodes formula

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 2K views
ducmod
Messages
86
Reaction score
0

Homework Statement


Hello!
Typical binary search tree has a number of nodes equal to 2^(n+1) - 1.
I don't understand why we add 1 to the n?
For example: a tree has a height 4.
#
# #
# # # #
# # # # # # # #
each level has 2^i nodes; i = 0, 2^0 = 1 for the first row, etc.
If the height is 4 then total amount of nodes is 15, which is 2^4 - 1,
and not 2^(4+1) - 1.

I would be grateful for your help!
 
Physics news on Phys.org
ducmod said:

Homework Statement


Hello!
Typical binary search tree has a number of nodes equal to 2^(n+1) - 1.
I don't understand why we add 1 to the n?
For example: a tree has a height 4.
#
# #
# # # #
# # # # # # # #
each level has 2^i nodes; i = 0, 2^0 = 1 for the first row, etc.
If the height is 4 then total amount of nodes is 15, which is 2^4 - 1,
and not 2^(4+1) - 1.

I would be grateful for your help!

The formula works perfectly well if you regard the depth as n=3, rather than n=4. Four is the number of nodes in a path from root to tip, but three is the number of "steps". It is the same as saying that your first year of life has two endpoints, t = 0 and t = 1, but it is still just one year.
 
Ray Vickson said:
The formula works perfectly well if you regard the depth as n=3, rather than n=4. Four is the number of nodes in a path from root to tip, but three is the number of "steps". It is the same as saying that your first year of life has two endpoints, t = 0 and t = 1, but it is still just one year.
I see now. Thank you!