MATH 302 Lecture 14

From Notes
Jump to navigation Jump to search

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


Recursively Defined Sets

Basis step. 3S

Inductive step. if x,yS, then x+yS.


Example property: S=3+

Proof by structural induction.

  1. S3+
  2. 3+S

(1) Basis step. 3=313Z+

Inductive step. Assume x,y3+ for x,yS. 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 S3+ followl by structural principle of mathematical induction.

(2) Basis step. 31=3S by definition of S

Inductive step. Assume 3kS for k1, then 3(k+1)=3k+3S 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 k0 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 n1 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)+1n(T)2h(T)+11, 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. 111 true.

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

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

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

Adding the two formulae together gives

2h(T1)+2h(T2)+2+1n(T1)+n(T2)+12h(T1)+11+2h(T2)+11+12(max(h(T1), h(T2))+1)n(T1T2)22max(h(T1), h(T2))+112h(T1T2)+1n(T1T2)2h(T1T2)+11

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(n1)! 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.