Download Induction and Recursion 093 ICS 253: Discrete

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Algorithm characterizations wikipedia , lookup

Computational phylogenetics wikipedia , lookup

Binary search algorithm wikipedia , lookup

History of the Church–Turing thesis wikipedia , lookup

Recursion (computer science) wikipedia , lookup

Corecursion wikipedia , lookup

Transcript
King Fahd University of Petroleum & Minerals
Information & Computer Science Department
ICS 253: Discrete Structures I
Induction and Recursion
093 ICS 253: Discrete Structures I
2
Induction and Recursion
Section 4.2: Strong Induction and Well Ordering
• Strong induction is similar to the mathematical
induction in both requiring a basis step.
• Strong induction differs in the inductive step,
where we assume that the statement P(j) is true
for all j  k, and then prove that P holds for
j=k+1.
• The validity of both mathematical induction and
strong induction follow from the well-ordering
property.
•
In fact, mathematical induction, strong induction,
and well-ordering are all equivalent principles.
093 ICS 253: Discrete Structures I
3
Induction and Recursion
Strong Induction
• Basis Step: P(1) is shown to be true
• Inductive Step:
[P(1)  P(2)  …  P(n)]  P(n+1)
is shown to be true for every positive integer n
093 ICS 253: Discrete Structures I
4
Induction and Recursion
Examples
• Suppose we can reach the first and second
rungs of an infinite ladder, and we know that
if we can reach a rung, then we can reach two
rungs higher.
• Can we prove that we can reach every rung using
the principle of mathematical induction?
• Can we prove that we can reach every rung using
strong induction?
093 ICS 253: Discrete Structures I
5
Induction and Recursion
Examples
• Show that if n is an integer greater than 1, then
n can be written as the product of primes.
093 ICS 253: Discrete Structures I
6
Induction and Recursion
Examples
• Prove that every amount of postage of 12
cents or more can be formed using just 4-cent
and 5-cent stamps.
093 ICS 253: Discrete Structures I
7
Induction and Recursion
Well Ordering Property
• Mathematical induction follows from the
following fundamental axiom
The Well Ordering Property: Every nonempty set of nonnegative integers has a least
element
• The well ordering property can often be used
directly in proofs.
093 ICS 253: Discrete Structures I
8
Induction and Recursion
Section 4.3: Recursive Definitions and
Structural Induction
• Sometimes it is difficult to define an object explicitly.
However, it may be easy to define this object in terms
of itself. This process is called recursion.
093 ICS 253: Discrete Structures I
9
Induction and Recursion
Recursive Definitions and Structural Induction
• Recursion can be used to define sequences,
functions and sets
n
• Sequences: an  2 can also be defined as
n 0
1
an  
2an 1 n  1
• Functions: Similar to sequences
• After all, sequences are, themselves, functions!
• Sets
093 ICS 253: Discrete Structures I
10
Induction and Recursion
Recursively Defined Functions
• Q3 pp 308: Find f(2), f(3), f(4), and f(5) if f is
defined recursively by f(0) = –1, f(l) = 2 and
for n = 1,2, ...
a) f(n + 1) = f(n) + 3f(n – 1).
b) f(n + 1) = f(n)2 f(n – 1).
c) f(n + 1) = 3f(n)2 – 4f(n – 1)2.
d) f(n + 1) = f(n – l)/f(n).
093 ICS 253: Discrete Structures I
Induction and Recursion
11
Recursively Defined Functions
• Give an inductive definition of the factorial
function F(n) = n!.
n
• Give a recursive definition of
a
k 0
k
093 ICS 253: Discrete Structures I
12
Induction and Recursion
Fibonacci Numbers
• Definition: The Fibonacci numbers, f0, f1, f2, .
. . , are defined by the equations f0 = 0, f1 = 1,
and fn = fn – l + fn – 2 for n = 2, 3, 4, . . . .
• Show that whenever n  3, fn >  n – 2 , where
1 5

