6. Counting

Counting problems arise throughout mathematics and computer science. In CS, we need to measure the time complexity of given algorithms, and know the number of passwords of a computer system and so on.

6.1 The Basics of Counting

6.1.1 Basic Counting Principles

**The Product Rule**
Suppose that a procedure can be broken down into two tasks. If there are 离散数学及其应用 第6、8章 组合 - 图1 ways to do the first task and 离散数学及其应用 第6、8章 组合 - 图2 ways to do the second after the first task has been done, then there are 离散数学及其应用 第6、8章 组合 - 图3 ways to complete the procedure.
In terms of sets, if 离散数学及其应用 第6、8章 组合 - 图4 are finite sets, then the number of elements in the Cartesian product of these sets is the product of the number of elements of each set. The task of choosing an element in the Cartesian product 离散数学及其应用 第6、8章 组合 - 图5 is done by choosing an element in 离散数学及其应用 第6、8章 组合 - 图6, an element in 离散数学及其应用 第6、8章 组合 - 图7 , … , and an element in 离散数学及其应用 第6、8章 组合 - 图8. By the product rule, it follows that 离散数学及其应用 第6、8章 组合 - 图9
**The Sum Rule**
If a task can be done either in one of 离散数学及其应用 第6、8章 组合 - 图10 ways or in one of 离散数学及其应用 第6、8章 组合 - 图11 ways, where none of the set of 离散数学及其应用 第6、8章 组合 - 图12 ways is the same as any of the set of 离散数学及其应用 第6、8章 组合 - 图13 ways, then there are 离散数学及其应用 第6、8章 组合 - 图14 ways to do the tasks.
In terms of sets, 离散数学及其应用 第6、8章 组合 - 图15 where 离散数学及其应用 第6、8章 组合 - 图16 for all 离散数学及其应用 第6、8章 组合 - 图17.
**The Subtraction Rule**
If a task can be done in either 离散数学及其应用 第6、8章 组合 - 图18 ways or 离散数学及其应用 第6、8章 组合 - 图19 ways, then the number of ways to do the task in 离散数学及其应用 第6、8章 组合 - 图20 minus the number of ways to do the task that are common to the two different ways. The subtraction rule is also known as the principle of inclusion-exclusion.
**The Division Rule**
There are 离散数学及其应用 第6、8章 组合 - 图21 ways to do a task if it can be done using a procedure that can be carried out in 离散数学及其应用 第6、8章 组合 - 图22 ways, and for every way 离散数学及其应用 第6、8章 组合 - 图23, exactly 离散数学及其应用 第6、8章 组合 - 图24 of the 离散数学及其应用 第6、8章 组合 - 图25 ways correspond to way 离散数学及其应用 第6、8章 组合 - 图26.
Restated in terms of sets: If the finite set 离散数学及其应用 第6、8章 组合 - 图27 is the union of 离散数学及其应用 第6、8章 组合 - 图28 pairwise disjoint subsets each with 离散数学及其应用 第6、8章 组合 - 图29 elements, then 离散数学及其应用 第6、8章 组合 - 图30.
In terms of functions: If 离散数学及其应用 第6、8章 组合 - 图31 is a function from 离散数学及其应用 第6、8章 组合 - 图32 to 离散数学及其应用 第6、8章 组合 - 图33, where both are finite sets, and for every value 离散数学及其应用 第6、8章 组合 - 图34 there are exactly 离散数学及其应用 第6、8章 组合 - 图35 values 离散数学及其应用 第6、8章 组合 - 图36 such that 离散数学及其应用 第6、8章 组合 - 图37, then 离散数学及其应用 第6、8章 组合 - 图38.
🌰 e.g.
How many ways are there to seat four people around a circular table, where two seatings are considered the same when each person has the same left and right neighbor?
Solution:
Number the seats around the table from 1 to 4 proceeding clockwise. There are four ways to select the person for seat 1, three for seat 2, two for seat 3, and one way for seat 4. Thus there are 4! = 24 ways to order the four people. But since two seatings are the same when each person has the same left and right neighbor, for every choice for seat 1, we get the same seating. Therefore, by the division rule, there are 24/4 = 6 different seating arrangements.

6.1.2 Tree Diagrams

We can solve many counting problems through the use of tree diagrams, where a branch represents a possible choice and the leaves represent possible outcomes.
image.png

6.2 The Pigeonhole Principle

