1 / 22

Recurrence Relations

Recurrence Relations. Chapter 6. Recursion. Defining an object in terms of itself. To recursively define a function:. Specify initial value(s) of function Give a rule for finding a function’s value for one input (n) from its values at previous inputs (n-1).

Download Presentation

Recurrence Relations

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Recurrence Relations Chapter 6

  2. Recursion • Defining an object in terms of itself

  3. To recursively define a function: • Specify initial value(s) of function • Give a rule for • finding a function’s value for one input (n) • from its values at previous inputs (n-1)

  4. {1, 2, 4, 8, 16, … } an = 2n for n=0,1,2,… • The sequence may be defined by giving first term: a0 = 1 • And a rule for finding a term of a sequence from a previous one: an = 2an-1 for n=1, 2, 3, ….

  5. Recurrence Relation • The second part of recursive definition • A rule for • finding a function’s value for one input (n) • from its values at previous inputs (n-1)

  6. Recurrence Relation for sequence {an} • A formula that expresses an • in terms of • one or more previous terms • of sequence, a0, a1, … an-1 • The inductive part of a recursive definition.

  7. Recurrence Relation Solution • A sequence whose terms satisfy a recurrence relation • {a0, a1, a2, a3, … } • NOTE: • If we don't restrict values for the first term of a sequence, there may be many solutions to a given RR.

  8. Find a R.R. Solution (sequence satisfying a recurrence relation) • Let {an} be a solution that satisfies the recurrence relation an = an-1 - an-2 • Let a0 = 3, a1 = 5 • What are a2 and a3? • a2 = a1 - a0 = 5 - 3 = 2 • a3 = a2 - a1 = 2 - 5 = -3

  9. Is the sequence a valid solution for a Recurrence Relation? • Is sequence {an} = { 6, 9, 12, 15, … } OR an = 3n (for n>=2) • a solution for the following recurrence rel? • an = 2an-1 - an-2 for n=2,3,4,… • {an} = { 6, 9, 12, 15, 18, … } • an = 3n, an-1 = 3n - 3 • an-2 = 3n - 6 • an = 2an-1 - an-2 • 3n = 2(3n - 3) - (3n - 6) • = 6n – 6 – 3n + 6 = 3n YES

  10. Is the sequence a valid solution for a Recurrence Relation? • Is the sequence {an}, where an = n • a solution for the following recurr. rel? • an = 2an-1 - an-2 for n=3,4,… • {an} = {3, 4, 5, … } • an = n, an-1 = n - 1 • an-2 = n - 2 • an = 2an-1 - an-2 • an = 2(n - 1) - (n - 2) = n YES

  11. Recurrence Relation Example • Is the sequence {an} where an = 2n • a solution for the recurrence relation • an = 2an-1 - an-2 for n=0,1,2,3,4,… ? • {an} = { 1, 2, 4, 8, 16, 32, … } • an = 2n, an-1 = 2n-1 = 2n2-1 = 2n / 2 • an-2 = 2n-2 = 2n2-2 =2n / 4 • an = 2an-1 - an-2 • 2n = 2(2n / 2) - (2n / 4) = 3 / 4 * 2n NO

  12. Initial Conditions • Specify terms preceding the first term where the recurrence relation takes effect • A sequence is uniquely determined by • Initial conditions • recurrence relation • Without initial conditions, many solutions may exist for a given recurrence relation.

  13. Recurrence Relation Models • A person deposits $10K in savings at 11% compounded annually? • What will be in the account after 30 years? • P0 = 10,000 • Pn = P n-1 + 0.11P n-1 • = 1.11 P n-1

  14. Recurrence Relation Models • What will be in the account after 30 years? • P0 = 10,000 • Pn = 1.11 Pn-1 • P1 = 1.11 P0 • P2 = 1.11 P1 = 1.11* 1.11* P0 = (1.11)2 P0 • P3 = 1.11 P2 = (1.11)3 P0 • Pn = 1.11 Pn-1 = (1.11)n P0 • P30 = (1.11)30 P0 =(1.11)30 *10000 = $228,922.97

  15. Inclusion-Exclusion 6.5

  16. Inclusion-Exclusion Principle • The number of ways of doing two tasks • which may be done at the same time • (i.e., sets are not disjoint) • Add the number of ways to do the first task • To the number of ways to do the second task • Subtract number of ways of doing both tasks

  17. Inclusion-Exclusion Example • Of all CS students • 25 take C++ programming • 18 take discrete math • 6 take both • How many CS students are there? • 25 + 18 is too many • 25 + 18 - 6 = 37 CS students

  18. Inclusion-Exclusion • | A È B | = | A | + | B | - | A Ç B | C++ Discrete 19 6 12 25 18

  19. I-E Example • How many positive integers not exceeding 1000 are divisible by 7 or 11? • | A È B | = | A | + | B | - | A Ç B | • = ë1000/7û + ë1000/11û - ë1000/ (7*11) û • = 142 + 90 - 12 • = 220

  20. Formula for the # Element in the Union of Three Sets • | A È B È C | = ? A B C

  21. Formula for the # Element in the Union of Three Sets • | A È B È C | = | A | + | B | + | C | • - | A Ç B | - | A Ç C | - | B Ç C | • + | A Ç B Ç C |

More Related