Advanced Counting Techniques CS1200, CSE IIT Madras Meghana Nasre - - PowerPoint PPT Presentation

advanced counting techniques
SMART_READER_LITE
LIVE PREVIEW

Advanced Counting Techniques CS1200, CSE IIT Madras Meghana Nasre - - PowerPoint PPT Presentation

Advanced Counting Techniques CS1200, CSE IIT Madras Meghana Nasre April 16, 2020 CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques Advanced Counting Techniques Principle of Inclusion-Exclusion Recurrences and its


slide-1
SLIDE 1

Advanced Counting Techniques

CS1200, CSE IIT Madras Meghana Nasre April 16, 2020

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-2
SLIDE 2

Advanced Counting Techniques

  • Principle of Inclusion-Exclusion
  • Recurrences and its applications
  • Solving Recurrences

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-3
SLIDE 3

Recap: Solving recurrences

We have seen

  • Method of Repeated Substitution.
  • Linear Homogeneous recurrence relations with constant coefficients.
  • Use of characteristic equation to solve these recurrences.

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-4
SLIDE 4

Recap: Solving recurrences

We have seen

  • Method of Repeated Substitution.
  • Linear Homogeneous recurrence relations with constant coefficients.
  • Use of characteristic equation to solve these recurrences.

Today:

  • Non-homogeneous case.
  • Comparing functions (a short detour).

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-5
SLIDE 5

Example 1

an = 3 · n · 2n − an−1

  • This is a non-homogeneous linear recurrence with constant coefficients.

The presence of the term F(n) = 3 · n · 2n makes it non-homogeneous.

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-6
SLIDE 6

Example 1

an = 3 · n · 2n − an−1

  • This is a non-homogeneous linear recurrence with constant coefficients.

The presence of the term F(n) = 3 · n · 2n makes it non-homogeneous.

  • The recurrence an = −an−1 is the “associated homogeneous recurrence”.

We know the general form for the solution :

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-7
SLIDE 7

Example 1

an = 3 · n · 2n − an−1

  • This is a non-homogeneous linear recurrence with constant coefficients.

The presence of the term F(n) = 3 · n · 2n makes it non-homogeneous.

  • The recurrence an = −an−1 is the “associated homogeneous recurrence”.

We know the general form for the solution : call this solution {a(h)

n }.

For the example it is α1 · (−1)n.

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-8
SLIDE 8

Example 1

an = 3 · n · 2n − an−1

  • This is a non-homogeneous linear recurrence with constant coefficients.

The presence of the term F(n) = 3 · n · 2n makes it non-homogeneous.

  • The recurrence an = −an−1 is the “associated homogeneous recurrence”.

We know the general form for the solution : call this solution {a(h)

n }.

For the example it is α1 · (−1)n.

  • Suppose there is a solution to the non-homogeneous recurrence

that we somehow guess!, lets call it {a(p)

n }.

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-9
SLIDE 9

Example 1

an = 3 · n · 2n − an−1

  • This is a non-homogeneous linear recurrence with constant coefficients.

The presence of the term F(n) = 3 · n · 2n makes it non-homogeneous.

  • The recurrence an = −an−1 is the “associated homogeneous recurrence”.

We know the general form for the solution : call this solution {a(h)

n }.

For the example it is α1 · (−1)n.

  • Suppose there is a solution to the non-homogeneous recurrence

that we somehow guess!, lets call it {a(p)

n }. Note that this may still not

satisfy base cases.

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-10
SLIDE 10

Example 1

an = 3 · n · 2n − an−1

  • This is a non-homogeneous linear recurrence with constant coefficients.

The presence of the term F(n) = 3 · n · 2n makes it non-homogeneous.

  • The recurrence an = −an−1 is the “associated homogeneous recurrence”.

We know the general form for the solution : call this solution {a(h)

n }.

For the example it is α1 · (−1)n.

  • Suppose there is a solution to the non-homogeneous recurrence

that we somehow guess!, lets call it {a(p)

n }. Note that this may still not

satisfy base cases.

