28
Discrete Mathematics CS 2610 March 26, 2009 Skip: structural induction generalized induction Skip section 4.5

Discrete Mathematics CS 2610

  • Upload
    mac

  • View
    45

  • Download
    2

Embed Size (px)

DESCRIPTION

Discrete Mathematics CS 2610. March 26, 2009. Skip: structural induction generalized induction Skip section 4.5. Well-Ordering Property. Every non-empty set of non-negative integers has a minimum (smallest) element - PowerPoint PPT Presentation

Citation preview

Page 1: Discrete Mathematics   CS 2610

Discrete Mathematics CS 2610

March 26, 2009

Skip: structural induction generalized inductionSkip section 4.5

Page 2: Discrete Mathematics   CS 2610

2

Well-Ordering PropertyEvery non-empty set of non-negative integers has a minimum (smallest) element

The well-ordering property is the foundation of Mathematical induction

Page 3: Discrete Mathematics   CS 2610

3

RecursionRecursion means defining an object in terms of itself part of itself versions of itself

An object can be Sequence Function Set Algorithm

Page 4: Discrete Mathematics   CS 2610

4

In NatureFractals are self-similar structures, most of them

defined recursively

Romanesque BroccoliA fractal coastline in northern Portugal

Page 5: Discrete Mathematics   CS 2610

5

Recursively Defined SequenceDef.: A sequence is defined recursively whenever some initial terms are specified and later terms are defined in terms of earlier terms.

Arithmetic Seriesa0=1, r=3

an=an-1+r, n>0 yields: 1, 4, 7, 10, 13, …

Geometric Seriesa0=3, r=2

an=an-1r, n>0 yields: 3, 6, 12, 24, 48, …

an = 2n yields: 1, 2, 4, 8, 16, 32, …

or an+1 = 2an where n > 0 and a0 = 1

Page 6: Discrete Mathematics   CS 2610

6

Recursively Defined SequenceIn a recursively defined sequence:

1. Base or Initial Conditions The first term(s) of the sequence are defined

2. 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: a0=1, r=3

Recursion: an=an-1+r, n > 0

Geometric SeriesBase: a0=3, r=2

Recursion: an=an-1r, n > 0

Recurrence Formula

Page 7: Discrete Mathematics   CS 2610

7

Recursively 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? Can’t tell so this is no good.

Page 8: Discrete Mathematics   CS 2610

8

Fibonacci SequenceFibonnaci Sequence

Non-recursive (closed form) Definition

Recursive Definition:Base Cases: f0=0, f1=1

Recurrence: fn = fn-1 + fn-2 for n > 1

nn

nf2

51

2

51

5

1)(

Page 9: Discrete Mathematics   CS 2610

9

Fibonacci SequenceTheorem: fn < 2n.

Proof: (By strong induction.)

1) Base cases:f0 = 0 < 20 = 1f1 = 1 < 21 = 2

2) Inductive step:Inductive Hypothesis: Assume j, 1 < j k, fj < 2j.

i.e., f2 < 22, f3 < 23, …, fk < 2k

show that fk+1 < 2k+1

fk + fk-1 < 2·2k = 2k + 2k

fk < 2k from ind hyp and fk-1 ≤ fk < 2k so

fk+1 < 2k+1

Page 10: Discrete Mathematics   CS 2610

10

Fibonacci SequenceTheorem. n ≥ 3, fn > αn−2, where α = (1+5)/2.Proof. First note that: α2 – α - 1 = (1 + 25 + 5)/4 - (1+5)/2 – 1 = 6/4 + 25/4 – 1/2 - 5/2 – 1 = 5/2 - 5/2 + 3/2 – 1/2 – 1 = 0 (recall quadratic formula)Therefore, α2 = α + 1

Take it away!

Page 11: Discrete Mathematics   CS 2610

11

Recursively Defined FunctionA 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 < n

Basis: f(0) = 1Recursion:

Define f(n) from f defined on smaller terms

Example

Let f : N -> N defined recursively asBasis: f(0) = 1Recursion: 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!

Page 12: Discrete Mathematics   CS 2610

12

Recursively 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) = 1Recursion: f(n) = 1 + f(n/2 ), n ≥ 1Is 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) ?

Consider a function f:N{0,1,2}, Is this function well-defined ?

0 if 2 | n

f (n)= 1 if 3 | n

2 otherwise.

Page 13: Discrete Mathematics   CS 2610

13

Recursively Defined SetAn 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 SRecursive Step: if n S then 2n S

S = {2k | k N }

Page 14: Discrete Mathematics   CS 2610

14

Recursively Defined SetExample:

Basis Step: 0 SRecursive Step: if m S then m + 1 SExclusion Rule: No other numbers are in S.

What is S?

Example:Basis Step: 1 SRecursive Step: if m S then -1m S

Exclusion Rule: No other numbers are in S

What is S?

Page 15: Discrete Mathematics   CS 2610

15

Set of StringsDef.: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: Σ* where is the empty string containing no symbols

Recursive Step: if w Σ* and x Σ then wx Σ* Is * countable or uncountable ?

Page 16: Discrete Mathematics   CS 2610

16

Recursive Definition on Strings

Concatenation (combining two strings)

Basis Step: if w Σ* then w· = w, where is the empty string containing no symbols.

Recursive Step: if w1 Σ*, w2 Σ* and x Σ then

w1·(w2 x) Σ* (same as (w1 · w2) x Σ*)

Example: Σ={a, b}Let w1=aba, w2=a and x=b then abaab Σ*

Page 17: Discrete Mathematics   CS 2610

17

Recursive Definition on Strings

Length

Basis Step: || = 0

Recursive Step: if w Σ* and x Σ then

|wx| = |w| + 1

Example: Σ = {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

Page 18: Discrete Mathematics   CS 2610

18

Recursive 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 Σ, v Σ*

then wR = xvR

Page 19: Discrete Mathematics   CS 2610

19

Well-Formed Formulasp,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

Page 20: Discrete Mathematics   CS 2610

20

Recursive StructuresThe 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.

Page 21: Discrete Mathematics   CS 2610

21

Recursive StructuresThe 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.

Page 22: Discrete Mathematics   CS 2610

22

Recursive StructuresThe 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.

Page 23: Discrete Mathematics   CS 2610

23

Counting (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 n·m 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.

Page 24: Discrete Mathematics   CS 2610

24

CountingProduct 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). What’s the maximum number of seats in the stadium?

How many license plates can we make using three letters followed by three digits?

.

Page 25: Discrete Mathematics   CS 2610

25

CountingSum 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)

Page 26: Discrete Mathematics   CS 2610

26

CountingHow 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.

Page 27: Discrete Mathematics   CS 2610

27

CountingThe Pigeonhole Principle: If k is a positive integer

and k+1 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.

Page 28: Discrete Mathematics   CS 2610

28

CountingFor 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 n+1 integers: 1, 11, 111, …, 11…1 where the last integer is the integer with n+1 1s. There are n possible remainders when an integer is divided by n. Since there are n+1 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.