📋The Pigeonhole Principle (Also called Dirichlet Drawer Principle)
If 离散数学及其应用 第6、8章 组合 - 图40 is a positive integer and 离散数学及其应用 第6、8章 组合 - 图41 or more objects are placed into 离散数学及其应用 第6、8章 组合 - 图42 boxes, then there is at least one box containing two or more of the objects.
Proof:
We use a proof by contraposition. Suppose none of the 离散数学及其应用 第6、8章 组合 - 图43 boxes has more than one object. Then the total number of objects would be at most 离散数学及其应用 第6、8章 组合 - 图44. This contradicts the statement that we have 离散数学及其应用 第6、8章 组合 - 图45 objects.
🌰e.g.
In a party of 2 or more people, there are 2 people with the same number of friends in the party, assuming you can’t be your own friend and that friendship is mutual.
Pigeons : the 离散数学及其应用 第6、8章 组合 - 图46 people (with 离散数学及其应用 第6、8章 组合 - 图47).
Pigeonholes: the possible number of friends, i.e. the set 离散数学及其应用 第6、8章 组合 - 图48
🌰e.g.
Show that for every integer 离散数学及其应用 第6、8章 组合 - 图49 there is a multiple of 离散数学及其应用 第6、8章 组合 - 图50 that has only 0s and 1s in its decimal expansion.
Solution:
Let 离散数学及其应用 第6、8章 组合 - 图51 be a positive integer. Consider the 离散数学及其应用 第6、8章 组合 - 图52 integers 1, 11, 111, … , 11…1 (where the last has 离散数学及其应用 第6、8章 组合 - 图53 1s). There are 离散数学及其应用 第6、8章 组合 - 图54 possible remainders when an integer is divided by 离散数学及其应用 第6、8章 组合 - 图55.
By the pigeonhole principle, when each of the 离散数学及其应用 第6、8章 组合 - 图56 integers is divided by 离散数学及其应用 第6、8章 组合 - 图57, at least two must have the same remainder. Subtract the smaller from the larger and the result is a multiple of 离散数学及其应用 第6、8章 组合 - 图58 that has only 0s and 1s in its decimal expansion.
📋The Generalized Pigeonhole Principle
If 离散数学及其应用 第6、8章 组合 - 图59 objects are placed into 离散数学及其应用 第6、8章 组合 - 图60 boxes, then there is at least one box containing at least 离散数学及其应用 第6、8章 组合 - 图61 objects.
Proof:
Suppose that none of the boxes contains more than 离散数学及其应用 第6、8章 组合 - 图62 objects. Then, the total number of objects is at most 离散数学及其应用 第6、8章 组合 - 图63.
🌰e.g.
Show that among any 离散数学及其应用 第6、8章 组合 - 图64 positive integers not exceeding 离散数学及其应用 第6、8章 组合 - 图65 there must be an integer that divides one of the other integers.
Solution:
image.png
🌰e.g.
During 11 weeks football games will be held at least 1 game a day, but at most 12 games be arranged each week. Show that there must be a period of some number of consecutive days during which exactly 21 games must be played.
Solution:
Let xi be the number of football games helded on the i-th day.
Let 离散数学及其应用 第6、8章 组合 - 图67 be 离散数学及其应用 第6、8章 组合 - 图68, where离散数学及其应用 第6、8章 组合 - 图69
Let 离散数学及其应用 第6、8章 组合 - 图70 be离散数学及其应用 第6、8章 组合 - 图71, so 离散数学及其应用 第6、8章 组合 - 图72
离散数学及其应用 第6、8章 组合 - 图73,离散数学及其应用 第6、8章 组合 - 图74
Since离散数学及其应用 第6、8章 组合 - 图75, there exist integers离散数学及其应用 第6、8章 组合 - 图76that 离散数学及其应用 第6、8章 组合 - 图77
So 离散数学及其应用 第6、8章 组合 - 图78
🌰e.g.
Every sequence of 离散数学及其应用 第6、8章 组合 - 图79 distinct integers contains a subsequence of length 离散数学及其应用 第6、8章 组合 - 图80 that is either strictly increasing or strictly decreasing.
Proof:
image.png
image.png
🌰e.g.

6.3 Permutations and Combinations

💡这一节基本是高中排列组合的知识。

6.3.1 Basic Concepts

**Permutation** An ordered arrangement of the elements of a set.
**r-Permutation** An ordered arrangement of 离散数学及其应用 第6、8章 组合 - 图83 elements of a set
📋The number of r-permutations of a set with 离散数学及其应用 第6、8章 组合 - 图84 distinct elements is离散数学及其应用 第6、8章 组合 - 图85
Specially, 离散数学及其应用 第6、8章 组合 - 图86, 离散数学及其应用 第6、8章 组合 - 图87.
**r-Combination** An unordered selection of 离散数学及其应用 第6、8章 组合 - 图88 elements of a set. An r-combination is simply a subset of a set with 离散数学及其应用 第6、8章 组合 - 图89 elements.
📋The number of r-combination of a set with 离散数学及其应用 第6、8章 组合 - 图90 elements, where 离散数学及其应用 第6、8章 组合 - 图91 is a positive integer and 离散数学及其应用 第6、8章 组合 - 图92 is an integer with 离散数学及其应用 第6、8章 组合 - 图93, denoted by 离散数学及其应用 第6、8章 组合 - 图94, equals to 离散数学及其应用 第6、8章 组合 - 图95
📋Combination Corollary
Let 离散数学及其应用 第6、8章 组合 - 图96 and 离散数学及其应用 第6、8章 组合 - 图97 be nonnegative integers with 离散数学及其应用 第6、8章 组合 - 图98. Then 离散数学及其应用 第6、8章 组合 - 图99

6.3.2 Combinatorial Proof