In the example, the formula (2n + 2

3 ) · 2n satisfies the given recurrence.

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-11
SLIDE 11

Example 1

an = 3 · n · 2n − an−1

  • This is a non-homogeneous linear recurrence with constant coefficients.

The presence of the term F(n) = 3 · n · 2n makes it non-homogeneous.

  • The recurrence an = −an−1 is the “associated homogeneous recurrence”.

We know the general form for the solution : call this solution {a(h)

n }.

For the example it is α1 · (−1)n.

  • Suppose there is a solution to the non-homogeneous recurrence

that we somehow guess!, lets call it {a(p)

n }. Note that this may still not

satisfy base cases.

In the example, the formula (2n + 2

3 ) · 2n satisfies the given recurrence.

Then the solution to the given recurrence is of the form {an} = {a(p)

n } + {a(h) n }

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-12
SLIDE 12

Example 1

an = 3 · n · 2n − an−1

  • This is a non-homogeneous linear recurrence with constant coefficients.

The presence of the term F(n) = 3 · n · 2n makes it non-homogeneous.

  • The recurrence an = −an−1 is the “associated homogeneous recurrence”.

We know the general form for the solution : call this solution {a(h)

n }.

For the example it is α1 · (−1)n.

  • Suppose there is a solution to the non-homogeneous recurrence

that we somehow guess!, lets call it {a(p)

n }. Note that this may still not

satisfy base cases.

In the example, the formula (2n + 2

3 ) · 2n satisfies the given recurrence.

Then the solution to the given recurrence is of the form {an} = {a(p)

n } + {a(h) n }

=

  • 2n + 2

3

  • · 2n + α1(−1)n

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-13
SLIDE 13

Example 1

an = 3 · n · 2n − an−1

  • This is a non-homogeneous linear recurrence with constant coefficients.

The presence of the term F(n) = 3 · n · 2n makes it non-homogeneous.

  • The recurrence an = −an−1 is the “associated homogeneous recurrence”.

We know the general form for the solution : call this solution {a(h)

n }.

For the example it is α1 · (−1)n.

  • Suppose there is a solution to the non-homogeneous recurrence

that we somehow guess!, lets call it {a(p)

n }. Note that this may still not

satisfy base cases.

In the example, the formula (2n + 2

3 ) · 2n satisfies the given recurrence.

Then the solution to the given recurrence is of the form {an} = {a(p)

n } + {a(h) n }

=

  • 2n + 2

3

  • · 2n + α1(−1)n

If base case is a1 = 1 we get α1 = 13

3 . Check out the formula works!

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-14
SLIDE 14

Example 1 continued

an = 3 · n · 2n − an−1

  • This is a non-homogeneous linear recurrence with constant coefficients.

The presence of the term F(n) = 3 · n · 2n makes it non-homogeneous.

  • The recurrence an = −an−1 is the “associated homogeneous recurrence”.

We know the general form for the solution : call this solution {a(h)

n }.

For the example it is α1 · (−1)n.

  • Suppose there is a solution to the non-homogeneous recurrence

that we somehow guess!, lets call it {a(p)

n }. Note that this may still not

satisfy base cases.

In the example, the formula (2n + 2

3 ) · 2n satisfies the given recurrence.

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-15
SLIDE 15

Example 1 continued

an = 3 · n · 2n − an−1

  • This is a non-homogeneous linear recurrence with constant coefficients.

The presence of the term F(n) = 3 · n · 2n makes it non-homogeneous.

  • The recurrence an = −an−1 is the “associated homogeneous recurrence”.

We know the general form for the solution : call this solution {a(h)

n }.

For the example it is α1 · (−1)n.

  • Suppose there is a solution to the non-homogeneous recurrence

that we somehow guess!, lets call it {a(p)

n }. Note that this may still not

satisfy base cases.

In the example, the formula (2n + 2

3 ) · 2n satisfies the given recurrence.

