12
Ch VII: RECURRENCE RELATIONS Example 1: Arrangements Find a recurrence relation for a n , the number of arrangements of n distinct objects a n = n(a n-1 ) Example 2: Stair Climbing An elf has a staircase of n stairs to climb. Each step it takes can cover one or two stairs. Find a recurrence relation for a n , the number of different sequences of steps to climb n stairs. By inspection, a 1 =1, a 2 =2 (1+1, 2), a 3 =3(1+1+1, 2+1, 1+2) First step 1 stair (n-1 left) 2 stairs (n-2 left) a n = a n-1 + a n-2

Apache2 Ubuntu Default Page: It workstucker/AMS301-VII.1,3.docx · Web viewCh VII: RECURRENCE RELATIONS Ex ample 1: Arrangements Find a recurrence relation for a n, the number of

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Apache2 Ubuntu Default Page: It workstucker/AMS301-VII.1,3.docx · Web viewCh VII: RECURRENCE RELATIONS Ex ample 1: Arrangements Find a recurrence relation for a n, the number of

Ch VII: RECURRENCE RELATIONSExample 1: ArrangementsFind a recurrence relation for an, the number of arrangements of n distinct objects an = n(an-1)

Example 2: Stair ClimbingAn elf has a staircase of n stairs to climb. Each step it takes can cover one or two stairs. Find a recurrence relation for an, the number of different sequences of steps to climb n stairs. By inspection, a1 =1, a2 =2 (1+1, 2), a3 =3(1+1+1, 2+1, 1+2)

First step 1 stair (n-1 left) 2 stairs (n-2 left)an = an-1 + an-2

Fibonacci relation an = an-1 + an-2 , a0 = 1, a1 = 1: 1,1,2,3,5,8,13,..

Page 2: Apache2 Ubuntu Default Page: It workstucker/AMS301-VII.1,3.docx · Web viewCh VII: RECURRENCE RELATIONS Ex ample 1: Arrangements Find a recurrence relation for a n, the number of

Example 3: Dividing the PlaneWe draw n straight lines across a piece of paper such that every pair of lines intersects at a different point. Find a recurrence relation for an, the number of regions formed by the n lines. a0 = 1, a1 = 2, a2 = 4 , BUT a3 = 7

Count as an = an-1 + (number of regions split in two) = an-1 +

Page 3: Apache2 Ubuntu Default Page: It workstucker/AMS301-VII.1,3.docx · Web viewCh VII: RECURRENCE RELATIONS Ex ample 1: Arrangements Find a recurrence relation for a n, the number of

Example 5: Savings AccountsA bank pays 4% interest each year on money in a savings account. Find a recurrence relation for an, the amount of money a gnome would have after n years if it follows the investment strategy of:(i) Investing $1000 and leaving it in the bank.(ii) Investing $100 at the end of each year.(iii) Your debt after n years, an, if you borrow $10,000 and pay back $500 at the end of each year; an = debt after n years.(i) an = an-1 + (changes in account in n-th year, e.g, interest) = an-1 + .04an-1 = (1.04)an-1

Solving an = 1000(1.04)n

(iii) building on (i), first without repayment an = an-1 + .04an-1

Now add repayment an = 1.04an-1 +/-? 500

Example 7: Forbidden SubsequenceFind a recurrence relation for an, the number of n-digit ternary sequences that do not contain the (consecutive) subsequence “012”.

Start 1 2 0 - 012an = an-1 + an-1 + (an-1 - an-3) Problem: some of the valid sequences of length n-1 following an 0 produce an invalid sequence 0 1 2 x x x

Page 4: Apache2 Ubuntu Default Page: It workstucker/AMS301-VII.1,3.docx · Web viewCh VII: RECURRENCE RELATIONS Ex ample 1: Arrangements Find a recurrence relation for a n, the number of

valid sequence of length n-1

Page 5: Apache2 Ubuntu Default Page: It workstucker/AMS301-VII.1,3.docx · Web viewCh VII: RECURRENCE RELATIONS Ex ample 1: Arrangements Find a recurrence relation for a n, the number of

Example: 8: Selection Without RepetitionFind a recurrence relation for ak,n , the number of ways to pick k items from a set of n distinct items. Do sequentially. Consider the first item: choose it (then pick k-1 from remaining n-1) or don’t choose it (then pick k from remaining n-1) Start pick first don’t pick first ak,n = ak-1,n-1 + ak,n-1

1 1 1

1 2 1 1 3 3 1 1 4 6 4 1

Page 6: Apache2 Ubuntu Default Page: It workstucker/AMS301-VII.1,3.docx · Web viewCh VII: RECURRENCE RELATIONS Ex ample 1: Arrangements Find a recurrence relation for a n, the number of

Example 9: Distributionsi) Find a recurrence relation for the number of ways to distribute n identical balls into k distinct boxes with between two and four balls in each box.ii) Repeat the problem drawing from piles of balls of three different colors.

i) Solve like Example 8. Instead of picking 0 or 1 of first object, now we pick 2 or 3 or 4 for the first box—and pick rest from other k boxes.

# of 1st type 2 3 4

ak,n = ak-1,n-2 + ak-1,n-3 + ak-1,n-4

ii) Now there are C(3+m-1,m) ways to pick m objects to put in each box

# of 1st type 2 3 4 ak,n = C(3+2-1,2)ak-1,n-2 + C(3+3-1,3)ak-1,n-3 + C(3+4-1,4)ak-1,n-4

Page 7: Apache2 Ubuntu Default Page: It workstucker/AMS301-VII.1,3.docx · Web viewCh VII: RECURRENCE RELATIONS Ex ample 1: Arrangements Find a recurrence relation for a n, the number of

7.3 Solution to Linear Recurrence Relations

For the rec. rel. an = 2an-1 + 3an-2 or an - 2an-1 - 3an-2 = 0 (*)we ‘guess’ that the solution will be of the form an = n (like y = elx in linear differential equations)

Substituting in the rec. rel., we have n

– 2n-1 - 3n-2 = 0

Factoring out a common n-2 term, we have 2 - 2 - 3 = 0 – a quadratic equation which factors to ( -3)( +1) = 0 so that = 3 or -1.

Checking one of our answers: for = 3, we substitute an = 3n in the rec. rel. (*) 3n – 2•3n-1 - 3•3n-2 = [32 – 2x3 - 3]3n-2 = [ 0 ] 3n-2 = 0We can also multiply this solution by any constant A and it will still be a solution. The most general form of the solution to our second-order rec. rel. is A•3n + B• (-1)n since a linear combination of solutions is again a solution. The constants are chosen to satisfy initial conditions.

Page 8: Apache2 Ubuntu Default Page: It workstucker/AMS301-VII.1,3.docx · Web viewCh VII: RECURRENCE RELATIONS Ex ample 1: Arrangements Find a recurrence relation for a n, the number of

Example 2: Solve an = 2an-1 + 3an-2 with a0 = a1 = 1 We already know that the general solution has the form an = A•3n + B•(-1)n. Substituting the values of n = 0 and n = 1 we have in this form, we have 1 = a0 = A•30 + B•(-1)0 = A + B 1 = a1 = A•31 + B•(-1)1 = 3A - B We solve these two equations in two unknowns. Adding the two eq. we get 2 = 4A --> A = ½ --> B = 1 – A = ½

Solution an = (1/2)3n + (1/2)(-1)n

Note that the solution to the Fibonacci rec. rel an = an-1 + an-2 , with initial conditions a0 = 1, a1 = 1 is an = 1√5 {1+√5

2}n+1

- 1√5 {1−√52

}n+1

--- it is easier to iterate