A **combinatorial proof** of an identity:

  • **Double Counting Proofs** Uses counting arguments to prove that both sides of the identity count the same objects but in different ways.
  • **Bijective Proofs** Show that there is a bijection between the sets of objects counted by the two sides of the identity.

    6.4 Binomial Coefficients

    💡二项式定理也是高中就学了的。
    A **binomial expression** is the sum of two terms, such as 离散数学及其应用 第6、8章 组合 - 图100. (More generally, these
    terms can be products of constants and variables.)
    📋The Binomial Theorem
    Let 离散数学及其应用 第6、8章 组合 - 图101 and 离散数学及其应用 第6、8章 组合 - 图102 be varaibles, and let 离散数学及其应用 第6、8章 组合 - 图103 be a nonnegative integer. Then 离散数学及其应用 第6、8章 组合 - 图104.
    Proof:
    We can use counting principles to find the coefficients in the expansion of 离散数学及其应用 第6、8章 组合 - 图105. To form the term 离散数学及其应用 第6、8章 组合 - 图106, it is necessary to choose 离散数学及其应用 第6、8章 组合 - 图107离散数学及其应用 第6、8章 组合 - 图108s and 离散数学及其应用 第6、8章 组合 - 图109离散数学及其应用 第6、8章 组合 - 图110s from the 离散数学及其应用 第6、8章 组合 - 图111 sums.
    📋Corrolaries for the Binomial Theorem
    离散数学及其应用 第6、8章 组合 - 图112, 离散数学及其应用 第6、8章 组合 - 图113, 离散数学及其应用 第6、8章 组合 - 图114
    📋Pascal’s Identity
    Let 离散数学及其应用 第6、8章 组合 - 图115 and 离散数学及其应用 第6、8章 组合 - 图116 be positive integers with 离散数学及其应用 第6、8章 组合 - 图117. Then 离散数学及其应用 第6、8章 组合 - 图118.
    Proof:
    We construct a subset of size 离散数学及其应用 第6、8章 组合 - 图119 form a set 离散数学及其应用 第6、8章 组合 - 图120 with 离散数学及其应用 第6、8章 组合 - 图121 elements. The total will include:
    All of the subsets from the set of size 离散数学及其应用 第6、8章 组合 - 图122 which do not contain the element 离散数学及其应用 第6、8章 组合 - 图123, 离散数学及其应用 第6、8章 组合 - 图124, plus the subsets of size 离散数学及其应用 第6、8章 组合 - 图125 with the element 离散数学及其应用 第6、8章 组合 - 图126 added 离散数学及其应用 第6、8章 组合 - 图127.
    📋Pascal’s Triangle
    image.png
    The nth row in the triangle consists of the binomial coefficients 离散数学及其应用 第6、8章 组合 - 图129. By Pascal’s identity, adding two adjacent bionomial coefficients results is the binomial coefficient in the next row between these two coefficients.
    📋Vandermonde’s Identity
    Let 离散数学及其应用 第6、8章 组合 - 图130, 离散数学及其应用 第6、8章 组合 - 图131 and 离散数学及其应用 第6、8章 组合 - 图132 be nonnegative integer with 离散数学及其应用 第6、8章 组合 - 图133 not exceeding either 离散数学及其应用 第6、8章 组合 - 图134 or 离散数学及其应用 第6、8章 组合 - 图135. Then 离散数学及其应用 第6、8章 组合 - 图136.
    📋If 离散数学及其应用 第6、8章 组合 - 图137 is a nonnegative integer. Then 离散数学及其应用 第6、8章 组合 - 图138.
    Proof:
    We use Vandermonde’s Identity with离散数学及其应用 第6、8章 组合 - 图139 to obtain 离散数学及其应用 第6、8章 组合 - 图140.
    📋Let 离散数学及其应用 第6、8章 组合 - 图141 and 离散数学及其应用 第6、8章 组合 - 图142 be nonnegative integer with 离散数学及其应用 第6、8章 组合 - 图143, then离散数学及其应用 第6、8章 组合 - 图144.
    Proof:
    The left-hand side counts the bit strings of length 离散数学及其应用 第6、8章 组合 - 图145 containing 离散数学及其应用 第6、8章 组合 - 图146 1s. We show that the right-hand side counts the same objects by considering the cases corresponding to the possible locations of the final 1 in a string with 离散数学及其应用 第6、8章 组合 - 图147 ones.

    6.5 Generalized Permutations and Combinations

    6.5.1 Permutations and Combinations with Repetition

    📋The number of r-permutations of a set of 离散数学及其应用 第6、8章 组合 - 图148 objects with repetition allowed is 离散数学及其应用 第6、8章 组合 - 图149.
    📋There are 离散数学及其应用 第6、8章 组合 - 图150 r-combination from a set with 离散数学及其应用 第6、8章 组合 - 图151 elements when repetition of elements is allowed.
    Proof:
  1. The 离散数学及其应用 第6、8章 组合 - 图152 bars are used to mark off 离散数学及其应用 第6、8章 组合 - 图153 different cells, with the ith cell contains a star for each time the ith element of the set occurs in the combination. For example, | | | | * means the first element occurs twice, the second element occurs once, the fourth element occurs once, and the fifth element occurs three times.
  2. Each r-combination of a set with n elements when repetition is allowed can be represented by a list of 离散数学及其应用 第6、8章 组合 - 图154 bars and 离散数学及其应用 第6、8章 组合 - 图155 stars.
  3. The number of such lists is 离散数学及其应用 第6、8章 组合 - 图156.

🌰e.g.
How many solutions are there to the equation 离散数学及其应用 第6、8章 组合 - 图157 where 离散数学及其应用 第6、8章 组合 - 图158 is nonnegative integer?
Solution:
Since a solution of this equation corresponds to a way of selecting 16 items from a set with four element, such that 离散数学及其应用 第6、8章 组合 - 图159 items of type one, 离散数学及其应用 第6、8章 组合 - 图160 items of type two, 离散数学及其应用 第6、8章 组合 - 图161 items of type three, 离散数学及其应用 第6、8章 组合 - 图162 items of type four are chosen.
Hence the number of solutions is 离散数学及其应用 第6、8章 组合 - 图163.
How about the number of solutions to 离散数学及其应用 第6、8章 组合 - 图164?
Solution:
We can introduce an auxiliary variable 离散数学及其应用 第6、8章 组合 - 图165 so that 离散数学及其应用 第6、8章 组合 - 图166.
离散数学及其应用 第6、8章 组合 - 图167.

