Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fall 2015 COMP 2300 Discrete Structures for Computation Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1.

Similar presentations


Presentation on theme: "Fall 2015 COMP 2300 Discrete Structures for Computation Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1."— Presentation transcript:

1 Fall 2015 COMP 2300 Discrete Structures for Computation Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 5.6 Defining Sequences Recursively

2 Fall 2015 COMP 2300 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Sequences Informally, A set of elements written in a row and demonstrate some pattern (i.e. 1, 3, 5, 7, 9) In the sequence denoted, each individual elements is called a term. in is called a subscript or index, is the subscript of the initial term, is the subscript of the final term. 2

3 Fall 2015 COMP 2300 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University How to Express a Sequence? Write the first few terms with the expectation that the general pattern will be obvious i.e. “consider the sequence 3, 5, 7, 9 …” Misunderstandings can occur Give an explicit formula for it th term, i.e. By recursion which requires a recurrence relation. 3 for all integers

4 Fall 2015 COMP 2300 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Recursion Recursion requires recurrence relation relates later terms in the sequence to earlier terms and initial conditions, values of the first few terms of the sequence. Ex. for all integers, (recurrence relation) (initial conditions) 4

5 Fall 2015 COMP 2300 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Formal Definition A recurrence relation for a sequence is a formula that relates each term to certain of its predecessors, where is an integer with. The initial condition for such a recurrence relation specify the values of if is a fixed integer, or, where is an integer with if depends on. 5

6 Fall 2015 COMP 2300 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Another Example Computing terms Recursive sequence, for all integers, find (recurrence relation) (initial conditions) 6

7 Fall 2015 COMP 2300 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Equivalent Recursion There is more than one way to setup a recursive sequence! for all Are the two sequences equivalent? show the results of the sequence for terms: starting at change first term to second by adjusting first for all start at 0 (k≥0) same as the second form. 7

8 Fall 2015 COMP 2300 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Example Show that sequence given satisfies a recurrence relation: for is equivalent to for General term of the sequence starting with, then for substitute for and 8

9 Fall 2015 COMP 2300 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Solving Recursive Problems To solve a problem recursively means to find a way to break it down into smaller subproblems each having the same form as the original problem. 9

10 Fall 2015 COMP 2300 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Towers of Hanoi Problem statement Eight disks with holes in the center that are stacked from largest diameter to smallest on the first of three poles. Move the stacked disk from one pole to another. Rules A larger disk cannot be placed on top of a smaller disk at any time. Watch this: http://www.youtube.com/watc h?v=aGlt2G-DC8c http://www.youtube.com/watc h?v=aGlt2G-DC8c 10

11 Fall 2015 COMP 2300 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Towers of Hanoi Recursive Solution 1.Transfer the top disks from pole to pole. (Note: requires a number of moves.) 2.Move the bottom disk from pole to pole. 3.Transfer the top disks from pole to pole. (Again, if, execution of this step will require more than one move.) 11

12 Fall 2015 COMP 2300 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Towers of Hanoi Suppose is the minimum number of moves to transfer n disks from one pole to another pole. Then, we know and 12

13 Fall 2015 COMP 2300 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Fibonacci 13 Leonardo of Pisa was the greatest mathematician of the 13th century. Proposed the following problem: A single pair of rabbits (male/female) is born at the beginning of a year. Assuming the following conditions: Rabbit pairs are not fertile during their first month of life but thereafter give birth to one new male/female pair at the end of every month. No rabbits die How many rabbits will there be at the end of the year?

14 Fall 2015 COMP 2300 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University 1 st month 2 nd month 3 rd month 4 th month 5 st month Non-fertile Fertile Fibonacci 14 To solve the problem you can hand compute for each of the 12 months.

15 Fall 2015 COMP 2300 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Fibonacci 15 To solve the problem you can hand compute for each of the 12 months. num of pairs alive at end of month k = num of pairs alive at end of month k -1 + num of pairs born at end of month k = num of pairs alive at month k -1 + num of pairs alive at month k -2

16 Fall 2015 COMP 2300 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Why We Need Recursion in Computer Science 16 Give us a power to divide a big problem into smaller pieces Divide-and-Conquer technique (in Algorithm design) Recursive programming is a popular technique Generally, we can use other techniques such as multiple loops, but complicated to design and analyze Question Given that what is ?


Download ppt "Fall 2015 COMP 2300 Discrete Structures for Computation Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1."

Similar presentations


Ads by Google