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 applications � • Solving Recurrences CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques
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
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
Example 1 a n = 3 · n · 2 n − a n − 1 • This is a non-homogeneous linear recurrence with constant coefficients. The presence of the term F ( n ) = 3 · n · 2 n makes it non-homogeneous. CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques
Example 1 a n = 3 · n · 2 n − a n − 1 • This is a non-homogeneous linear recurrence with constant coefficients. The presence of the term F ( n ) = 3 · n · 2 n makes it non-homogeneous. • The recurrence a n = − a n − 1 is the “associated homogeneous recurrence” . We know the general form for the solution : CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques
Example 1 a n = 3 · n · 2 n − a n − 1 • This is a non-homogeneous linear recurrence with constant coefficients. The presence of the term F ( n ) = 3 · n · 2 n makes it non-homogeneous. • The recurrence a n = − a n − 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
Example 1 a n = 3 · n · 2 n − a n − 1 • This is a non-homogeneous linear recurrence with constant coefficients. The presence of the term F ( n ) = 3 · n · 2 n makes it non-homogeneous. • The recurrence a n = − a n − 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
Example 1 a n = 3 · n · 2 n − a n − 1 • This is a non-homogeneous linear recurrence with constant coefficients. The presence of the term F ( n ) = 3 · n · 2 n makes it non-homogeneous. • The recurrence a n = − a n − 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
Example 1 a n = 3 · n · 2 n − a n − 1 • This is a non-homogeneous linear recurrence with constant coefficients. The presence of the term F ( n ) = 3 · n · 2 n makes it non-homogeneous. • The recurrence a n = − a n − 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. 3 ) · 2 n satisfies the given recurrence. In the example, the formula (2 n + 2 CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques
Example 1 a n = 3 · n · 2 n − a n − 1 • This is a non-homogeneous linear recurrence with constant coefficients. The presence of the term F ( n ) = 3 · n · 2 n makes it non-homogeneous. • The recurrence a n = − a n − 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. 3 ) · 2 n satisfies the given recurrence. In the example, the formula (2 n + 2 Then the solution to the given recurrence is of the form { a ( p ) n } + { a ( h ) { a n } = n } CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques
Example 1 a n = 3 · n · 2 n − a n − 1 • This is a non-homogeneous linear recurrence with constant coefficients. The presence of the term F ( n ) = 3 · n · 2 n makes it non-homogeneous. • The recurrence a n = − a n − 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. 3 ) · 2 n satisfies the given recurrence. In the example, the formula (2 n + 2 Then the solution to the given recurrence is of the form { a ( p ) n } + { a ( h ) { a n } = n } � 2 n + 2 � · 2 n + α 1 ( − 1) n = 3 CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques
Example 1 a n = 3 · n · 2 n − a n − 1 • This is a non-homogeneous linear recurrence with constant coefficients. The presence of the term F ( n ) = 3 · n · 2 n makes it non-homogeneous. • The recurrence a n = − a n − 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. 3 ) · 2 n satisfies the given recurrence. In the example, the formula (2 n + 2 Then the solution to the given recurrence is of the form { a ( p ) n } + { a ( h ) { a n } = n } � 2 n + 2 � · 2 n + α 1 ( − 1) n = 3 If base case is a 1 = 1 we get α 1 = 13 3 . Check out the formula works! CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques
Example 1 continued a n = 3 · n · 2 n − a n − 1 • This is a non-homogeneous linear recurrence with constant coefficients. The presence of the term F ( n ) = 3 · n · 2 n makes it non-homogeneous. • The recurrence a n = − a n − 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. 3 ) · 2 n satisfies the given recurrence. In the example, the formula (2 n + 2 CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques
Example 1 continued a n = 3 · n · 2 n − a n − 1 • This is a non-homogeneous linear recurrence with constant coefficients. The presence of the term F ( n ) = 3 · n · 2 n makes it non-homogeneous. • The recurrence a n = − a n − 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. 3 ) · 2 n satisfies the given recurrence. In the example, the formula (2 n + 2 Some unanswered questions: • Why can we add the two solutions? That is, why is { a n } = { a ( p ) n } + { a ( h ) n } ? • How did we guess (2 n + 2 3 ) · 2 n ? • Does it depend on the function F ( n )? CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques
Non-Homogeneous Case Why can we add the two solutions? That is, why is { a n } = { a ( p ) n } + { a ( h ) n } ? a n = c 1 a n − 1 + c 2 a n − 2 + . . . + c k a n − k + F ( n ) CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques
Non-Homogeneous Case Why can we add the two solutions? That is, why is { a n } = { a ( p ) n } + { a ( h ) n } ? a n = c 1 a n − 1 + c 2 a n − 2 + . . . + c k a n − 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
Non-Homogeneous Case Why can we add the two solutions? That is, why is { a n } = { a ( p ) n } + { a ( h ) n } ? a n = c 1 a n − 1 + c 2 a n − 2 + . . . + c k a n − k + F ( n ) • Let { a ( p ) n } be some (guessed!) solution to the recurrence (not necessarily satisfying base cases). • Let { b n } be another solution to the recurrence. CS1200, CSE IIT Madras Meghana Nasre Advanced Counting Techniques
Recommend
More recommend