6.5.2 Permutations with Indistinguishable Objects

📋The number of different permutations of 离散数学及其应用 第6、8章 组合 - 图168 objects, 离散数学及其应用 第6、8章 组合 - 图169, where there are 离散数学及其应用 第6、8章 组合 - 图170 indistinguishable objects of type 1, … ,and 离散数学及其应用 第6、8章 组合 - 图171 indistinguishable objects of type k, is 离散数学及其应用 第6、8章 组合 - 图172.
Proof:
离散数学及其应用 第6、8章 组合 - 图173
🌰e.g.
How many different strings can be made form the letters in MISSISSIPPI, using all the letters?
Solution:
离散数学及其应用 第6、8章 组合 - 图174, so there are 离散数学及其应用 第6、8章 组合 - 图175 different strings.

6.5.3 Distributing Objects into Boxes

Many counting problems can be solved by counting the ways objects can be placed in boxes. The objects may be either different from each other (distinguishable) or identical (indistinguishable). The boxes may be labeled (distinguishable) or unlabeled (indistinguishable).
📋The number of ways to distribute 离散数学及其应用 第6、8章 组合 - 图176 distinguishable objects into 离散数学及其应用 第6、8章 组合 - 图177 distinguishable boxes so that 离散数学及其应用 第6、8章 组合 - 图178 objects are place into box i, i=1,2,…,k, equals 离散数学及其应用 第6、8章 组合 - 图179.
It can be proved by setting up a one-to-one correspondence between the permutations in the last theorem and the ways to distribute objects counted here.
🌰e.g.
How many ways are there to distribute hands of 5 cards to each of four players from the standard deck of 52 cards?
Solution:
It is typical problem that involves distributing distinguishable objects into distinguishable boxes.
The distinguishable objects are the 52 cards.
The five distinguishable boxes are the hands of the four players and the rest of the deck.
So there are 离散数学及其应用 第6、8章 组合 - 图180 kinds of distribution.
📋There are 离散数学及其应用 第6、8章 组合 - 图181 ways to place 离散数学及其应用 第6、8章 组合 - 图182 indistinguishable objects into 离散数学及其应用 第6、8章 组合 - 图183 distinguishable boxes.
Proof based on one-to-one correspondence between k-combinations from a set with n-elements when repetition is allowed and the ways to place 离散数学及其应用 第6、8章 组合 - 图184 indistinguishable objects into 离散数学及其应用 第6、8章 组合 - 图185 distinguishable boxes.
📋Stirling Numbers(斯特林数) of the Second Kind
离散数学及其应用 第6、8章 组合 - 图186, the number of ways to distribute 离散数学及其应用 第6、8章 组合 - 图187 distinguishable objects into 离散数学及其应用 第6、8章 组合 - 图188 indistinguishable boxes so that no boxes is empty.

  • 离散数学及其应用 第6、8章 组合 - 图189
  • 离散数学及其应用 第6、8章 组合 - 图190
  • 离散数学及其应用 第6、8章 组合 - 图191
  • 离散数学及其应用 第6、8章 组合 - 图192
  • 离散数学及其应用 第6、8章 组合 - 图193 is the number of ways to partition the set with nelements into 离散数学及其应用 第6、8章 组合 - 图194 nonempty and disjoint subsets.
  • 离散数学及其应用 第6、8章 组合 - 图195 is the number of ways to distribute 离散数学及其应用 第6、8章 组合 - 图196 distinguishable objects into 离散数学及其应用 第6、8章 组合 - 图197 distinguishable boxes so that no boxes is empty.
  • 离散数学及其应用 第6、8章 组合 - 图198 is the number of ways to place 离散数学及其应用 第6、8章 组合 - 图199 distinguishable objects into 离散数学及其应用 第6、8章 组合 - 图200 indistinguishable boxes.

    6.6 Generating Permutations and Combinations

    **Lexicographic Ordering for Permutations** The permutation 离散数学及其应用 第6、8章 组合 - 图201 precedes the permutation of 离散数学及其应用 第6、8章 组合 - 图202, if for some 离散数学及其应用 第6、8章 组合 - 图203, with 离散数学及其应用 第6、8章 组合 - 图204, 离散数学及其应用 第6、8章 组合 - 图205, and 离散数学及其应用 第6、8章 组合 - 图206.
    📋Generating All the Permutations
  1. List the elements in lexicographic order.
  2. Find the least permutation.
  3. Find the next least permutation until the largest permutation is found.

🌰e.g.
Algorithm of producing the 离散数学及其应用 第6、8章 组合 - 图207 permutations of the integers 离散数学及其应用 第6、8章 组合 - 图208.

  1. Begin with the smallest permutation in lexicographic order, namely 离散数学及其应用 第6、8章 组合 - 图209.
  2. Produce the next largest permutation.
  3. Continue until all 离散数学及其应用 第6、8章 组合 - 图210 permutations have been found.