Some unanswered questions:

  • Why can we add the two solutions? That is, why is {an} = {a(p)

n } + {a(h) n }?

  • How did we guess (2n + 2

3) · 2n?

  • Does it depend on the function F(n)?

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-16
SLIDE 16

Non-Homogeneous Case

Why can we add the two solutions? That is, why is {an} = {a(p)

n } + {a(h) n }?

an = c1an−1 + c2an−2 + . . . + ckan−k + F(n)

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-17
SLIDE 17

Non-Homogeneous Case

Why can we add the two solutions? That is, why is {an} = {a(p)

n } + {a(h) n }?

an = c1an−1 + c2an−2 + . . . + ckan−k + F(n)

  • Let {a(p)

n } be some (guessed!) solution to the recurrence (not necessarily

satisfying base cases).

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-18
SLIDE 18

Non-Homogeneous Case

Why can we add the two solutions? That is, why is {an} = {a(p)

n } + {a(h) n }?

an = c1an−1 + c2an−2 + . . . + ckan−k + F(n)

  • Let {a(p)

n } be some (guessed!) solution to the recurrence (not necessarily

satisfying base cases).

  • Let {bn} be another solution to the recurrence.

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-19
SLIDE 19

Non-Homogeneous Case

Why can we add the two solutions? That is, why is {an} = {a(p)

n } + {a(h) n }?

an = c1an−1 + c2an−2 + . . . + ckan−k + F(n)

  • Let {a(p)

n } be some (guessed!) solution to the recurrence (not necessarily

satisfying base cases).

  • Let {bn} be another solution to the recurrence.
  • The difference {bn} − {a(p)

n } is a solution to the associated homogeneous

recurrence relation.

short justification: the term F(n) cancels out in the difference.

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-20
SLIDE 20

Non-Homogeneous Case

Why can we add the two solutions? That is, why is {an} = {a(p)

n } + {a(h) n }?

an = c1an−1 + c2an−2 + . . . + ckan−k + F(n)

  • Let {a(p)

n } be some (guessed!) solution to the recurrence (not necessarily

satisfying base cases).

  • Let {bn} be another solution to the recurrence.
  • The difference {bn} − {a(p)

n } is a solution to the associated homogeneous

recurrence relation.

short justification: the term F(n) cancels out in the difference.

See Theorem 5 and its proof in Section 8.2[KR].

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-21
SLIDE 21

Non-Homogeneous Case

an = c1an−1 + c2an−2 + . . . + ckan−k + F(n)

  • Let F(n) = q(n) · sn where q(n) is a polynomial of degree t and s is a

constant.

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-22
SLIDE 22

Non-Homogeneous Case

an = c1an−1 + c2an−2 + . . . + ckan−k + F(n)

  • Let F(n) = q(n) · sn where q(n) is a polynomial of degree t and s is a

constant.

Note that this is a specific type of F(n) that we are dealing with.

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-23
SLIDE 23

Non-Homogeneous Case

an = c1an−1 + c2an−2 + . . . + ckan−k + F(n)

  • Let F(n) = q(n) · sn where q(n) is a polynomial of degree t and s is a

constant.

Note that this is a specific type of F(n) that we are dealing with.

  • Solve the associated homogeneous part to get a general form.

Do not fix the constants α1, α2, . . .. Let r1, r2, . . . , rk be the roots of the charac. equation for the homogeneous part.

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-24
SLIDE 24

Non-Homogeneous Case

an = c1an−1 + c2an−2 + . . . + ckan−k + F(n)

  • Let F(n) = q(n) · sn where q(n) is a polynomial of degree t and s is a

constant.

Note that this is a specific type of F(n) that we are dealing with.

  • Solve the associated homogeneous part to get a general form.

Do not fix the constants α1, α2, . . .. Let r1, r2, . . . , rk be the roots of the charac. equation for the homogeneous part.

Two possibilities

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-25
SLIDE 25

Non-Homogeneous Case

an = c1an−1 + c2an−2 + . . . + ckan−k + F(n)

  • Let F(n) = q(n) · sn where q(n) is a polynomial of degree t and s is a

constant.

