Download Part 2 - Dr. Djamel Bouchaffra

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

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

Document related concepts
no text concepts found
Transcript
CSE 504 Discrete Structures &
Foundations of Computer Science
Dr. Djamel Bouchaffra
Chapter 3 (Part 2):
Mathematical Reasoning, Induction
& Recursion
‹ Recursive Definitions & Structural
Induction (3.4)
Introduction
‹ Define an object in
terms of itself: this
process is called
recursion
Ch. 3 (Part 2): Sections 3.4
1
CSE 504 Discrete Structures &
Foundations of Computer Science
Dr. Djamel Bouchaffra
Introduction (cont.)
‹We can use recursion to define sequences,
functions and sets
‹Example: the sequence of powers of 2 is given by
an = 2n for n = 0, 1, 2, … (explicitly defined)
a0 = 1; an+1 = 2an for n = 0, 1, 2, … (recursively
defined)
Recursively Defined Functions
‹We use 2 steps to define a function recursively:
X Basis step: specify the the value of the function at 0
X Recursive step: give a rule for determining its value at an
integer from its value at smaller integers
X Such a definition is called a recursive or induction
definition
Ch. 3 (Part 2): Sections 3.4
2
CSE 504 Discrete Structures &
Foundations of Computer Science
Dr. Djamel Bouchaffra
Recursively Defined Functions (cont.)
‹Example: f defined recursively as:
f(0) = 3
f(n + 1) = 2 f(n) + 3
determine f(1), f(2), f(3) and f(4)
Solution: by definition:
f(1) = 2f(0) + 3 = 2 * 3 + 3 = 9
f(2) = 2f(1) + 3 = 2 * 9 + 3 = 21
f(3) = 2f(2) + 3 = 2 * 21 + 3 = 45
f(4) = 2f(3) + 3 = 2 * 45 + 3 = 93
Recursively Defined Functions (cont.)
‹Example: Give an inductive definition of F(n) = n!
Solution:
Basis step: Specify the initial value of this
function; F(0) = 1.
Recursive step: give a rule for determining
F(n + 1) from F(n)
(n + 1)! = (n + 1) * n! ⇒ F(n + 1) = (n + 1) F(n)
Ch. 3 (Part 2): Sections 3.4
3
CSE 504 Discrete Structures &
Foundations of Computer Science
Dr. Djamel Bouchaffra
Recursively Defined Functions (cont.)
n
‹Example: Give a recursive definition of
∑a
k =0
k
Solution:
0
Basis step:
∑a
k =0
k
= a0
 n

Recursive step: ∑ a k =  ∑ a k  + a n + 1
k =0
 k =0 
n+1
Recursively Defined Functions (cont.)
‹Definition 1:
The Fibonacci numbers, f0, f1, f2, …, are defined by
the equations f0 = 0, f1 = 1, and
fn = fn-1 + fn-2
for n = 2, 3, 4, …
Ch. 3 (Part 2): Sections 3.4
4
CSE 504 Discrete Structures &
Foundations of Computer Science
Dr. Djamel Bouchaffra
Recursively Defined Functions (cont.)
‹Example: Determine the Fibonacci numbers
f2, f3, f4, f5 and f6
Solution:
Basis step: f0 = 0 and f1 = 1
Recursive step: fn = fn-1 + fn-2 ⇒
f2 = f1 + f0 = 1 + 0 = 1
f3 = f2 + f1 = 1 + 1 = 2
f4 = f3 + f2 = 2 + 1 = 3
f5 = f4 + f3 = 3 + 2 = 5
f6 = f5 + f4 = 5 + 3 = 8
Recursively defined sets and structures.
Recursively Defined Functions (cont.)
‹Question: How can sets be defined recursively?
Example: Consider the subset S of the set of
integers defined by:
Basis step: 3 ∈ S
Recursive steps: if x ∈ S ∧ y ∈ S ⇒ x + y ∈ S.
3 ∈ S (basis step)
3 ∈ S ∧ 3 ∈ S ⇒ 3 + 3 = 6 ∈ S (recursive step)
6 ∈ S ∧ 3 ∈ S ⇒ 6 + 3 = 9 ∈ S (recursive step)
6 ∈ S ∧ 6 ∈ S ⇒ 6 + 6 = 12 ∈ S (recursive step)
Ch. 3 (Part 2): Sections 3.4
5
CSE 504 Discrete Structures &
Foundations of Computer Science
Dr. Djamel Bouchaffra
Recursively Defined Functions (cont.)
‹Definition 2:
The set Σ* of strings over the alphabet Σ can be
defined by
Basis step: λ ∈ Σ* (where λ is the empty string
containing no symbols)
Recursive step: if w ∈ Σ* and x ∈ Σ, then wx ∈ Σ*.
‹
Example: if Σ = {0, 1}
Basis step: λ ∈ Σ*
Recursive step: 0, 1 (0 ∈ Σ*, 1 ∈ Σ*)
Recursive step: 00 01 10 11 ∈ Σ*
Recursively Defined Functions (cont.)
‹Definition 3
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 ∈ Σ*, w2 ∈ Σ* and x ∈ Σ, then
w1 ⋅ (w2x) = (w1 ⋅ w2) x.
‹
Example:
Ch. 3 (Part 2): Sections 3.4
w1= abra
w2 = cadabra
w1w2 = abracadabra
6
CSE 504 Discrete Structures &
Foundations of Computer Science
Dr. Djamel Bouchaffra
Recursively Defined Functions (cont.)
‹ Definition 4
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 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.
Building up rooted trees
Basis step
Step 1
Step 2
…
Ch. 3 (Part 2): Sections 3.4
…
7
Related documents