Data Str &amp; Algorithm HW Solutions 32

# Data Str &amp; Algorithm HW Solutions 32 - T By the...

This preview shows page 1. Sign up to view the full content.

5 Binary Trees 5.1 Consider a non-full binary tree. By de f nition, this tree must have some inter- nal node X with only one non-empty child. If we modify the tree to remove X , replacing it with its child, the modi f ed tree will have a higher fraction of non-empty nodes since one non-empty node and one empty node have been removed. 5.2 Use as the base case the tree of one leaf node. The number of degree-2 nodes is 0, and the number of leaves is 1. Thus, the theorem holds. For the induction hypothesis, assume the theorem is true for any tree with n 1 nodes. For the induction step, consider a tree T with n nodes. Remove from the tree any leaf node, and call the resulting tree
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: T . By the induction hypothesis, T has one more leaf node than it has nodes of degree 2. Now, restore the leaf node that was removed to form T . There are two possible cases. (1) If this leaf node is the only child of its parent in T , then the number of nodes of degree 2 has not changed, nor has the number of leaf nodes. Thus, the theorem holds. (2) If this leaf node is the child of a node in T with degree 2, then that node has degree 1 in T . Thus, by restoring the leaf node we are adding one new leaf node and one new node of degree 2. Thus, the theorem holds. By mathematical induction, the theorem is correct. 32...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online