12. Trees 2

12. Trees 2 - Maggie Johnson Handout#12 CS103B Structural...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Maggie Johnson Handout #12 CS103B Key Topics * Structural Induction * Other Methods of Proof for Trees * Node Induction _____________________________________________________________________ In 103A, we saw a number of inductive proofs concerning integers and sequences. We would assume some statement for n, or for all integers less than or equal to n (strong induction), and use this "inductive hypothesis" to prove the same statement for n+1. A similar form of proof is useful for concluding facts about trees. Suppose we want to prove that a statement S(T) is true for all trees. For a basis, we show that S(T) is true whenever T consists of one node. For the induction, we suppose that T is a tree with root r and children c1, c2, . .., ck. Let T1, T2, . .., Tk be the subtrees of T rooted at c1, c2, . .., ck respectively as shown below: The inductive step is to assume S(T1), S(T2), . .., S(Tk) are all true, and prove S(T). If we can do this, we have proven S(T). Why does structural induction work? Example 1: S(T) denotes that there are at most m h leaves in an m-ary tree of height h. (Note: the root is at level 1 with a height of 0) basis: Consider an m-ary tree of height 1. These trees consist of a root with no more than m children, each of which is a leaf. Therefore, there are no more than m 1 = m leaves in an m- ary tree of height 1. inductive hypothesis : We assume the above statement is true for all m-ary trees of height less than h, and show it is true for all m-ary trees of height h. PROOF: Let T be an m-ary tree of height h. The leaves of T are the leaves of the subtrees of T obtained by deleting the edges from the root to each of the vertices connected to it, as shown below:
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Each of these subtrees has height less than or equal to h-1. So, by the inductive hypothesis, these trees have at most m (h-1) leaves. Since there are at most m such subtrees, each with a minimum of m (h-1) leaves, there are at most m * m (h-1) = m h leaves in the rooted tree. Thus, by the principle of mathematical induction applied to the structure of trees, S(T) is true for all m-ary trees. Example 2: S(T) denotes a strictly binary tree with n leaves has 2n-2 edges. (Note: strictly binary means every node has either 0 or 2 children.) basis: A strictly binary tree with two leaves consists of the root connected to its only two children: 2 * 2 - 2 = 2. inductive hypothesis : We assume S(T) is true for all strictly binary trees with i leaves where i >= 2 and i < n leaves; Show that S(T) is true for a tree with n leaves. PROOF: Consider a tree T with n leaves where n > 1. By the definition of a binary tree, T must consist of two subtrees T L and T R (since n > 1). If T L has n L leaves and T R has n R leaves, then n L + n R = n. By the inductive hypothesis, T L has 2n L - 2 edges and T R has 2n R - 2 edges. Since T has two additional edges that are not part of T L or T R , the number of edges in T is (2n L - 2) + (2n R - 2) + 2 = 2(n L + n R ) - 2 = 2n - 2. Thus, by the principle of mathematical induction applied to the structure of trees, S(T) is true
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 8

12. Trees 2 - Maggie Johnson Handout#12 CS103B Structural...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online