L027: Rosen, 5.3 Recursive Definition and Structural Induction

Discrete Structures
CMSC 2123
Lecture 27
5.3 Recursive Definitions and Structural Induction
Introduction
recursion
A definition that defines an object in terms of itself.
Recursively Defined Functions
Two steps are employed to define a function with the set of nonnegative integers as its domain:
1. BASIS STEP: Specify the value of the function at zero.
2. RECURSIVE STEP: Give a rule for finding its value at an integer from its values at smaller
integers.
EXAMPLE 1
EXAMPLE 2
Suppose that f is defined recursively by
𝑓𝑓(0) = 3.
𝑓𝑓(𝑛𝑛 + 1) = 2𝑓𝑓(𝑛𝑛) + 3.
Find 𝑓𝑓(1), 𝑓𝑓(2), 𝑓𝑓(3) and 𝑓𝑓(4).
Solution:
𝑓𝑓(1) =
2𝑓𝑓(0) + 3
𝑓𝑓(2) =
2𝑓𝑓(1) + 3
𝑓𝑓(3) =
2𝑓𝑓(2) + 3
𝑓𝑓(4) =
2𝑓𝑓(3) + 3
EXAMPLE 3
Give an inductive definition of the factorial function 𝐹𝐹(𝑛𝑛) = 𝑛𝑛!.
Solution:
1. BASIS STEP: 𝐹𝐹(0) = 1
2. RECURSIVE STEP: 𝐹𝐹(𝑛𝑛 + 1) = (𝑛𝑛 + 1) βˆ™ 𝐹𝐹(𝑛𝑛)
EXAMPLE 4
Give a recursive definition of
9
21
45
93
Give an inductive definition of the function π‘Žπ‘Žπ‘›π‘› , where a is a nonzero real
number an n is a nonnegative integer.
Solution:
1. BASIS STEP: 𝑓𝑓(0) = 1, π‘Žπ‘Ž0 = 1
2. RECURSIVE STEP: 𝑓𝑓(𝑛𝑛 + 1) = π‘Žπ‘Ž βˆ™ 𝑓𝑓(𝑛𝑛), π‘Žπ‘Žπ‘›π‘›+1 = π‘Žπ‘Ž βˆ™ π‘Žπ‘Žπ‘›π‘›
𝑛𝑛
οΏ½ π‘Žπ‘Žπ‘˜π‘˜
π‘˜π‘˜=0
Solution:
1. βˆ‘0π‘˜π‘˜=0 π‘Žπ‘Žπ‘˜π‘˜ = π‘Žπ‘Ž0
𝑛𝑛
2. βˆ‘π‘›π‘›+1
π‘˜π‘˜=0 π‘Žπ‘Žπ‘˜π‘˜ = (βˆ‘π‘˜π‘˜=0 π‘Žπ‘Žπ‘˜π‘˜ ) + π‘Žπ‘Žπ‘›π‘›+1
1
Discrete Structures
CMSC 2123
DEFINITION 1
Lecture 27
5.3 Recursive Definitions and Structural Induction
The Fibonacci numbers, 𝑓𝑓0 , 𝑓𝑓1 , 𝑓𝑓2 , β‹―, are defined by the equations 𝑓𝑓0 = 0 and
𝑓𝑓1 = 1, and
𝑓𝑓𝑛𝑛 = π‘“π‘“π‘›π‘›βˆ’1 + π‘“π‘“π‘›π‘›βˆ’2
EXAMPLE 5
for 𝑛𝑛 = 2, 3, 4 , β‹―
Find the Fibonacci numbers 𝑓𝑓2 , 𝑓𝑓3 , 𝑓𝑓4 , 𝑓𝑓5 , and 𝑓𝑓6 .
Solution:
𝑓𝑓2 = 𝑓𝑓1 + 𝑓𝑓0 =
1+0=
𝑓𝑓3 = 𝑓𝑓2 + 𝑓𝑓1 =
1+1=
𝑓𝑓4 = 𝑓𝑓3 + 𝑓𝑓2 =
2+1=
𝑓𝑓5 = 𝑓𝑓4 + 𝑓𝑓3 =
3+2=
𝑓𝑓6 = 𝑓𝑓5 + 𝑓𝑓4 =
5+3=
2
1
2
3
5
8