Note that this is a specific type of F(n) that we are dealing with.

  • Solve the associated homogeneous part to get a general form.

Do not fix the constants α1, α2, . . .. Let r1, r2, . . . , rk be the roots of the charac. equation for the homogeneous part.

Two possibilities Case 1: s is not one of the roots Guess {a(p)

n } =

(β0 + β1n + . . . + βtnt) ·sn Obtain the values for these βi, we show next how.

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-26
SLIDE 26

Non-Homogeneous Case

an = c1an−1 + c2an−2 + . . . + ckan−k + F(n)

  • Let F(n) = q(n) · sn where q(n) is a polynomial of degree t and s is a

constant.

Note that this is a specific type of F(n) that we are dealing with.

  • Solve the associated homogeneous part to get a general form.

Do not fix the constants α1, α2, . . .. Let r1, r2, . . . , rk be the roots of the charac. equation for the homogeneous part.

Two possibilities Case 1: s is not one of the roots Guess {a(p)

n } =

(β0 + β1n + . . . + βtnt) ·sn Obtain the values for these βi, we show next how. Case 2: s is one of the roots with multiplicity m Guess {a(p)

n } =

(β0 + β1n + . . . + βtnt) ·nmsn Obtain the values for these βi, we show next how.

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-27
SLIDE 27

Back to Example 1

an = 3 · n · 2n − an−1

  • The associated homogeneous recurrence an = −an−1 has a solution

r1 = −1.

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-28
SLIDE 28

Back to Example 1

an = 3 · n · 2n − an−1

  • The associated homogeneous recurrence an = −an−1 has a solution

r1 = −1.

  • F(n) = 3 · n · 2n, thus, q(n) = 3n and s = 2.

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-29
SLIDE 29

Back to Example 1

an = 3 · n · 2n − an−1

  • The associated homogeneous recurrence an = −an−1 has a solution

r1 = −1.

  • F(n) = 3 · n · 2n, thus, q(n) = 3n and s = 2.
  • Guess {a(p)

n } = (β0 + β1n) · 2n.

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-30
SLIDE 30

Back to Example 1

an = 3 · n · 2n − an−1

  • The associated homogeneous recurrence an = −an−1 has a solution

r1 = −1.

  • F(n) = 3 · n · 2n, thus, q(n) = 3n and s = 2.
  • Guess {a(p)

n } = (β0 + β1n) · 2n.

Since {a(p)

n } is a “guess” for the recurrence, we substitute it in the given

recurrence. an + an−1 = 3 · n · 2n

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-31
SLIDE 31

Back to Example 1

an = 3 · n · 2n − an−1

  • The associated homogeneous recurrence an = −an−1 has a solution

r1 = −1.

  • F(n) = 3 · n · 2n, thus, q(n) = 3n and s = 2.
  • Guess {a(p)

n } = (β0 + β1n) · 2n.

Since {a(p)

n } is a “guess” for the recurrence, we substitute it in the given

recurrence. an + an−1 = 3 · n · 2n (β0 + β1n) · 2n + (β0 + β1(n − 1)) · 2n−1 = 3 · n · 2n

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-32
SLIDE 32

Back to Example 1

an = 3 · n · 2n − an−1

  • The associated homogeneous recurrence an = −an−1 has a solution

r1 = −1.

  • F(n) = 3 · n · 2n, thus, q(n) = 3n and s = 2.
  • Guess {a(p)

n } = (β0 + β1n) · 2n.

Since {a(p)

n } is a “guess” for the recurrence, we substitute it in the given

recurrence. an + an−1 = 3 · n · 2n (β0 + β1n) · 2n + (β0 + β1(n − 1)) · 2n−1 = 3 · n · 2n 3 2β1n2n +

  • −1

2β1 + 3 2β0

  • · 2n

= 3 · n · 2n = ⇒ 3 2β1 = 3 and

  • −1

2β1 + 3 2β0

  • = 0

= ⇒ β1 = 2 and β0 = 2 3

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-33
SLIDE 33

Example 2

