1
votes

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:

  1. 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.

  2. 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

1
Added a proof that Property 1 => Property 2.Daniel Fischer

1 Answers

7
votes

No, the two are not equivalent.

    3
   / \
  2   7
 /   / \
1   5   8
   / \   \
  4   6   9

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 n inner nodes, all leaves are at a depth of

  • k if n = 2^k - 1
  • k or k+1 if 2^k <= n < 2^(k+1)-1, and there are leaves at depth k+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 >= 2 and consider a binary tree that is balanced according to property 1 with n+1 inner nodes.

If n is even, n = 2*m, both subtrees must have m inner nodes, and the depth property holds by the induction hypothesis.

If n = 2*m+1 is odd, one subtree has m inner nodes, the other m+1.

  1. If 2^k <= m < 2^(k+1)-1, the subtree with m inner nodes has leaves at depth k+1, and possibly leaves at depth k by the induction hypothesis. The tree with m+1 inner nodes also has leaves at depth k+1 and possibly (if m+1 < 2^(k+1)-1) at depth k.

  2. If m = 2^k - 1, the subtree with m inner nodes has leaves only at depth k, and the subtree with m+1 inner nodes has leaves at depth k+1 and possibly at depth k.