📋Generating All the Combinations

  1. A combination is just a subset, so we need to list all subsets of the finite set.
  2. Use bit strings of length 离散数学及其应用 第6、8章 组合 - 图211 to represent a subset of a set with 离散数学及其应用 第6、8章 组合 - 图212 elements. If the subset contains the ith element, then the ith bit of the string is 1; otherwise the ith bit is 0.
  3. The 离散数学及其应用 第6、8章 组合 - 图213 bit strings can be listed in order of their increasing size as integers in their binary expansions.

    8. Advanced Counting Techniques

    8.1 Applications of Recurrence Relations

    A **recurrence relation** for the sequence 离散数学及其应用 第6、8章 组合 - 图214 is an equation that express 离散数学及其应用 第6、8章 组合 - 图215 in terms of one or more of the previous terms of the sequence, namely, 离散数学及其应用 第6、8章 组合 - 图216, for all integers 离散数学及其应用 第6、8章 组合 - 图217 with 离散数学及其应用 第6、8章 组合 - 图218, where 离散数学及其应用 第6、8章 组合 - 图219 is a nonnegative integers. 离散数学及其应用 第6、8章 组合 - 图220
    A **solution** of a recurrence relation is a sequence if its terms satisfy the recurrence relation. Normally, there are many sequences which satisfy a recurrence relation. We should distinguish them by initial conditions.
    The **degree** of a recurrence relation is the number of initial conditions it needs to determine a specific sequence. For example, 离散数学及其应用 第6、8章 组合 - 图221 is a recurrence relation of degree 8.
    💡Many relationships are most easily described using recurrence relations.
    🌰e.g.
    Find a recurrence relation for the number of bit strings of length 离散数学及其应用 第6、8章 组合 - 图222 that don’t have two consecutive 0s.
    Solution:
    Let 离散数学及其应用 第6、8章 组合 - 图223 denote the number of bit strings of length 离散数学及其应用 第6、8章 组合 - 图224 that don’t have two consecutive 0s.
    image.png
    Recurrence relation: 离散数学及其应用 第6、8章 组合 - 图226.
    Initial conditions: 离散数学及其应用 第6、8章 组合 - 图227.
    Note that 离散数学及其应用 第6、8章 组合 - 图228 satisfies the same recurrence relation as the Fibonacci sequence. Since 离散数学及其应用 第6、8章 组合 - 图229 and 离散数学及其应用 第6、8章 组合 - 图230, we conclude that 离散数学及其应用 第6、8章 组合 - 图231.
    ⚙️ Recurrence relations play an important role in many aspects of the study of algorithms and their complexity.
  • Dynamic programming algorithm
    • An algorithm follows the dynamic programming paradigm when it recursively breaks down a problem into simpler overlapping subproblems, and computes the solution using the solutions of the subproblems.
    • Recurrence relations are used to find the overall solution from the solutions of the subproblems.
  • Divide-and-conquer algorithm
    • Recurrence relations can be used to analyze the complexity of divide-and-conquer algorithms.

      8.2 Solving Linear Recurrence Relations

      8.2.1 Linear Homogeneous Recurrence Relations

      线性齐次常系数递推关系

离散数学及其应用 第6、8章 组合 - 图232 where 离散数学及其应用 第6、8章 组合 - 图233 are real numbers, and 离散数学及其应用 第6、8章 组合 - 图234.
**Linear**: The right-hand side is a sum of the previous terms of the sequence each multiplied by a
function of 离散数学及其应用 第6、8章 组合 - 图235.
**Constant Coefficients**: The coefficients in the sum of the 离散数学及其应用 第6、8章 组合 - 图236s are constants, independent of 离散数学及其应用 第6、8章 组合 - 图237.
**Degree**: 离散数学及其应用 第6、8章 组合 - 图238 is expressed in terms of the previous 离散数学及其应用 第6、8章 组合 - 图239 terms of the sequence. By strong induction, a sequence satisfying such a recurrence relation is uniquely determined by the recurrence relation and the 离散数学及其应用 第6、8章 组合 - 图240 initial conditions 离散数学及其应用 第6、8章 组合 - 图241.
**Homogeneous**: Because no terms occur that are not multiples of the 离散数学及其应用 第6、8章 组合 - 图242s. Otherwise **inhomogeneous** or **nonhomogeneous**.
📋 Solving Linear Homogeneous Recurrence Relation with Constant Coefficients
离散数学及其应用 第6、8章 组合 - 图243
Two key ideas to find all their solutions:

  1. These recurrence relations have solutions of the form 离散数学及其应用 第6、8章 组合 - 图244, where 离散数学及其应用 第6、8章 组合 - 图245 is a constant.

离散数学及其应用 第6、8章 组合 - 图246
The last equation is called the **Characteristic Equation**, and the roots of the equation is called the **Characteristic Roots**. The sequence 离散数学及其应用 第6、8章 组合 - 图247 with 离散数学及其应用 第6、8章 组合 - 图248 where 离散数学及其应用 第6、8章 组合 - 图249 is a solution if and only if 离散数学及其应用 第6、8章 组合 - 图250 is a characteristic root.

  1. A linear combination of two solutions of a linear homogeneous recurrence relation is also a solution.

