Title: Recursive Definitions
1Recursive Definitions
2Recursive (or inductive) Definitions
- Sometimes easier to define an object in terms of
itself. - This process is called recursion.
- Sequences
- s0,s1,s2, defined by s0 a and sn 2sn-1
b for constants a and b and n? Z - Sets
- 3 ? S and xy ? S if x?S and y?S
- Functions
- Example f(n) 2n, f(n) 2f(n-1) and f(0) 1
3Recursively Defined Functions
- To define a function with the set of nonnegative
integers as its domain - Specify the value of the function at zero (or
sometimes, it first k terms). - Give a rule for finding its value as an integer
from its values at smaller integers.
4Examples of Recursively Defined Functions
- Factorial Function n!
- n! n(n-1)(n-2).(1)
- f(0) 1, f(n) n(f(n-1))
- an
- f(0) 1, f(n1) ana
- Fibonacci Numbers
- f00, f11, f n1 fn f n-1
- 0,1,1,2,3,5,8,13,...
5Prove that the nth term in the Fibonacci sequence
is when n?2
Induction Proof Basic Step Let n 2, then f2
1 10 Inductive Step Consider k?2
and assume that the expression is true for 2 ? n
? k. We must show that the expression is true
for n k1, I.e., that fk1 fk1 fk fk-1
by definition by the inductive
hyposthesis
6Fibonacci Proof (cont.)
Since f2 is true and fn is true for 2 ? n ? k ?
fk1 is true, then fn is true for all positive
integers n?2.
7Recursively Defined Set Example
- Let the set S be defined recursively as 3 ? S and
xy ? S if x?S and y?S. - Prove that S is equal to the set of positive
integers divisible by 3 (set A). -
- Proof
- To show that S A, we must show that A?S and
that S?A.
8Recursive Set Example (cont.)
- First we will show that A ?S. To do this we must
show that every positive integer divisible by 3
is in S. This is the same as saying that 3n is
in S for n?Z. We will do an inductive proof. - Let p(n) be the statement that 3n?S for n a
positive integer. - Basis Step p(1) 3(1) 3
- Inductive Step We will show that p(n) ? p(n1)
- Let p(n) ? S. Then p(n1) 3(n1) 3n 3.
Since 3n?S and 3?S, then 3n3?S. - Therefore every element in A must be in S.
9Recursive Set Example (cont.)
- Now we will show that S?A. To do this we must
show that every element in S is divisible by 3,
i.e., that it can be represented as 3(j) where j
is a positive integer. - Basis Step 3?A since 3 3(1)
- Inductive Step
- Assume z xy ? S and x,y are in A. x and y are
divisible by 3 since they are both in A.
Therefore x 3j and y 3k for j,k ? Z. Then
z xy 3j3k 3(jk) which is divisible by 3
so z ?A - Therefore every element in S must be in A
10Prove fn gt ?n-2 where ? (1?5)/2 whenever n?3
- Inductive Proof
- Basis Step First we will show fn gt ?n-2 for f3
and f4. - ?3-2 ?1 (1?5)/2 lt (1?9)/2 4/2 2 f3
- ?4-2 ?2 (1?5)/22 (1 2?5 5)/4 (6
2?5)/4 3/2 ?5/2 lt 3/2 ?9/2 3 f4
11 fn gt ?n-2 (cont.)
- Inductive Step
- Assume that fk gt ?k-2 is true for all nonnegative
integers 3 ? k ? n when ngt4 . We must show that
fn1gt ?n-1. - Lemma ?2 (1?5)/22 (12?5 5)/4 3/2
(?5)/2 1 (1?5)/2 1?
12fn gt ?n-2 (cont.)
- ?n-1 ?2?n-3 (?1)(?n-3) ?n-2?n-3
- By our inductive hypothesis
- fn-1 gt ?n-3 and fn gt ?n-2
- fn1 fn fn-1 gt ?n-2?n-3 ?n-1
- Since f3 and f3 are true and fk is true for 3 ?
k ? n ? fn1 is true, then fn is true for all
positive integers n?3
13Find a closed form solution to the recursive
equation T(n) T(n-1) c1. T(0) c0
- One approach is to write down several terms,
guess what the equation is, and then prove that
your guess is correct (or not) using an induction
proof. - T(0) c0
- T(1) T(0) c1 c0 c1
- T(2) T(1) c1 c0 2c1
- T(3) T(2) c1 c0 3c1
- T(4) T(3) c1 c0 4c1
- Guess that T(n) c0 nc1
14Induction proof
- Basis Step for n 0, T(0) c0 (0)c1 c0
- Inductive Step Assume that T(n) c0 nc1, we
must show that T(n1) c0 (n1)c1. - T(n1) T(n) c1 c0 nc1 c1 c0 (n1)c1.
15Find a closed form solution to T(1) c0, T(n)
2T(n-1)c1
- T(1) c0
- T(2) 2T(1) c1 2c0 c1
- T(3) 2T(2)c1 2(2c0c1)c1 4c03c1
- T(4) 2T(3)c1 2(4c03c1)c1 8c07c1
- T(5) 2T(4)c1 2(8c07c1)c1 16c015c1
- Guess that T(n) 2n-1c0 (2n-1-1)c1
16Prove that T(1) c0, T(n) 2T(n-1)c1has closed
form solution T(n) 2n-1c0 (2n-1-1)c1
- Basis Step T(1) 21-1c0 (21-1-1)c1 c0
- Induction Step Assume that T(n) 2n-1c0
(2n-1-1)c1. We must show that T(n1)
2(n1)-1c0 (2(n1)-1-1)c1 2nc0 (2n-1)c1. - T(n1) 2T(n) c1 22n-1c0 (2n-1-1)c1 c1
2nc0 (2n-2)c1 c1 2nc0 2nc1 - c1 2nc0
(2n-1)c1.