Title: Discrete Mathematics CS 2610
1Discrete Mathematics CS 2610
March 26, 2009
Skip structural induction generalized
induction Skip section 4.5
2Well-Ordering Property
- Every non-empty set of non-negative integers has
a minimum (smallest) element - The well-ordering property is the foundation of
Mathematical induction
3Recursion
- Recursion means defining an object in terms of
- itself
- part of itself
- versions of itself
- An object can be
- Sequence
- Function
- Set
- Algorithm
4In Nature
- Fractals are self-similar structures, most of
them defined recursively
A fractal coastline in northern Portugal
Romanesque Broccoli
5Recursively Defined Sequence
- Def. A sequence is defined recursively whenever
some initial terms are specified and later terms
are defined in terms of earlier terms. - Arithmetic Series
- a01, r3
- anan-1r, ngt0 yields 1, 4, 7, 10, 13,
- Geometric Series
- a03, r2
- anan-1r, ngt0 yields 3, 6, 12, 24, 48,
- an 2n yields 1, 2, 4, 8, 16, 32,
- or an1 2an where n gt 0 and a0 1
6Recursively Defined Sequence
- In a recursively defined sequence
- Base or Initial Conditions
- The first term(s) of the sequence are defined
- Recursion or Recursive Step
- The nth term is defined in terms of previous
terms - The formula to express the nth term is called a
recurrence formula - Arithmetic Series
- Base a01, r3
- Recursion anan-1r, n gt 0
- Geometric Series
- Base a03, r2
- Recursion anan-1r, n gt 0
7Recursively Defined Sequence
- Be sure that the recursive definition of the
sequence produces a well-defined sequence in
which all the terms 0,1,2 are covered by the
definition - Example
- Base a0 1
- Recursion an 3an-2 - an-1
- What is a1? Cant tell so this is no good.
8Fibonacci Sequence
- Fibonnaci Sequence
- Non-recursive (closed form) Definition
- Recursive Definition
- Base Cases f00, f11
- Recurrence fn fn-1 fn-2 for n gt 1
9Fibonacci Sequence
- Theorem fn lt 2n.
- Proof (By strong induction.)
- Base cases
- f0 0 lt 20 1f1 1 lt 21 2
- Inductive step
- Inductive Hypothesis Assume ?j, 1 lt j ? k, fj
lt 2j. - i.e., f2 lt 22, f3 lt 23, , fk lt 2k
- show that fk1 lt 2k1
- fk fk-1 lt 22k 2k 2k
- fk lt 2k from ind hyp and fk-1 fk lt 2k
so - fk1 lt 2k1
10Fibonacci Sequence
- Theorem. ? n 3, fn gt an-2, where a (1?5)/2.
- Proof.
- First note that
- a2 a - 1 (1 2?5 5)/4 - (1?5)/2 1
- 6/4 2?5/4 1/2 - ?5/2 1
- ?5/2 - ?5/2 3/2 1/2 1
- 0 (recall quadratic formula)
- Therefore, a2 a 1
- Take it away!
11Recursively Defined Function
- A function f(n) with domain N or a subset of N is
defined recursively, when f(n) is defined in
terms of the previous functions of m lt n - Basis f(0) 1
- Recursion
- Define f(n) from f defined on smaller terms
- Example
- Let f N -gt N defined recursively as
- Basis f(0) 1
- Recursion f(n 1) (n 1) f(n).
- What are the values of the following?
- f(1) 1 f(2) 2 f(3) 6 f(4) 24
- What does this function compute?
n!
12Recursively Defined Function
- Be sure that the recursive definition produces a
well-defined function, i.e., every element in the
domain has an image under f - Example
- Base f(1) 1
- Recursion f(n) 1 f(?n/2? ), n 1
- Is this function correctly defined ?
Ill-defined f(1) is 1 but is not well-defined
according to the recursion and f(0) is not
defined.
f(0) ? f(6) ?
13Recursively Defined Set
- An infinite set S may be defined recursively, by
giving - Basis Step A finite set of base elements
- Recursive Step a rule for forming new elements
in the set from those already in the set - Exclusion Rule specifies that the set only
contains those elements specified in the basis
step or those generated by the recursive step - Example
- Let S be defined as follows
- Basis Step 1 ? S
- Recursive Step if n ? S then 2n ? S
S 2k k ? N
14Recursively Defined Set
- Example
- Basis Step 0 ?? S
- Recursive Step if m ? S then m 1 ? S
- Exclusion Rule No other numbers are in S.
- What is S?
Example Basis Step 1 ?? S Recursive Step if
m ? S then -1m ? S Exclusion Rule No other
numbers are in S What is S?
15Set of Strings
- Def.An alphabet ? is a finite non-empty set of
symbols (e.g., ? 0, 1 ) - Def.A String over an alphabet ? is a finite
sequence of symbols from ? (e.g., 11010 ) - The set ? of strings over ? can be defined as
- Basis Step ? ? S where ? is the empty string
containing no symbols - Recursive Step if w ? S and x ? S then wx ? S
Is ? countable or uncountable ?
16Recursive Definition on Strings
- Concatenation (combining two strings)
- Basis Step if w ? S then w? w, where ?
is the empty string containing no symbols. - Recursive Step if w1 ? S, w2 ? S and x ? S
then - w1(w2 x) ? S (same as (w1 w2) x
? S) - Example
- Sa, b
- Let w1aba, w2a and xb then abaab ? S
17Recursive Definition on Strings
- Length
- Basis Step ? 0
- Recursive Step if w ? S and x ? S then
- wx w 1
- Example
- S a, b
- aba (ab)a ab 1
- ab (a)b a 1 so aba a 2
- a (?)a ? 1 so aba ? 3
- ? 0 so aba 3
18Recursive Function on Strings
- The reversal of a string w, wR, consists of the
string in reverse order. Give a recursive
definition of the reversal of a string. - Example
- w abacd, wR dcaba
- Basis Step if w ? then wR ?
- Recursive Step if w vx where x ? S, v ? S
- then wR xvR
19Well-Formed Formulas
- p,q,r, represent proposition variables T, F and
the set of logical operators ?, ?, ?, ? , ?
- Basis Step
- T, F and p where p is a propositional variable
is well defined (i.e., a wff) - Recursive Step If E and G are wff then
- (?E), (E ? G), (E ? G), (E ? G), (E ? G) are wff
- Examples
- (?p), (p ? q), ((?p) ? q) , ((?p) ? q) are wff
20Recursive Structures
- The set of rooted trees, where a rooted tree
consists of a set of vertices containing a
distinguished vertex called the root, and edges
connecting these vertices, can be defined
recursively by these steps - Basis Step A single vertex r is a rooted tree.
- Recursive Step Suppose that T1, T2, , Tn are
disjoint rooted trees with roots r1, r2, rn,
respectively. Then the graph formed by starting
with a root r, which is not in any of the rooted
trees T1, T2, Tn, and adding an edge from r to
each of the vertices r1, r2, rn is also a
rooted tree.
21Recursive Structures
- The set of extended binary trees can be defined
recursively by these steps - Basis Step The empty set is an extended binary
tree. -
- Recursive Step If T1 and T2 are disjoint
extended binary trees, then there is an extended
binary tree, denoted by T1 T2, consisting of a
root r together with edges connecting the root to
each of the roots of the left subtree T1 and the
right subtree T2 when these trees are nonempty.
22Recursive Structures
- The set of full binary trees can be defined
recursively by these steps - Basis Step There is a full binary tree
consisting only of a single vertex r. - Recursive Step If T1 and T2 are disjoint full
binary trees, there is a full binary tree,
denoted by T1 T2, consisting of a root r
together with edges connecting the root to each
of the roots of the left subtree T1 and the right
subtree T2.
23Counting (now in chapter 5)
- The basic counting principles are the product
rule and sum rule. - Product Rule Suppose that a procedure can be
broken down into a sequence of two tasks. If
there are n ways to do the first task and for
each of these ways of doing the first task, there
are m ways to do the second task, then there are
nm ways to do the procedure. - Sum Rule If a task can be done either in one of
n ways or in one of m ways, where none of the set
of n ways is the same as any of the set of m
ways, then there are n m ways to do the task.
24Counting
- Product Rule Examples.
- Bill and Ted move into a new house with 12
bedrooms. How many ways can we assign rooms to
them? - Stadium seats are labeled with a letter and a
two-digit number (00 99). Whats the maximum
number of seats in the stadium? - How many license plates can we make using three
letters followed by three digits? - .
25Counting
- Sum Rule Examples.
- IHOP offers 16 breakfast items, 22 lunch items,
and 31 dinner items (all unique). How many
possible items do we have to choose from? - How many 8-bit bit strings begin with 1 or end
with 00? - - begin with 1 27
- - end with 00 26
- - oops, some have been double counted how many?
25 - So, 128 64 32 160 ways
- (principle of inclusion-exclusion)
26Counting
- How many 4-bit bit strings are there that do not
have two consecutive 1s? - How many ways can a playoff occur between two
teams where the winner must win 3 out of 5 games.
27Counting
- The Pigeonhole Principle If k is a positive
integer and k1 or more objects are placed in k
boxes, then there is at least one box containing
two or more of the objects. (prove BWOC) - Of 367 people, at least two have the same birth
day. - For every integer n there is a multiple of n that
has only 0s and 1s in its decimal expansion.
28Counting
- For every integer n there is a multiple of n that
has only 0s and 1s in its decimal expansion. - Let n be a positive integer. Consider the n1
integers 1, 11, 111, , 111 where the last
integer is the integer with n1 1s. There are n
possible remainders when an integer is divided by
n. Since there are n1 integers in the list, by
the php there must be at least two with the same
remainder when divided by n. The larger integer
minus the smaller integer is a multiple of n (how
do we know?), which has a decimal expansion
consisting entirely of 0s and 1s.