Suppose that 离散数学及其应用 第6、8章 组合 - 图251 and 离散数学及其应用 第6、8章 组合 - 图252 are both solutions of this recurrence relation.
Then we have
离散数学及其应用 第6、8章 组合 - 图253
and
离散数学及其应用 第6、8章 组合 - 图254
Now suppose that 离散数学及其应用 第6、8章 组合 - 图255 and 离散数学及其应用 第6、8章 组合 - 图256 are real numbers. Then
离散数学及其应用 第6、8章 组合 - 图257
This means that 离散数学及其应用 第6、8章 组合 - 图258 is also a solution of the same linear homogeneous recurrence relation.
📋 The Degree 2 Case
Let 离散数学及其应用 第6、8章 组合 - 图259 be real numbers. Suppose that 离散数学及其应用 第6、8章 组合 - 图260 has two distinct roots 离散数学及其应用 第6、8章 组合 - 图261. Then the sequence 离散数学及其应用 第6、8章 组合 - 图262 is a solution of the recurrence relation 离散数学及其应用 第6、8章 组合 - 图263 if and only if
离散数学及其应用 第6、8章 组合 - 图264 for 离散数学及其应用 第6、8章 组合 - 图265, where 离散数学及其应用 第6、8章 组合 - 图266 are constants.
Proof:
Show that if 离散数学及其应用 第6、8章 组合 - 图267 is a solution, then 离散数学及其应用 第6、8章 组合 - 图268 for some constant 离散数学及其应用 第6、8章 组合 - 图269.
The initial conditions 离散数学及其应用 第6、8章 组合 - 图270 hold. It will be shown that there are constants 离散数学及其应用 第6、8章 组合 - 图271 such that the sequence 离散数学及其应用 第6、8章 组合 - 图272 with 离散数学及其应用 第6、8章 组合 - 图273 satisfies these same initial conditions. This requires that:
离散数学及其应用 第6、8章 组合 - 图274
Hence, with these values for 离散数学及其应用 第6、8章 组合 - 图275, the sequence 离散数学及其应用 第6、8章 组合 - 图276 with 离散数学及其应用 第6、8章 组合 - 图277 satisfies the two initial conditions. We know that 离散数学及其应用 第6、8章 组合 - 图278 and 离散数学及其应用 第6、8章 组合 - 图279 are both solutions of the recurrence relation and both satisfy the initial conditions when 离散数学及其应用 第6、8章 组合 - 图280 and 离散数学及其应用 第6、8章 组合 - 图281.
Because there is a unique solution of a linear homogeneous recurrence relation of degree two with two initial conditions, it follows that the two solutions are the same.
📋 The Solution of the Degree 2 Case when there is a Repeated Root
Let 离散数学及其应用 第6、8章 组合 - 图282 be real numbers with 离散数学及其应用 第6、8章 组合 - 图283. Suppose that 离散数学及其应用 第6、8章 组合 - 图284 has only one root 离散数学及其应用 第6、8章 组合 - 图285. A sequence 离散数学及其应用 第6、8章 组合 - 图286 is a solution of the recurrence relation 离散数学及其应用 第6、8章 组合 - 图287 if and only if 离散数学及其应用 第6、8章 组合 - 图288, where 离散数学及其应用 第6、8章 组合 - 图289 are constants.
📋 The General Case
Let 离散数学及其应用 第6、8章 组合 - 图290 be real numbers. Suppose that the characteristic equation has 离散数学及其应用 第6、8章 组合 - 图291 distinct roots 离散数学及其应用 第6、8章 组合 - 图292. Then a sequence 离散数学及其应用 第6、8章 组合 - 图293 is a solution of the recurrence relation 离散数学及其应用 第6、8章 组合 - 图294 if and only if 离散数学及其应用 第6、8章 组合 - 图295for 离散数学及其应用 第6、8章 组合 - 图296 where 离散数学及其应用 第6、8章 组合 - 图297 are constants.
The coefficients 离散数学及其应用 第6、8章 组合 - 图298 are found by enforcing the initial conditions.
📋 The General Case with Repeated Roots Allowed
Let 离散数学及其应用 第6、8章 组合 - 图299 be real numbers. Suppose that the characteristic equation 离散数学及其应用 第6、8章 组合 - 图300 has 离散数学及其应用 第6、8章 组合 - 图301 distinct roots with multiplicities 离散数学及其应用 第6、8章 组合 - 图302, respectively, so that 离散数学及其应用 第6、8章 组合 - 图303for 离散数学及其应用 第6、8章 组合 - 图304 and 离散数学及其应用 第6、8章 组合 - 图305. Then a sequence 离散数学及其应用 第6、8章 组合 - 图306 is a solution of the recurrence relation 离散数学及其应用 第6、8章 组合 - 图307 if and only if 离散数学及其应用 第6、8章 组合 - 图308 for 离散数学及其应用 第6、8章 组合 - 图309where 离散数学及其应用 第6、8章 组合 - 图310 are constants.

8.2.2 Linear Nonhomogeneous Recurrence Relation With Constant Coefficients

离散数学及其应用 第6、8章 组合 - 图311, where 离散数学及其应用 第6、8章 组合 - 图312 are real number, 离散数学及其应用 第6、8章 组合 - 图313 is a function not identically zero depending only on 离散数学及其应用 第6、8章 组合 - 图314. 离散数学及其应用 第6、8章 组合 - 图315 is called the **associated homogeneous recurrence relation**. Solution to nonhomogeneous case is sum of solution to associated homogeneous recurrence system and a **particular solution** to the nonhomogeneous case.
📋 Solving Linear Nonhomogeneous Recurrence Relations with Constant Coefficients
Let 离散数学及其应用 第6、8章 组合 - 图316 be a particular solution of the nonhomogeneous linear recurrence relation with constant coefficients 离散数学及其应用 第6、8章 组合 - 图317. Then every solution is of the form 离散数学及其应用 第6、8章 组合 - 图318, where 离散数学及其应用 第6、8章 组合 - 图319 is a solution of the associated homogeneous recurrence relation 离散数学及其应用 第6、8章 组合 - 图320.
📋 Assume a linear nonhomogeneous recurrence equation with constant coefficients with the nonlinear part 离散数学及其应用 第6、8章 组合 - 图321 of the form 离散数学及其应用 第6、8章 组合 - 图322. If 离散数学及其应用 第6、8章 组合 - 图323 is not a root of the characteristic equation of the associated homogeneous recurrence equation, there is a particular solution of the form 离散数学及其应用 第6、8章 组合 - 图324. If 离散数学及其应用 第6、8章 组合 - 图325 is a root of multiplicity 离散数学及其应用 第6、8章 组合 - 图326, a particular solutions is of the form 离散数学及其应用 第6、8章 组合 - 图327.

