MATH 302 Lecture 14

From Notes
Jump to navigation Jump to search

« previous | Monday, October 17, 2011 | next »


Recursively Defined Sets

Basis step. 3∈S

Inductive step. if x,y∈S, then x+y∈S.


Example property: S=3ℤ+

Proof by structural induction.

  1. S⊆3ℤ+
  2. 3ℤ+⊆S

(1) Basis step. 3=3⋅1∈3Z+

Inductive step. Assume x,y∈3ℤ+ for x,y∈S. Then x=3k and y=3l for some k,l∈ℤ+.

Hence x+y=3k+3l=3(k+l)∈3ℤ+. THis proves the inductive step, and S⊆3ℤ+ followl by structural principle of mathematical induction.

(2) Basis step. 3⋅1=3∈S by definition of S

Inductive step. Assume 3k∈S for k≥1, then 3(k+1)=3k+3∈S by recursive step definition of S. This proves the inductive step and thus the general result 3ℤ+⊆S follows by the principle of mathematical induction.

Properties of S

Basis step. 3 has a property P

Recursive step. If x,y have the property P, then x+y has the property P

This is an example of structural induction.

Strong Properties of S

Basis Step. Something has a certain property P

Inductive Step. Any element which can be obtained either by the basis step or up to kiterations for some k≥0 of recursive step has property P. Show any such element that can be obtained by k+1 iterations of recursive steps has property P.


Trees

Basis step. A root r is a tree

Inductive step. Let T1,…,Tn be n disjoint rooted trees such that n≥1 with corresponding roots r1,…,rn. Draw edges connecting another distinct root r with each of the roots r1,…,rn. T, the resulting graph, is a rooted tree.

Example Structural Proof

This proof is for full binary trees in which each node is a leaf or has exactly two children.

Theorem. 2h(T)+1≤n(T)≤2h(T)+1−1, where n(T) is the number of vertices and h(T) is the height.

Proof by Structural Induction.

Basis step. T is a root alone: h(T)=0, n(T)=1. 1≤1≤1 true.

Recursive step. Assume T1 and T2 are full binary trees satisfying the theorem

n(T1⋅T2)=n(T1)+n(T2)+1
h(T1⋅T2)=max(h(T1), h(T2))+1

Thus we have 2h(Ti)+1≤n(Ti)≤2h(Ti)+1−1 for i=1,2

Adding the two formulae together gives

2h(T1)+2h(T2)+2+1≤n(T1)+n(T2)+1≤2h(T1)+1−1+2h(T2)+1−1+12(max(h(T1), h(T2))+1)≤n(T1⋅T2)≤2⋅2max(h(T1), h(T2))+1−12h(T1⋅T2)+1≤n(T1⋅T2)≤2h(T1⋅T2)+1−1

This proves the inductive step, and the general result follows by the structural principle of mathematical induction.

Q.E.D.


And now for something completely different.

Recursive Algorithms

Solving a problem by reducing it to the same problem with a smaller input.

Simple definition for Factorial

Basis step. 0!=1

Recursive step. n!=n⋅(n−1)! for n>0

def factorial n

 raise Exception.new("must be nonnegative") if n < 0
 return 1 if n == 0
 n * factorial(n-1)

end

Greatest Common Divisor

def gcd a, b

 return b if a == 0
 gcd(b % a, a)

end

Note: if gcd(a,b)=1, then a and b are relatively prime.