Advanced Counting Techniques CSC2259 Discrete Structures Konstantin Busch
Advanced Counting Techniques CSC-2259 Discrete Structures Konstantin Busch - LSU 1
Recurrence Relations Sequence Recurrence relation: For any Konstantin Busch - LSU 2
Example: Recurrence relation Solutions to recurrence relation: Konstantin Busch - LSU 3
Example: $10, 000 bank deposit %11 interest : amount after years Konstantin Busch - LSU 4
Example: Fibonacci sequence Konstantin Busch - LSU 5
Example: bar 1 Towers of Hanoi bar 2 bar 3 discs Goal: move all discs to bar 3 Rule: not allowed to put larger discs on top of smaller discs Konstantin Busch - LSU 6
bar 1 bar 2 Step 1: move recursively Konstantin Busch - LSU bar 3 discs to bar 2 7
bar 1 bar 2 bar 3 Step 2: move largest disc to bar 3 Konstantin Busch - LSU 8
bar 1 Step 3: bar 2 move recursively Konstantin Busch - LSU bar 3 discs to bar 3 9
: total disc moves 2 recursive calls with discs (steps 1&3) movement of largest disc (step 2) one move for one disc Konstantin Busch - LSU 10
Konstantin Busch - LSU 11
Solving Linear Recurrence Relations Linear homogeneous recurrence relation of degree : Constant coefficients: Konstantin Busch - LSU 12
A sequence (solution) satisfying the relation is uniquely determined by the initial values: (these are different constants than the coefficients) Konstantin Busch - LSU 13
Solution to recurrence relation: if an only if divide both sides with characteristic equation Konstantin Busch - LSU 14
characteristic equation: factorize with roots characteristic roots: Multiple possible solutions: Konstantin Busch - LSU 15
The solutions may not satisfy the initial conditions Konstantin Busch - LSU 16
Theorem: Recurrence relation of degree 2 has unique solution where are solutions to the characteristic equation, and are constants that depend on initial conditions Konstantin Busch - LSU 17
Proof: Characteristic Equation Roots: Konstantin Busch - LSU 18
First compute from initial conditions Konstantin Busch - LSU 19
Konstantin Busch - LSU 20
Prove by induction that Basis cases: true for the specific choices of Konstantin Busch - LSU 21
Inductive hypothesis: assume that for all Inductive step: prove that for Konstantin Busch - LSU 22
By (strong) inductive hypothesis: Konstantin Busch - LSU 23
By recurrence relation definition Inductive hypothesis characteristic equations End of Proof Konstantin Busch - LSU 24
Example: Fibonacci sequence Has solution: Characteristic roots: Konstantin Busch - LSU 25
Konstantin Busch - LSU 26
Konstantin Busch - LSU 27
Degree recurrence relation: has unique solution where are solutions to the characteristic equation, and are constants that depend on initial conditions Konstantin Busch - LSU 28
Example: Solution: Characteristic equation: Roots: Konstantin Busch - LSU 29
Final solution: Konstantin Busch - LSU 30
Recurrence Relations for Divide and Conquer Algorithms Typical divide and conquer algorithm: • Input of size • Divide into sub-problems each of size • Combine sub-problems with cost Konstantin Busch - LSU 31
Divide an conquer recurrence relation: Cost of subproblem of size Konstantin Busch - LSU 32
Examples: Binary search: Merge Sort: Fast Matrix Multiplication (Stassen’s Alg. ): Konstantin Busch - LSU 33
Theorem: if then Konstantin Busch - LSU 34
Proof: Konstantin Busch - LSU 35
Konstantin Busch - LSU 36
End of Proof Konstantin Busch - LSU 37
Theorem: if then Konstantin Busch - LSU 38
Proof: From previous theorem Konstantin Busch - LSU 39
Case: Konstantin Busch - LSU 40
Case: End of Proof Konstantin Busch - LSU 41
Example: Binary search: Konstantin Busch - LSU 42
Master Theorem: if then Konstantin Busch - LSU 43
Example: Merge Sort: Konstantin Busch - LSU 44
Example: Fast Matrix Multiplication (Stassen’s Alg. ): Konstantin Busch - LSU 45
Generating Functions Find number of solutions for: Answer: Konstantin Busch - LSU 46
Alternative solution choices for Konstantin Busch - LSU choices for 47
Alternative solution is the total number of solutions to equation Konstantin Busch - LSU 48
Another problem: Find total number of solutions which satisfy: Konstantin Busch - LSU 49
Alternative solution choices for Konstantin Busch - LSU choices for 50
Alternative solution is the total number of solutions to equation Konstantin Busch - LSU 51
Generating function: generating function for sequence Konstantin Busch - LSU 52
Generating functions can also be used to solve recurrence relations Example: Solve recurrence relation Konstantin Busch - LSU 53
Let be the generating function for sequence Konstantin Busch - LSU 54
Konstantin Busch - LSU 55
Konstantin Busch - LSU 56
Konstantin Busch - LSU 57
Konstantin Busch - LSU 58
Solution to recurrence relation Konstantin Busch - LSU 59
Inclusion-Exclusion Konstantin Busch - LSU 60
Konstantin Busch - LSU 61
Principle of Inclusion-Exclusion: Konstantin Busch - LSU 62
Proof: We want to prove that: an arbitrary element is counted exactly one time in the expression of theorem Konstantin Busch - LSU 63
Suppose Then is a member of exactly sets: is counted in the terms: Konstantin Busch - LSU 64
In sum: is counted (since times belongs exactly to Konstantin Busch - LSU sets) 65
In sum: is counted (since times belongs exactly to Konstantin Busch - LSU sets) 66
In sum: is counted (since times belongs exactly to Konstantin Busch - LSU sets) 67
In sum: is counted (since times belongs exactly to Konstantin Busch - LSU sets) 68
Thus, in the expression of theorem is counted so many times: Konstantin Busch - LSU 69
From binomial expansion we have that: Thus, is counted exactly one time End of Proof Konstantin Busch - LSU 70
Example: Find the number of primes between 1… 100 If a number is composite and between 1… 100 then it must be divided by a prime which is at most : 2, 3, 5, 7 Konstantin Busch - LSU 71
: the set of primes between 1… 100 : the set of composites between 1… 100 : composites between 1… 100 divided by 2 : composites between 1… 100 divided by 3 : composites between 1… 100 divided by 5 : composites between 1… 100 divided by 7 Konstantin Busch - LSU 72
From the principle of inclusion-exclusion: Konstantin Busch - LSU 73
Konstantin Busch - LSU 74
Number of primes between 1… 100: Konstantin Busch - LSU 75
Dearrangements: given some ordered list, permutations that have no item in original position Example: 12345 Dearrangements: 51234 35412 21453 Konstantin Busch - LSU 76
Theorem: Given a list with elements, the number of dearrangements are Konstantin Busch - LSU 77
: set of all permutations : permutations which fix position Konstantin Busch - LSU 78
- Slides: 78