Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
LOW, Bryan Kian Hsiang PhD: Carnegie Mellon Univ., 2009 Undergraduate: SoC, NUS, 2001 Website: http://www.comp.nus.edu.sg/~lowkh Email: lowkh@comp.nus.edu.sg Research interests: AI, multi-agent systems, machine learning, robotics Lecture topics: counting/combinatorics, graphs, trees
Basics of Counting
Read Rosen, 5.1
What is Counting?
Combinatorics
Study of arrangement of objects
Enumeration
Counting of objects with certain properties Example: Counting the elements in a list If m and n are integers, and m n, then there are n m + 1 integers from m to n
List Count m (m+0) 0+1=1 m+1 1+1=2 m+2 2+1=3 n (m+(n-m)) (n-m)+1
Recurrence Relations
Determine counting formula from equation relating the terms of a sequence
Generating Functions
Use formal power series to solve some of the above counting problems
Topics
Product/Multiplication Rule Sum/Addition Rule Combining Rules Inclusion-Exclusion Principle Possibility Trees
Product Rule
Product/Multiplication Rule
Suppose that an operation can be broken down into a sequence of 2 tasks: task A and task B. If there are nA ways to do rst task A and nB ways to do second task B for each way of doing task A, the number of ways to do the operation is nAnB . Can you generalize the Product Rule for multiple tasks?
8
Example
The chairs of an auditorium are to be labeled with a letter and a positive integer not exceeding 100 What is the largest number of chairs that can be labeled differently? Solution:
Task A: Assigning one of 26 possible letters Task B: Assigning one of 100 possible integers Product Rule: 26 100 = 2600 different ways to label chairs Hence, the largest no. of chairs that can be labeled differently is 2600
10
12
13
Example
Let U = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}. The ordering of the elements of U has the elements in increasing order, i.e., ai = i. What bit strings represent
the subset of all odd integers in U? the subset of all even integers in U? The subset of integers not exceeding 5 in U?
15
Solution
Length of the bit strings = 10 (why?) For the subset of odd integers, O = {1, 3, 5, 7, 9}
The bit string has one bit in the 1st, 3rd, 5th, 7th, and 9th positions, and a zero elsewhere, i.e., 1010101010
Example
Given that the bit string of the subset O = {1, 3, 5, 7, 9} for the universal set U = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} is 1010101010 , What is the bit string for the complement of this set? [Solution]: To obtain the complement, replace 0s with 1s and vice versa: 0101010101
which corresponds to the set E = {2, 4, 6, 8, 10} Question: How to perform intersection and union on the subsets?
17
By the Product Rule, there are 2|S| bit strings of length |S|. Hence, |P(S)| = 2|S|.
18
Sum Rule
20
Sum/Addition Rule
Suppose that an operation can be broken down into 2 tasks A and B that cannot be done at the same time. If there are nA ways to do task A and nB ways to do task B, the number of ways to do the operation is nA + nB . Can you generalize the Sum Rule for multiple tasks?
21
Example
Suppose that either a member of the computer science faculty or a student who is a computer science major is chosen as a representative to a university committee. How many different choices are there for this representative if there are 37 members of the faculty and 83 students? Solution:
The rst task, choosing a member of the faculty, can be done in 37 ways. The second task, choosing a student, can be done in 83 ways. From the Sum Rule, if follows that there are 37 + 83 = 120 possible ways to pick the representative.
22
Example
A student can choose a computer project from one of three lists. The three lists contain 23, 15, and 19 possible projects, respectively. How many possible projects are there to choose from? Solution: By the Sum Rule, the student can choose from 23 + 15 + 19 = 57 projects.
24
Combining Rules
26
27
28
29
Hence, P = 2,684,483,063,360
30
Inclusion-Exclusion Principle
31
Inclusion-Exclusion Principle
Does not assume mutually disjoint sets. If A and B and C are nite sets, then |A B| = |A| + |B| - |A B|
and |A B C | = |A| + |B| + |C| |A B| - |B C| - |A C| + |A B C | . Proof by mathematical induction. Omitted.
1
2
1
3
2
32
1. How many students do not know any languages? 2. How many students know all three languages? 3. How many students know English and Chinese but not Malay? How many students know English but neither Chinese nor Malay?
33
34
Answers: No. of students who know English and Chinese but not Malay = 3 No. of students who know English only = 11
36
Possibility Trees
37
Possibility Tree
Does not assume number of ways to perform each task to be independent of actions taken in prior tasks Systematically keep track of all possibilities in sequential events Branching Factors
Uniform Non-uniform
Subtrees
Balanced Unbalanced
Reordering Leaves
Final outcomes/events
38
Example
Suppose that a Gap t-shirt comes in 4 different sizes: S, M, L, and XL. Further suppose that each size comes in 3 colors: Red, White, and Blue, except for L, which comes only in Red and White. How many different shirts does a souvenir shop have to stock to have at least one of each available size and color of the T-shirt? Solution:
Answer is 11 = 3*3 + 1*2
XL
B R
W R
39
Example
Three ofcers a president, a treasurer, and a secretary are to be chosen from among 4 people: Ali, Ben, Chee, and Devi. Suppose that, for various reasons, Ali cannot be president and either Chee or Devi must be secretary. How many ways can the ofcers be chosen? Solution:
Can we use the Product Rule directly? 3 choices for president (except Ali) 3 choices for treasurer (except president) 2 choices for secretary (Chee or Devi) By Product Rule, there are 3*3*2 = 18 ways Is this correct?
40
Solution 1
There are only 8 ways to choose!
Task 1: president
Task 2: treasurer
Task 3: secretary C D D C D D C C
41
Solution 2 (Reordering)
By applying Product Rule, there are 2 2 2 = 8 ways to choose
Task 1: secretary
C B
Task 2: president
Task 3: treasurer A D A B A C A B
42
Example
How many bit strings of length 4 do not have consecutive 1s? Solution: The possibility tree displays all bit strings of length 4 without two consecutive 1s. Answer is 8
1 0 1 0 1 0
0 0 1 0
01
1 0
0 1 0
43
Product Rule
Does any outcome appear on more than one branch of the tree? Does every outcome/element appear as a branch of the tree?
Sum Rule
Do any two subsets share common elements? All the subsets must be disjoint. Does every outcome/element appear in some subset of the diagram? ??
44
Permutations
Read Rosen, 5.3, 5.5
45
Permutations
Denition. A permutation of a set of objects is an ordered arrangement of the objects. Remark. Recall that the elements of a set are distinct. Example. Permutations of {a, b, c}. How many permutations are there? 3 ways to select x {a, b, c} of xyz. 2 ways to select y {a, b, c} - {x} of xyz. 1 way to select z {a, b, c} - {x, y} of xyz.
46
Possibility Tree
Example. Permutations of {a, b, c}.
a c b
abc
acb
bac
bca
cab
cba
47
Permutations
Theorem 1. Let n be an integer with n 0. Then, the number of permutations of a set with n distinct elements is n!. Proof. 1. Each permutation is a sequence of n elements. 2. The 1st element of the sequence can be selected in n ways because there are n elements in the set. 3. In general, the k-th element of the sequence can be selected in n k + 1 ways for k = 1, . . . , n because there are n k + 1 elements left in the set. 4. The sequence of n elements can be selected in n (n 1) . . . 1 = n! ways, by the Product Rule. So, there are n! permutations.
48
r-Permutations
Denition. An r-permutation of a set of n elements is an ordered selection of r elements taken from the set of n elements. The number of r-permutations of a set of n elements is denoted P(n, r). Remark. Recall that the elements of a set are distinct.
49
r-Permutations
Theorem 2. Let n and r be integers with 0 r n. Then, the number of r-permutations of a set of n elements is given by P (n, r) = n (n 1) (n 2) . . . (n r + 1). Proof. 1. Each r-permutation is a sequence of r elements.
2. The 1st element of the sequence can be selected in n ways because there are n elements in the set. 3. In general, the k-th element of the sequence can be selected in n k + 1 ways for k = 1, . . . , r because there are n k + 1 elements left in the set. 4. By the Product Rule, the sequence of r elements can be selected in n (n 1) . . . (n r + 1) ways, which is the number of r-permutations.
50
r-Permutations
Corollary 1. Let n and r be integers with 0 r n. Then, P (n, r) = Proof. P (n, r) = n (n n (n = = n! (n r)! 1) . . . (n r + 1) 1) . . . (n r + 1)(n (n r)! r)! n! (n r)! .
51
Possibility Tree
Example. 2-Permutations of {a, b, c}. There are 3!/(3-2)! = 6 ways of arranging 2 elements of {a, b, c}.
a c b
ab
ac
ba
bc
ca
cb
52
r-Permutations
Example. There are 5 4 3 = 60 ways of arranging 3 of the 5 letters of BYTES. There are 4 3 = 12 ways of arranging 3 of the 5 letters of BYTES such that the rst letter must be B. To explain this, consider the number of ways to form the sequence Bab where a, b {Y, T, E, S}.
53
Property of P(n, r)
Corollary 2. For all integers n By Corollary , P n, and P n, So, P n, P n, nn n n . n n n n nn n nn n n nn , P n, P n, n .
n.
54
55
Possibility Tree
Example. 3-permutations of {0,1} with repetition allowed. There are 23=8 3-permutations of the set {0,1}.
0 1
000
001 010
011
100
101 110
111
56