8.4 Generating Function

如果觉得不好理解可以看这篇文章:
The **generating function**(生成函数) for a finite sequence 离散数学及其应用 第6、8章 组合 - 图328 of real numbers is the series 离散数学及其应用 第6、8章 组合 - 图329.
The generating function for a infinite sequence 离散数学及其应用 第6、8章 组合 - 图330 of real numbers is the infinite series 离散数学及其应用 第6、8章 组合 - 图331.
📋 Let 离散数学及其应用 第6、8章 组合 - 图332, 离散数学及其应用 第6、8章 组合 - 图333, then 离散数学及其应用 第6、8章 组合 - 图334.
Proof:
离散数学及其应用 第6、8章 组合 - 图335

🌰 e.g.
Suppose that the generating function of the sequence 离散数学及其应用 第6、8章 组合 - 图336 is 离散数学及其应用 第6、8章 组合 - 图337. What is the generating function for the sequence 离散数学及其应用 第6、8章 组合 - 图338?
Solution:
离散数学及其应用 第6、8章 组合 - 图339
So 离散数学及其应用 第6、8章 组合 - 图340. The generating function of 离散数学及其应用 第6、8章 组合 - 图341 is 离散数学及其应用 第6、8章 组合 - 图342.
So 离散数学及其应用 第6、8章 组合 - 图343.
📋 The Extended Binomial Coefficient
Let 离散数学及其应用 第6、8章 组合 - 图344 be a real number and 离散数学及其应用 第6、8章 组合 - 图345 a nonnegative integer. Then the extended binomial coefficient is defined by 离散数学及其应用 第6、8章 组合 - 图346.
📋 Let 离散数学及其应用 第6、8章 组合 - 图347 be a real number with 离散数学及其应用 第6、8章 组合 - 图348 and let 离散数学及其应用 第6、8章 组合 - 图349 be a real number. Then 离散数学及其应用 第6、8章 组合 - 图350
image.png
📋 Counting Problems Using Generating Functions
This method is shown in the following examples.
🌰 e.g.
Find the number of solutions of 离散数学及其应用 第6、8章 组合 - 图352, where 离散数学及其应用 第6、8章 组合 - 图353, 离散数学及其应用 第6、8章 组合 - 图354, and 离散数学及其应用 第6、8章 组合 - 图355 are nonnegative integers with 离散数学及其应用 第6、8章 组合 - 图356, 离散数学及其应用 第6、8章 组合 - 图357, and 离散数学及其应用 第6、8章 组合 - 图358.
Solution:
The number of solutions with the indicated constraints is the coefficient of 离散数学及其应用 第6、8章 组合 - 图359 in the expansion of 离散数学及其应用 第6、8章 组合 - 图360. This follows because we obtain a term equal to 离散数学及其应用 第6、8章 组合 - 图361 in the product by picking a term in the first sum 离散数学及其应用 第6、8章 组合 - 图362, a term in the second sum 离散数学及其应用 第6、8章 组合 - 图363, and a term in the third sum 离散数学及其应用 第6、8章 组合 - 图364 , where 离散数学及其应用 第6、8章 组合 - 图365. It is not hard to see that the coefficient of 离散数学及其应用 第6、8章 组合 - 图366 in this product is 3. Hence, there are three solutions.
🌰 e.g.
Use generating functions to find the number of r-combinations from a set with 离散数学及其应用 第6、8章 组合 - 图367 elements when repetition of elements is allowed.
Solution:
Since there are 离散数学及其应用 第6、8章 组合 - 图368 elements in the set, each can be selected zero times, one times and so on. It follows that 离散数学及其应用 第6、8章 组合 - 图369.
the number of r-combinations from a set with 离散数学及其应用 第6、8章 组合 - 图370 elements when repetition of elements is allowed, is the coefficient ar of 离散数学及其应用 第6、8章 组合 - 图371 in the expansion of 离散数学及其应用 第6、8章 组合 - 图372. Since 离散数学及其应用 第6、8章 组合 - 图373. Then the coefficient 离散数学及其应用 第6、8章 组合 - 图374 equals 离散数学及其应用 第6、8章 组合 - 图375.
🌰 e.g.
Suppose that there are 离散数学及其应用 第6、8章 组合 - 图376 red balls, 离散数学及其应用 第6、8章 组合 - 图377 blue balls, and 离散数学及其应用 第6、8章 组合 - 图378 white balls. How many ways to select 离散数学及其应用 第6、8章 组合 - 图379 balls from these balls?
Solution:
离散数学及其应用 第6、8章 组合 - 图380
The coefficient 离散数学及其应用 第6、8章 组合 - 图381 of 离散数学及其应用 第6、8章 组合 - 图382 in the expansion of 离散数学及其应用 第6、8章 组合 - 图383 is the solution of this problem.
So 离散数学及其应用 第6、8章 组合 - 图384
离散数学及其应用 第6、8章 组合 - 图385, so 离散数学及其应用 第6、8章 组合 - 图386.
🌰 e.g.
Determine the number of ways to insert tokens worth $1,$2 and $5 into a vending machine to pay for an item that costs r dollars in both the case when the order in which the tokens are inserted does not matter and when the order does matter.
Solution:
(1) When the order in which the tokens are inserted does not matter:
离散数学及其应用 第6、8章 组合 - 图387
The coefficient of 离散数学及其应用 第6、8章 组合 - 图388 in the expansion of 离散数学及其应用 第6、8章 组合 - 图389 is the solution of this problem.
(2) When the order in which the tokens are inserted does matter:
The number of ways to insert exactly 离散数学及其应用 第6、8章 组合 - 图390 tokens to produce a total of $r is the coefficient of 离散数学及其应用 第6、8章 组合 - 图391 in 离散数学及其应用 第6、8章 组合 - 图392. Since any number of tokens may be inserted, the number of ways to produce $r using $1,$2 and $5 tokens, is the coefficient of 离散数学及其应用 第6、8章 组合 - 图393 in 离散数学及其应用 第6、8章 组合 - 图394.
📋 Use Generating Function to Solve Recurrence Relations
This method is shown in the following examples.
🌰 e.g.
Use generating functions to solve the recurrence relation 离散数学及其应用 第6、8章 组合 - 图395 with initial conditions 离散数学及其应用 第6、8章 组合 - 图396.
Solution:
Multiply by 离散数学及其应用 第6、8章 组合 - 图397 on both sides of 离散数学及其应用 第6、8章 组合 - 图398.
image.png
image.png

