cse 321 discrete structures winter 2008 lecture 16 counting
Post on 20-Dec-2015
217 views
TRANSCRIPT
![Page 1: CSE 321 Discrete Structures Winter 2008 Lecture 16 Counting](https://reader038.vdocument.in/reader038/viewer/2022110207/56649d4e5503460f94a2e855/html5/thumbnails/1.jpg)
CSE 321 Discrete Structures
Winter 2008
Lecture 16
Counting
![Page 2: CSE 321 Discrete Structures Winter 2008 Lecture 16 Counting](https://reader038.vdocument.in/reader038/viewer/2022110207/56649d4e5503460f94a2e855/html5/thumbnails/2.jpg)
Announcements
• Readings – Friday, Wednesday:
• Counting– 6th edition: 5.1, 5.2, 5.3, 5th edition: 4.1, 4.2. 4.3
– Lecture 16 video will be posted on Tuesday– Monday, Presidents’ Day, Holiday
![Page 3: CSE 321 Discrete Structures Winter 2008 Lecture 16 Counting](https://reader038.vdocument.in/reader038/viewer/2022110207/56649d4e5503460f94a2e855/html5/thumbnails/3.jpg)
Counting
• Determining the number of elements of a finite set
![Page 4: CSE 321 Discrete Structures Winter 2008 Lecture 16 Counting](https://reader038.vdocument.in/reader038/viewer/2022110207/56649d4e5503460f94a2e855/html5/thumbnails/4.jpg)
Counting Rules
Product Rule: If there are n1 choices for the first item and n2 choices for the second item, then there are n1n2 choices for the two items
Sum Rule: If there are n1 choices of an element from S1 and n2 choices of an element from S2 and S1 S2 is empty, then there are n1 + n2 choices of an element from S1 S2
![Page 5: CSE 321 Discrete Structures Winter 2008 Lecture 16 Counting](https://reader038.vdocument.in/reader038/viewer/2022110207/56649d4e5503460f94a2e855/html5/thumbnails/5.jpg)
Counting examples
License numbers have the form LLL DDD, how many different license numbers are available?
There are 38 students in a class, and 38 chairs, how many different seating arrangements are there if everyoneshows up?
How many different predicates are there on = {a,…,z}?
![Page 6: CSE 321 Discrete Structures Winter 2008 Lecture 16 Counting](https://reader038.vdocument.in/reader038/viewer/2022110207/56649d4e5503460f94a2e855/html5/thumbnails/6.jpg)
Important cases of the Product Rule
• Cartesian product– |A1 A2 … An| = |A1||A2||An|
• Subsets of a set S– |P(S)|= 2|S|
• Strings of length n over – |n| = ||n
![Page 7: CSE 321 Discrete Structures Winter 2008 Lecture 16 Counting](https://reader038.vdocument.in/reader038/viewer/2022110207/56649d4e5503460f94a2e855/html5/thumbnails/7.jpg)
Counting Functions
Suppose |S| = n, |T| = m
How many functions from S to T?
How many one-to-one functions from S to T?
![Page 8: CSE 321 Discrete Structures Winter 2008 Lecture 16 Counting](https://reader038.vdocument.in/reader038/viewer/2022110207/56649d4e5503460f94a2e855/html5/thumbnails/8.jpg)
More complicated counting examples
• BASIC variable names– Variables can be one or two characters long
• The first character must be a letter• The second character can be a letter or a digit• The keywords “TO”, “IF”, and “DO” are excluded
![Page 9: CSE 321 Discrete Structures Winter 2008 Lecture 16 Counting](https://reader038.vdocument.in/reader038/viewer/2022110207/56649d4e5503460f94a2e855/html5/thumbnails/9.jpg)
Counting Passwords
• Passwords must be 4 to 6 characters long, and must contain at least one letter and at least one digit. (Case insensitive, no special characters)
![Page 10: CSE 321 Discrete Structures Winter 2008 Lecture 16 Counting](https://reader038.vdocument.in/reader038/viewer/2022110207/56649d4e5503460f94a2e855/html5/thumbnails/10.jpg)
Inclusion-Exclusion Principle
• How many binary strings of length 9 start with 00 or end with 11
|A1 A2 | = |A1| + |A2| - |A1 A2|
![Page 11: CSE 321 Discrete Structures Winter 2008 Lecture 16 Counting](https://reader038.vdocument.in/reader038/viewer/2022110207/56649d4e5503460f94a2e855/html5/thumbnails/11.jpg)
Inclusion-Exclusion
• A class has of 40 students has 20 CS majors, 15 Math majors. 5 of these students are dual majors. How many students in the class are neither math, nor CS majors?
![Page 12: CSE 321 Discrete Structures Winter 2008 Lecture 16 Counting](https://reader038.vdocument.in/reader038/viewer/2022110207/56649d4e5503460f94a2e855/html5/thumbnails/12.jpg)
Generalizing Inclusion Exclusion
![Page 13: CSE 321 Discrete Structures Winter 2008 Lecture 16 Counting](https://reader038.vdocument.in/reader038/viewer/2022110207/56649d4e5503460f94a2e855/html5/thumbnails/13.jpg)
Pigeon Hole Principle
If k is a positive integer and k+1 or more objects are placed into k boxes, then at least one box has two or more objects
If N objects are placed into k boxes, then there is at least one box containing at least N/k objects
![Page 14: CSE 321 Discrete Structures Winter 2008 Lecture 16 Counting](https://reader038.vdocument.in/reader038/viewer/2022110207/56649d4e5503460f94a2e855/html5/thumbnails/14.jpg)
PHP Applications
• Prove that if a city has at least 10 million phone subscribers it needs more than one area code. (Phone numbers of the form NXX-XXXX.)
• Prove that if you have 800 people, at least three share a common birthday.
![Page 15: CSE 321 Discrete Structures Winter 2008 Lecture 16 Counting](https://reader038.vdocument.in/reader038/viewer/2022110207/56649d4e5503460f94a2e855/html5/thumbnails/15.jpg)
Clever PHP Applications
• Every sequence of n2 + 1 distinct numbers contains a subsequence of length n+1 that is either strictly increasing or strictly decreasing.
4, 22, 8, 15, 19, 11, 2, 1, 9, 20, 10, 7, 16, 3, 6, 5, 14
![Page 16: CSE 321 Discrete Structures Winter 2008 Lecture 16 Counting](https://reader038.vdocument.in/reader038/viewer/2022110207/56649d4e5503460f94a2e855/html5/thumbnails/16.jpg)
Proof
• Let a1, . . . am be a sequence of n2+1 distinct numbers
• Let ik be the length of the longest increasing sequence starting at ak
• Let dk be the length of the longest decreasing sequence starting at ak
• Suppose ik n and dk n for all k
• There must be k and j, k < j, with ik = ij and dk = dj
![Page 17: CSE 321 Discrete Structures Winter 2008 Lecture 16 Counting](https://reader038.vdocument.in/reader038/viewer/2022110207/56649d4e5503460f94a2e855/html5/thumbnails/17.jpg)
Permutations vs. Combinations
• How many ways are there of selecting 1st, 2nd, and 3rd place from a group of 10 sprinters?
• How many ways are there of selecting the top three finishers from a group of 10 sprinters?
![Page 18: CSE 321 Discrete Structures Winter 2008 Lecture 16 Counting](https://reader038.vdocument.in/reader038/viewer/2022110207/56649d4e5503460f94a2e855/html5/thumbnails/18.jpg)
r-Permutations
• An r-permutation is an ordered selection of r elements from a set
• P(n, r), number of r-permutations of an n element set
![Page 19: CSE 321 Discrete Structures Winter 2008 Lecture 16 Counting](https://reader038.vdocument.in/reader038/viewer/2022110207/56649d4e5503460f94a2e855/html5/thumbnails/19.jpg)
r-Combinations
• An r-combination is an unordered selection of r elements from a set (or just a subset of size r)
• C(r, n), number of r-permutations of an n element set
![Page 20: CSE 321 Discrete Structures Winter 2008 Lecture 16 Counting](https://reader038.vdocument.in/reader038/viewer/2022110207/56649d4e5503460f94a2e855/html5/thumbnails/20.jpg)
How many
• Binary strings of length 10 with 3 0’s
• Binary strings of length 10 with 7 1’s
• How many different ways of assigning 38 students to the 5 seats in the front of the class
• How many different ways of assigning 38 students to a table that seats 5 students
![Page 21: CSE 321 Discrete Structures Winter 2008 Lecture 16 Counting](https://reader038.vdocument.in/reader038/viewer/2022110207/56649d4e5503460f94a2e855/html5/thumbnails/21.jpg)
Prove C(n, r) = C(n, n-r) [Proof 1]
• Proof by formula
![Page 22: CSE 321 Discrete Structures Winter 2008 Lecture 16 Counting](https://reader038.vdocument.in/reader038/viewer/2022110207/56649d4e5503460f94a2e855/html5/thumbnails/22.jpg)
Prove C(n, r) = C(n, n-r) [Proof 2]
• Combinatorial proof
![Page 23: CSE 321 Discrete Structures Winter 2008 Lecture 16 Counting](https://reader038.vdocument.in/reader038/viewer/2022110207/56649d4e5503460f94a2e855/html5/thumbnails/23.jpg)
Counting paths
• How many paths are there of length n+m-2 from the upper left corner to the lower right corner of an n m grid?
![Page 24: CSE 321 Discrete Structures Winter 2008 Lecture 16 Counting](https://reader038.vdocument.in/reader038/viewer/2022110207/56649d4e5503460f94a2e855/html5/thumbnails/24.jpg)
Binomial Theorem
![Page 25: CSE 321 Discrete Structures Winter 2008 Lecture 16 Counting](https://reader038.vdocument.in/reader038/viewer/2022110207/56649d4e5503460f94a2e855/html5/thumbnails/25.jpg)
Binomial Coefficient Identities from the Binomial Theorem
![Page 26: CSE 321 Discrete Structures Winter 2008 Lecture 16 Counting](https://reader038.vdocument.in/reader038/viewer/2022110207/56649d4e5503460f94a2e855/html5/thumbnails/26.jpg)
Pascal’s Identity and Triangle
![Page 27: CSE 321 Discrete Structures Winter 2008 Lecture 16 Counting](https://reader038.vdocument.in/reader038/viewer/2022110207/56649d4e5503460f94a2e855/html5/thumbnails/27.jpg)
How many
• Let s1 be a string of length n over
• Let s2 be a string of length m over
• Assuming and are distinct, how many interleavings are there of s1 and s2?
![Page 28: CSE 321 Discrete Structures Winter 2008 Lecture 16 Counting](https://reader038.vdocument.in/reader038/viewer/2022110207/56649d4e5503460f94a2e855/html5/thumbnails/28.jpg)
Permutations with repetition
![Page 29: CSE 321 Discrete Structures Winter 2008 Lecture 16 Counting](https://reader038.vdocument.in/reader038/viewer/2022110207/56649d4e5503460f94a2e855/html5/thumbnails/29.jpg)
Combinations with repetition
• How many different ways are there of selecting 5 letters from {A, B, C} with repetition
![Page 30: CSE 321 Discrete Structures Winter 2008 Lecture 16 Counting](https://reader038.vdocument.in/reader038/viewer/2022110207/56649d4e5503460f94a2e855/html5/thumbnails/30.jpg)
How many non-decreasing sequences of {1,2,3} of length 5 are there?
![Page 31: CSE 321 Discrete Structures Winter 2008 Lecture 16 Counting](https://reader038.vdocument.in/reader038/viewer/2022110207/56649d4e5503460f94a2e855/html5/thumbnails/31.jpg)
How many different ways are there of adding 3 non-negative integers together to
get 5 ?
1 + 2 + 2 | |
2 + 0 + 3 | |
0 + 1 + 4
3 + 1 + 1
5 + 0 + 0
![Page 32: CSE 321 Discrete Structures Winter 2008 Lecture 16 Counting](https://reader038.vdocument.in/reader038/viewer/2022110207/56649d4e5503460f94a2e855/html5/thumbnails/32.jpg)
C(n+r-1,n-1) r-combinations of an n element set with repetition
![Page 33: CSE 321 Discrete Structures Winter 2008 Lecture 16 Counting](https://reader038.vdocument.in/reader038/viewer/2022110207/56649d4e5503460f94a2e855/html5/thumbnails/33.jpg)
Permutations of indistinguishable objects
• How many different strings can be made from reordering the letters ABCDEFGH
• How many different strings can be made from reordering the letters AAAABBBB
• How many different strings can be made from reordering the letters GOOOOGLE