lecture#16 discrete mathematics. recursion now, 1 is an odd positive integer by the definition base....

17
Lecture#16 Discrete Mathematics

Upload: gillian-bradley

Post on 31-Dec-2015

221 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture#16 Discrete Mathematics. Recursion Now, 1 is an odd positive integer by the definition base. With k = 1, 1 + 2 = 3, so 3 is an odd positive integer

Lecture#16Discrete Mathematics

Page 2: Lecture#16 Discrete Mathematics. Recursion Now, 1 is an odd positive integer by the definition base. With k = 1, 1 + 2 = 3, so 3 is an odd positive integer

RecursionFirst of all instead of giving the definition of Recursion we give you an example, you already know the Set of Odd numbers Here we give the new definition of the same set that is the set of Odd numbers.Definition for odd positive integers may be given as:BASE:

1 is an odd positive integer.

RECURSION:

If k is an odd positive integer, so is k + 2

Page 3: Lecture#16 Discrete Mathematics. Recursion Now, 1 is an odd positive integer by the definition base. With k = 1, 1 + 2 = 3, so 3 is an odd positive integer

RecursionNow, 1 is an odd positive integer by the definition base.With k = 1, 1 + 2 = 3, so 3 is an odd positive integer.With k = 3, 3 + 2 = 5, so 5 is an odd positive integerand so, 7, 9, 11, … are odd positive integers.REMARK: Recursive definitions can be used in a “generative” manner

Page 4: Lecture#16 Discrete Mathematics. Recursion Now, 1 is an odd positive integer by the definition base. With k = 1, 1 + 2 = 3, so 3 is an odd positive integer

RecursionThe process of defining an object in terms of smaller versions of itself is called recursion.A recursive definition has two parts:BASEAn initial simple definition which cannot be expressed in terms of smaller versions of itselfRECURSIONThe part of definition which can be expressed in terms of smaller versions of itself

Page 5: Lecture#16 Discrete Mathematics. Recursion Now, 1 is an odd positive integer by the definition base. With k = 1, 1 + 2 = 3, so 3 is an odd positive integer

Recursion PrincipleA function is said to be recursively defined if the function refers to itself such that:1. There are certain arguments, called base values, for which the function does not refer to itself2. Each time the function does refer to itself, the argument of the function must be closer to a base value

Page 6: Lecture#16 Discrete Mathematics. Recursion Now, 1 is an odd positive integer by the definition base. With k = 1, 1 + 2 = 3, so 3 is an odd positive integer

Recursion: ExampleSuppose that f is defined recursively byf(0) = 3, f(n+1) = 2 f(n) + 3Find f(1), f(2), f(3) and f(4).

Page 7: Lecture#16 Discrete Mathematics. Recursion Now, 1 is an odd positive integer by the definition base. With k = 1, 1 + 2 = 3, so 3 is an odd positive integer

Recursion: ExampleFind f(2), f(3), and f(4) if f is defined recursively by f(0) = -1, f(1)=2 and for n = 1, 2, 3, …f(n+1) = f(n) + 3 f(n - 1)

Page 8: Lecture#16 Discrete Mathematics. Recursion Now, 1 is an odd positive integer by the definition base. With k = 1, 1 + 2 = 3, so 3 is an odd positive integer

Factorial FunctionN! = N X (N-1) X (N-2) ….. X 2 X 1Recursive definition of factorial function is:Factorial(0) = 1Factorial(n) = n Factorial(n-1)

Page 9: Lecture#16 Discrete Mathematics. Recursion Now, 1 is an odd positive integer by the definition base. With k = 1, 1 + 2 = 3, so 3 is an odd positive integer

Factorial FunctionN! = N X (N-1) X (N-2) ….. X 2 X 1Recursive definition of factorial function is:Factorial(0) = 1Factorial(n) = n Factorial(n-1)

Page 10: Lecture#16 Discrete Mathematics. Recursion Now, 1 is an odd positive integer by the definition base. With k = 1, 1 + 2 = 3, so 3 is an odd positive integer

Sum FunctionLet S be the function such that S(n) is the sum of the first n positive integers. Give a recursive definition of S(n).Solution:Initial value of this function may be specified as S(0)=0 Since S(n) = n + (n - 1) + (n - 2) + … + 3 + 2 + 1= n + [(n - 1) + (n - 2) + … + 3 + 2 + 1]= n + S(n-1)which defines the recursive step.Accordingly S may be defined as:1. S(0)= 0 2. S(n) = n + S(n - 1) for n 1

Page 11: Lecture#16 Discrete Mathematics. Recursion Now, 1 is an odd positive integer by the definition base. With k = 1, 1 + 2 = 3, so 3 is an odd positive integer

Sum FunctionLet a and b denote positive integers. Suppose a function Q is defined recursively as follows:

if1),(

if0),(

abbbaQ

babaQ

Find the value of Q(2,3) and Q(14,3)

What does this function do? Find Q (3355, 7)

Page 12: Lecture#16 Discrete Mathematics. Recursion Now, 1 is an odd positive integer by the definition base. With k = 1, 1 + 2 = 3, so 3 is an odd positive integer

Fibonacci SeriesThe Fibonacci sequence is defined as follows.F0=1, F1=1Fk = Fk – 1 + Fk – 2 for all integers k 2F2 = F1 + F0 = 1 + 1 = 2F3 = F2 + F1 = 2 + 1 = 3F4 = F3 + F2 = 3 + 2 = 5F5 = F4 + F3 = 5 + 3 = 8 . . .

Page 13: Lecture#16 Discrete Mathematics. Recursion Now, 1 is an odd positive integer by the definition base. With k = 1, 1 + 2 = 3, so 3 is an odd positive integer

Recurrence RelationA recurrence relation for a sequence a0, a1, a2, . . . , is a formula that relates each term ak to certain of its predecessors ak – 1, ak – 2, . . . , ak – i , where i is a fixed integer and k is any integer greater than or equal to i. The initial conditions for such a recurrence relation specify the values of a0, a1, a2, . . . ,.ai – 1

Page 14: Lecture#16 Discrete Mathematics. Recursion Now, 1 is an odd positive integer by the definition base. With k = 1, 1 + 2 = 3, so 3 is an odd positive integer

Recurrence Relation: ExampleFind the first four terms of the following recursively defined sequence.b1 = 2bk = bk – 1 + 2 · k, for all integers k 2

Page 15: Lecture#16 Discrete Mathematics. Recursion Now, 1 is an odd positive integer by the definition base. With k = 1, 1 + 2 = 3, so 3 is an odd positive integer

Recurrence Relation: ExampleFind the first five terms of the following recursively defined sequence.t0 = – 1, t1 = 1tk = tk – 1 + 2 · tk – 2, for all integers k 2

Page 16: Lecture#16 Discrete Mathematics. Recursion Now, 1 is an odd positive integer by the definition base. With k = 1, 1 + 2 = 3, so 3 is an odd positive integer

Recurrence Relation: ExampleDefine a sequence b0, b1, b2, . . . by the formula bn = 5n, for all integers n 0. Show that this sequence satisfies the recurrence relation bk = 5bk – 1, for all integers k 1.

Page 17: Lecture#16 Discrete Mathematics. Recursion Now, 1 is an odd positive integer by the definition base. With k = 1, 1 + 2 = 3, so 3 is an odd positive integer

Recurrence Relation: ExampleShow that the sequence 0, 1, 3, 7, . . . , 2n – 1, . . . , for n 0, satisfies the recurrence relationdk = 3dk – 1 – 2dk – 2, for all integers k 2