8.5 Inclusion-Exclusion and Its Application

📋 The Formula for the Number of Elements in the Union of n Finite Sets
离散数学及其应用 第6、8章 组合 - 图401
There are 离散数学及其应用 第6、8章 组合 - 图402 terms in this formula.
Proof:
An element in the union is counted exactly once by the right-hand side of the equation.
Suppose that 离散数学及其应用 第6、8章 组合 - 图403 is an element of exactly 离散数学及其应用 第6、8章 组合 - 图404 of the sets 离散数学及其应用 第6、8章 组合 - 图405 where 离散数学及其应用 第6、8章 组合 - 图406. This element is counted 离散数学及其应用 第6、8章 组合 - 图407 times by 离散数学及其应用 第6、8章 组合 - 图408, 离散数学及其应用 第6、8章 组合 - 图409 times by 离散数学及其应用 第6、8章 组合 - 图410, …
Thus it is counted exactly 离散数学及其应用 第6、8章 组合 - 图411.
📋 An Alternative Form of Inclusion-Exclusion
To solve problems that ask for the number of elements in a set that have none of 离散数学及其应用 第6、8章 组合 - 图412 properties 离散数学及其应用 第6、8章 组合 - 图413. Let 离散数学及其应用 第6、8章 组合 - 图414 be the the subset containing the elements that have property 离散数学及其应用 第6、8章 组合 - 图415. Let 离散数学及其应用 第6、8章 组合 - 图416 be the number of elements with all properties 离散数学及其应用 第6、8章 组合 - 图417. It follows that 离散数学及其应用 第6、8章 组合 - 图418. Let 离散数学及其应用 第6、8章 组合 - 图419 be the number of elements with none of the properties 离散数学及其应用 第6、8章 组合 - 图420. From the inclusion-exclusion principle, we see that: 离散数学及其应用 第6、8章 组合 - 图421
📋 The Sieve of Eratoshenes
A method to find the number of primes not exceeding a specified positive integer.
🌰 e.g.
Take 100 for example.
Solution:
A composite integer is divisible by a prime not exceeding its square root, so composite integer not exceeding 100 must have a prime factor not exceeding 10. Since the only primes less than 10 are 2,3,5,7, the primes not exceeding 100 are these four primes and the positive integers greater than 1 and not exceeding 100 that are divisible by none of 2,3,5,7.
Firstly, we pick out the composites divisible by 2 and change their color into grey. Then pick out the composites divisible by 3 from the rest numbers and so on. Then the black integers are the primes we want.
image.png
🌰 e.g.
Let 离散数学及其应用 第6、8章 组合 - 图423 and 离散数学及其应用 第6、8章 组合 - 图424 be positive integers with 离散数学及其应用 第6、8章 组合 - 图425. Then, there are 离散数学及其应用 第6、8章 组合 - 图426 onto functions from a set with 离散数学及其应用 第6、8章 组合 - 图427 elements to a set with 离散数学及其应用 第6、8章 组合 - 图428 elements.
Proof:
离散数学及其应用 第6、8章 组合 - 图429
Let 离散数学及其应用 第6、8章 组合 - 图430 be the property that 离散数学及其应用 第6、8章 组合 - 图431 is not in the range of the function, respectively. A function is onto if and only if it has none of these properties.
**Derangement**: A derangement is a permutation of objects that leaves no object in the original position.
🌰 e.g.
21453 is a derangement of 12345 because no number is left in its original position.
📋 The number of derangements of a set with 离散数学及其应用 第6、8章 组合 - 图432 elements can be calculated using inclusion-exclusion, and is 离散数学及其应用 第6、8章 组合 - 图433.
Proof:
Let a permutation have property 离散数学及其应用 第6、8章 组合 - 图434 if it fixes element 离散数学及其应用 第6、8章 组合 - 图435. The number of derangements is the number of permutation having none of the properties 离散数学及其应用 第6、8章 组合 - 图436 for 离散数学及其应用 第6、8章 组合 - 图437, namely.
离散数学及其应用 第6、8章 组合 - 图438