an = an−1 + an−2 + 3n + 1 a0 = 2; a1 = 3

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-34
SLIDE 34

Example 2

an = an−1 + an−2 + 3n + 1 a0 = 2; a1 = 3

  • The associated homogeneous recurrence is familiar fibonacci sequence.

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-35
SLIDE 35

Example 2

an = an−1 + an−2 + 3n + 1 a0 = 2; a1 = 3

  • The associated homogeneous recurrence is familiar fibonacci sequence.

a(h)

n

= α1 1 + √ 5 2 n + α2 1 − √ 5 2 n

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-36
SLIDE 36

Example 2

an = an−1 + an−2 + 3n + 1 a0 = 2; a1 = 3

  • The associated homogeneous recurrence is familiar fibonacci sequence.

a(h)

n

= α1 1 + √ 5 2 n + α2 1 − √ 5 2 n

  • F(n) = 3n + 1 = (3n + 1) · 1n. Thus q(n) = (3n + 1) and s = 1.

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-37
SLIDE 37

Example 2

an = an−1 + an−2 + 3n + 1 a0 = 2; a1 = 3

  • The associated homogeneous recurrence is familiar fibonacci sequence.

a(h)

n

= α1 1 + √ 5 2 n + α2 1 − √ 5 2 n

  • F(n) = 3n + 1 = (3n + 1) · 1n. Thus q(n) = (3n + 1) and s = 1.
  • Hence we fall in Case 1 and guess a(p)

n

= (β0 + β1n) · 1n.

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-38
SLIDE 38

Example 2

an = an−1 + an−2 + 3n + 1 a0 = 2; a1 = 3

  • The associated homogeneous recurrence is familiar fibonacci sequence.

a(h)

n

= α1 1 + √ 5 2 n + α2 1 − √ 5 2 n

  • F(n) = 3n + 1 = (3n + 1) · 1n. Thus q(n) = (3n + 1) and s = 1.
  • Hence we fall in Case 1 and guess a(p)

n

= (β0 + β1n) · 1n. (β0 + β1n) · 1n = (β0 + β1(n − 1)) · 1n−1 + (β0 + β1(n − 2)) · 1n−2 + 3n + 1 = (3 + β1)n + (β0 − 3β1 + 1)

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-39
SLIDE 39

Example 2

an = an−1 + an−2 + 3n + 1 a0 = 2; a1 = 3

  • The associated homogeneous recurrence is familiar fibonacci sequence.

a(h)

n

= α1 1 + √ 5 2 n + α2 1 − √ 5 2 n

  • F(n) = 3n + 1 = (3n + 1) · 1n. Thus q(n) = (3n + 1) and s = 1.
  • Hence we fall in Case 1 and guess a(p)

n

= (β0 + β1n) · 1n. (β0 + β1n) · 1n = (β0 + β1(n − 1)) · 1n−1 + (β0 + β1(n − 2)) · 1n−2 + 3n + 1 = (3 + β1)n + (β0 − 3β1 + 1)

  • This gives us β0 = −10 and β1 = −3.

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-40
SLIDE 40

Example 2

an = an−1 + an−2 + 3n + 1 a0 = 2; a1 = 3

  • The associated homogeneous recurrence is familiar fibonacci sequence.

a(h)

n

= α1 1 + √ 5 2 n + α2 1 − √ 5 2 n

  • F(n) = 3n + 1 = (3n + 1) · 1n. Thus q(n) = (3n + 1) and s = 1.
  • Hence we fall in Case 1 and guess a(p)

n

= (β0 + β1n) · 1n. (β0 + β1n) · 1n = (β0 + β1(n − 1)) · 1n−1 + (β0 + β1(n − 2)) · 1n−2 + 3n + 1 = (3 + β1)n + (β0 − 3β1 + 1)

  • This gives us β0 = −10 and β1 = −3.

Thus, an = −3n − 10 + α1 1 + √ 5 2 n + α2 1 − √ 5 2 n Use base cases to get α1 = 6 + 2 √ 5 and α2 = 6 − 2 √ 5

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-41
SLIDE 41

