Expand the relationship between the inner path length I, the outer path length E and the number of inner nodes n of the binary tree

Definition of some concepts

  1. Expanding a binary tree: Add a binary tree formed by empty leaves where empty subtrees appear in the binary tree
  2. External node: empty leaf node
  3. Internal node: non-empty node
  4. External path length: expand the sum of the path lengths from all external nodes to the root node in the binary tree
  5. Internal path length: expand the sum of the path lengths from all internal nodes to the root node in the binary tree

Important conclusion

Length of outer path E Length of
inner path I Number of
inner nodes n
E = I + 2n

Prove by mathematical induction E = I + 2n

  1. When n is 1, I = 0; E = 2; satisfies E = I + 2n
  2. Suppose the formula holds when there are n internal nodes, then when there are n + 1 internal nodes (compared with n internal nodes, an external point is added), the height of the binary tree after adding an internal node is h (not including outer nodes), inner path length I(n+1) = I(n) + h, outer path length E(n+1) = E(n)-h + 2(h+1), Then there is E(n) = I(n) + 2n, and we can get E(n+1)-h-2 = I(n+1)-h + 2n, that is, E(n+1) = I(n+ 1) + 2(n+1)
    certificate completion

Guess you like

Origin blog.csdn.net/baidu_41628379/article/details/109387516