recursive

# Typically though it is simply used because it is more

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

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: hod directly exploits the inductive definition of the set. The method is more powerful than strong induction in the sense that one can prove statements that are difficult (or impossible) to prove with strong induction. Typically, though, it is simply used because it is more convenient than (strong) induction. 22 Structural Induction In structural induction, the proof of the assertion that every element of an inductively defined set S has a certain property P proceeds by showing that Basis: Every element in the basis of the definition of S satisfies the property P. Induction: Assuming that every argument of a constructor has property P, show that the constructed element has the property P. 23 Example 1: Binary Trees Recall that the set B of binary trees over an alphabet A is defined as follows: Basis: ⟨⟩∈B. Induction: If L, R∈B and x∈A, then ⟨L,x,R⟩∈B. We can now prove that every binary tree has a property P by arguing that Basis: P(⟨⟩) is true. Induction: For all binary trees L and R and x in A, if P(L) and P(R), then P(⟨L,x,R⟩). 24 Binary Trees (Cont.) Let f: B -> N be the function defined by f (￿￿) f (￿L, x, R￿) = = 0 ￿ 1 f ( L) + f ( R ) if L = R = ￿￿ otherwise Theorem: Let T in B be a binary tree. Then f(T) yields the number of leaves of T. 25 Binary Trees (Cont.) Theorem: Let T in B be a binary tree. Then f(T) yields the number of leaves of T. Proof: By structural induction on T. Basis: The empty tree has no leaves, so f(⟨⟩) = 0 is correct. Induction: Let L,R be trees in B, x in A. Suppose that f(L) and f(R) denotes the number of leaves of L and R, respectively. If L=R=⟨⟩, then ⟨L,x,R⟩ = ⟨⟨⟩,x,⟨⟩⟩ has one leaf, namely x, so f (⟨⟨⟩,x,⟨⟩⟩)=1 is correct. 26 Binary Trees (Cont.) If L and R are not both empty, then the number of leaves of the tree ⟨L,x,R⟩ is equal to the number of leaves of L plus the number of leaves of R. Hence, by induction hypothesis, we get f(⟨L,x,R⟩) = f(L)+f(R) as claimed. This completes the proo...
View Full Document

## This note was uploaded on 03/24/2014 for the course CSCE 222 taught by Professor Math during the Fall '11 term at Texas A&M.

Ask a homework question - tutors are online