2
093 ICS 253: Discrete Structures I
13
Induction and Recursion
Recursively Defined Sets and Structures
• In recursively defined sets, the basis step defines
some initial elements and the recursive step
defines a rule for constructing new elements
from those already in the set.
• Recursive definitions may also include an
exclusion rule, which specifies that a recursively
defined set contains nothing other than those
elements specified in the basis step or generated
by applications of the recursive step.
• We will assume that it always holds.
• To prove results about recursively defined sets
we use a method called structural induction.
093 ICS 253: Discrete Structures I
14
Induction and Recursion
Example
• Consider the subset S of the set of integers
defined by
• Basis step: 3 S.
• Recursive step: If x  S and y  S, then
x + y  S.
• Show that S is the set of all positive integers
that are multiples of 3.
093 ICS 253: Discrete Structures I
15
Induction and Recursion
Strings Over Alphabet 
• Definition: The set * of strings over the
alphabet  can be defined recursively by
• Basis step: * (where  is the empty string
containing no symbols).
• Recursive step: If w* and x, then wx*.
• Example: What are the strings formed over
={0,1}?
093 ICS 253: Discrete Structures I
16
Induction and Recursion
Concatenation of Strings
• Definition: Two strings can be combined via
the operation of concatenation. Let  be a set
of symbols and * the set of strings formed
from symbols in . We can define the
concatenation of two strings, denoted by .,
recursively as follows.
• Basis step: If w  *, then w ·  = w, where  is
the empty string.
• Recursive step: If w1* and w2* and x,
then w1 · (w2 x ) = (w1 . w2)x.
• Usually, w1 . w2 is denoted by w1w2
093 ICS 253: Discrete Structures I
17
Induction and Recursion
Length of a String
• Give a recursive definition of l(w), the length
of the string w.
• Solution:
The length of a string can be defined by
• l() = 0;
• l(wx) = l(w) + 1 if w  * and x  .
• Use structural induction to prove that l(xy) =
I(x) + l(y).
093 ICS 253: Discrete Structures I
18
Induction and Recursion
Well-Formed Formulae
• Well-Formed Formulae for Compound Statement Forms
• We can define the set of well-formed formulae for compound
statement forms involving T, F, propositional variables, and
operators from the set {,,,,} as follows
• Basis step: T, F, and s, where s is a propositional variable, are wellformed formulae.
• Recursive step: If E and F are well-formed formulae, then (E), (E 
F), (E  F), (E  F), and (E  F) are well-formed formulae.
• Is (p  q)  (q  F) a well-formed formula?
• Is p   q a well-formed formula?
• Can you similarly define well-formed formulae for operators
and operands?
• Show that every well-formed formulae for compound
propositions contains an equal number of left and right
parentheses.
093 ICS 253: Discrete Structures I
19
Induction and Recursion
Rooted Trees
• Definition: 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 rl , 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. .
093 ICS 253: Discrete Structures I
20
Building Up Rooted Trees
Induction and Recursion
093 ICS 253: Discrete Structures I
21
Induction and Recursion
Extended Binary Trees
• Definition: 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, there is an extended binary tree, denoted
by Tl · T2 , consisting of a root r together with edges
connecting the root to each of the roots of the left
subtree Tl and the right subtree T2 when these trees
are nonempty.
093 ICS 253: Discrete Structures I
22
Building Extended Binary Trees
Induction and Recursion
093 ICS 253: Discrete Structures I
23
Induction and Recursion
Full Binary Trees
• Definition: 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 Tl and T2 are disjoint full
binary trees, there is a full binary tree, denoted by
Tl · T2 , consisting of a root r together with edges
connecting the root to each of the roots of the left
subtree Tl and the right subtree T2 .
093 ICS 253: Discrete Structures I
24
Examples of Full Binary Trees
Induction and Recursion
093 ICS 253: Discrete Structures I
25
Induction and Recursion
Full Binary Trees
• Denote the number of nodes in full binary
tree T as n(T).
• Can you provide a recursive definition of n(T)?
• Definition: The height h(T) of a full binary
tree T recursively as follows
• Basis step: The height of the full binary tree T
consisting of only a root r is h(T) = 0.
• Recursive step: If T1 and T 2 are full binary trees,
then the full binary tree T = T1 · T2 has height
h(T) = 1 + max(h(T 1 ), h(T2))
093 ICS 253: Discrete Structures I
Induction and Recursion
26
Full Binary Trees
• Theorem: If T is a full binary tree, then
n (T )  2
h (T ) 1
1
Proof (By Structural Induction):
093 ICS 253: Discrete Structures I
27
Induction and Recursion
Full Binary Trees
• Definition: A leaf node is a node that has no
children.
• Definition: An internal node is a node that has
one or more children.
• Prove that in any full binary tree, the number
of leaf nodes is one more than the number of
internal nodes.
093 ICS 253: Discrete Structures I
28
Induction and Recursion
Generalized Induction
• Instead of using induction on Z+ or N, we can
extend it to any set having the well-ordering
property
• For example, consider N  N with the following
property (called lexicographic ordering)
• (x1, y1) is less than or equal to (x2, y2) if either
x1<x2, or x1=x2 and y1<y2;
Induction and Recursion
29
093 ICS 253: Discrete Structures I
Example
• Suppose that am,n is defined recursively for
(m, n)  N  N
am ,n
0

 am 1,n  1
a
 m ,n 1  n
if m  n  0
if n  0 and m  0
if n  0
Show that am,n = m + n(n + 1)/2 for all
(m,n)N  N