i am trying to understand the binary tree properties. But i am not sure about one thing:
The def. of a Binary trees states that:
-
A binary tree is balanced if for each node it holds that the number of inner nodes in the left subtree and the number of inner nodes in the right subtree differ by at most 1.
-
A binary tree is balanced if for any two leaves the diff. of the depth is ast most 1.
I am asking me if this two def. are equivalent, i mean does Def. 1 statisfy Def. 2 and viceversa? … it seems for me yes…but who can explain me exactly with examples the (non) equivalence of this properties?
Thanks,
Patric
No, the two are not equivalent.
is a tree satisfying property 2, but not property 1.
Property 1 implies property 2, however.
Proposition: In a binary tree that is balanced according to property 1 with
ninner nodes, all leaves are at a depth ofkifn = 2^k - 1kork+1if2^k <= n < 2^(k+1)-1, and there are leaves at depthk+1.Proof: (By induction on the number of inner nodes)
For
n = 1 = 2^1-1, there are one or two leaves at depth 1 (root is at depth 0).For
n = 2, one subtree has one inner node, all leaves in that subtree are at depth 2, the other subtree is empty or a leaf at depth 1.Let
n >= 2and consider a binary tree that is balanced according to property 1 withn+1inner nodes.If
nis even,n = 2*m, both subtrees must haveminner nodes, and the depth property holds by the induction hypothesis.If
n = 2*m+1is odd, one subtree hasminner nodes, the otherm+1.If
2^k <= m < 2^(k+1)-1, the subtree withminner nodes has leaves at depthk+1, and possibly leaves at depthkby the induction hypothesis. The tree withm+1inner nodes also has leaves at depthk+1and possibly (ifm+1 < 2^(k+1)-1) at depthk.If
m = 2^k - 1, the subtree withminner nodes has leaves only at depthk, and the subtree withm+1inner nodes has leaves at depthk+1and possibly at depthk.