Example 3

an = 4an−1 − 4an−2 + (n + 1) · 2n a0 = 2; a1 = 3

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-42
SLIDE 42

Example 3

an = 4an−1 − 4an−2 + (n + 1) · 2n a0 = 2; a1 = 3

  • The associated homogeneous recurrence is an = 4an−1 + 4an−2 whose

characteristic equation has a single root r1 = 2 of multiplicity 2.

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-43
SLIDE 43

Example 3

an = 4an−1 − 4an−2 + (n + 1) · 2n a0 = 2; a1 = 3

  • The associated homogeneous recurrence is an = 4an−1 + 4an−2 whose

characteristic equation has a single root r1 = 2 of multiplicity 2. a(h)

n

= α1 · 2n + α2 · n · 2n

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-44
SLIDE 44

Example 3

an = 4an−1 − 4an−2 + (n + 1) · 2n a0 = 2; a1 = 3

  • The associated homogeneous recurrence is an = 4an−1 + 4an−2 whose

characteristic equation has a single root r1 = 2 of multiplicity 2. a(h)

n

= α1 · 2n + α2 · n · 2n

  • F(n) = (n + 1) · 2n, thus q(n) = (n + 1) and s = 2.

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-45
SLIDE 45

Example 3

an = 4an−1 − 4an−2 + (n + 1) · 2n a0 = 2; a1 = 3

  • The associated homogeneous recurrence is an = 4an−1 + 4an−2 whose

characteristic equation has a single root r1 = 2 of multiplicity 2. a(h)

n

= α1 · 2n + α2 · n · 2n

  • F(n) = (n + 1) · 2n, thus q(n) = (n + 1) and s = 2.
  • Hence we fall in Case 2 and guess a(p)

n

= (β0 + β1n) · n2 · 2n.

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-46
SLIDE 46

Example 3

an = 4an−1 − 4an−2 + (n + 1) · 2n a0 = 2; a1 = 3

  • The associated homogeneous recurrence is an = 4an−1 + 4an−2 whose

characteristic equation has a single root r1 = 2 of multiplicity 2. a(h)

n

= α1 · 2n + α2 · n · 2n

  • F(n) = (n + 1) · 2n, thus q(n) = (n + 1) and s = 2.
  • Hence we fall in Case 2 and guess a(p)

n

= (β0 + β1n) · n2 · 2n.

  • Substitute it in the recurrence to obtain β0 = 1 and β1 = 1

6.

Ex: Use base cases to compute α1 and α2.

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-47
SLIDE 47

Solving Recurrences: Summary

  • Repeated substitution method (applicable in general).

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-48
SLIDE 48

Solving Recurrences: Summary

  • Repeated substitution method (applicable in general).
  • A special case of recurrence relations: Linear recurrences with constant

coefficients. homogeneous and non-homogeneous cases.

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-49
SLIDE 49

Solving Recurrences: Summary

  • Repeated substitution method (applicable in general).
  • A special case of recurrence relations: Linear recurrences with constant

coefficients. homogeneous and non-homogeneous cases.

  • For the non-homogeneous case: dealt with restricted case of F(n).

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-50
SLIDE 50

Solving Recurrences: Summary

  • Repeated substitution method (applicable in general).
  • A special case of recurrence relations: Linear recurrences with constant

coefficients. homogeneous and non-homogeneous cases.

  • For the non-homogeneous case: dealt with restricted case of F(n).
  • Other methods: Master method (to deal with recurrences in divide and

conquer algorithms), generating functions.

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques

slide-51
SLIDE 51

Solving Recurrences: Summary

  • Repeated substitution method (applicable in general).
  • A special case of recurrence relations: Linear recurrences with constant

coefficients. homogeneous and non-homogeneous cases.

  • For the non-homogeneous case: dealt with restricted case of F(n).
  • Other methods: Master method (to deal with recurrences in divide and

conquer algorithms), generating functions.

  • Reference : Section 8.2 [KR]

CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques