Counting
description
Transcript of Counting
![Page 1: Counting](https://reader035.fdocuments.in/reader035/viewer/2022081517/5681675d550346895ddc2b24/html5/thumbnails/1.jpg)
Counting
![Page 2: Counting](https://reader035.fdocuments.in/reader035/viewer/2022081517/5681675d550346895ddc2b24/html5/thumbnails/2.jpg)
Counting in Algorithms
• How many comparisons are needed to sort n numbers?
• How many steps to compute the GCD of two numbers ?
• How many steps to factor an integer?
![Page 3: Counting](https://reader035.fdocuments.in/reader035/viewer/2022081517/5681675d550346895ddc2b24/html5/thumbnails/3.jpg)
• How many different configurations for a Rubik’s cube?
• How many weighings to find the one counterfeit among 12 coins?
• How many different chess positions after n moves?
Counting in Games
![Page 4: Counting](https://reader035.fdocuments.in/reader035/viewer/2022081517/5681675d550346895ddc2b24/html5/thumbnails/4.jpg)
If sets A and B are disjoint, then |A B| = |A| + |B|
A B
Sum Rule
• Class has 43 women, 54 men, so total enrollment = 43 + 54 = 97
• 26 lower case letters, 26 upper case letters, and 10 digits, so total characters = 26+26+10 = 62
![Page 5: Counting](https://reader035.fdocuments.in/reader035/viewer/2022081517/5681675d550346895ddc2b24/html5/thumbnails/5.jpg)
Given two sets A and B, the Cartisean product
Product Rule
If |A| = m and |B| = n, then|A B| = mn.
A = {a, b, c, d}, B = {1, 2, 3}A B = {(a,1),(a,2),(a,3), (b,1),(b,2),(b,3), (c,1),(c,2),(c,3), (d,1),(d,2),(d,3) }
If there are 4 men and 3 women, there are possible married couples.4 13 2
![Page 6: Counting](https://reader035.fdocuments.in/reader035/viewer/2022081517/5681675d550346895ddc2b24/html5/thumbnails/6.jpg)
Product Rule: Counting Strings
The number of length-4 strings from alphabet B ::= {0,1}= |B B B B| = 2 · 2 · 2 · 2 = 24
The number of length-n strings from an alphabet of size m ismn.
![Page 7: Counting](https://reader035.fdocuments.in/reader035/viewer/2022081517/5681675d550346895ddc2b24/html5/thumbnails/7.jpg)
• between 6 & 8 characters long• starts with a letter• case sensitive• other characters: digits or letters
How many passwords satisfy the following requirements?
Example: Counting Passwords
L ::= {a,b,…,z,A,B,…,Z}D ::= {0,1,…,9}
![Page 8: Counting](https://reader035.fdocuments.in/reader035/viewer/2022081517/5681675d550346895ddc2b24/html5/thumbnails/8.jpg)
Example: Counting Passwords
![Page 9: Counting](https://reader035.fdocuments.in/reader035/viewer/2022081517/5681675d550346895ddc2b24/html5/thumbnails/9.jpg)
At Least One Seven
How many # 4-digit numbers with at least one 7?
![Page 10: Counting](https://reader035.fdocuments.in/reader035/viewer/2022081517/5681675d550346895ddc2b24/html5/thumbnails/10.jpg)
Defective Dollars
A dollar is defective if some digit appearsmore than once in the 6-digit serial number.
How common are nondefective dollars?
![Page 11: Counting](https://reader035.fdocuments.in/reader035/viewer/2022081517/5681675d550346895ddc2b24/html5/thumbnails/11.jpg)
Defective Dollars
How common are nondefective dollars?
![Page 12: Counting](https://reader035.fdocuments.in/reader035/viewer/2022081517/5681675d550346895ddc2b24/html5/thumbnails/12.jpg)
Generalized Product Rule
Q a set of length-k sequences. If there are:
n1 possible 1st elements in sequences,
n2 possible 2nd elements for each first entry,
n3 possible 3rd elements for each 1st & 2nd,
…then, |Q| = n1 · n2 · n3 · … · nk
![Page 13: Counting](https://reader035.fdocuments.in/reader035/viewer/2022081517/5681675d550346895ddc2b24/html5/thumbnails/13.jpg)
Example
How many four-digit integers are divisible by 5?
![Page 14: Counting](https://reader035.fdocuments.in/reader035/viewer/2022081517/5681675d550346895ddc2b24/html5/thumbnails/14.jpg)
Permutations
A permutation of a set S is a sequence that contains every element of S exactly once.
For example, here are all six permutations of the set {a, b, c}:
(a, b, c) (a, c, b) (b, a, c)(b, c, a) (c, a, b) (c, b, a)
How many permutations of an n-element set are there?
![Page 15: Counting](https://reader035.fdocuments.in/reader035/viewer/2022081517/5681675d550346895ddc2b24/html5/thumbnails/15.jpg)
How many permutations of an n-element set are there?
Permutations
nnn! 2πn e~Stirling’s formula:
![Page 16: Counting](https://reader035.fdocuments.in/reader035/viewer/2022081517/5681675d550346895ddc2b24/html5/thumbnails/16.jpg)
How many subsets of r elements of an n-element set?
Combinations
![Page 17: Counting](https://reader035.fdocuments.in/reader035/viewer/2022081517/5681675d550346895ddc2b24/html5/thumbnails/17.jpg)
How many subsets of r elements of an n-element set?
Combinations
![Page 18: Counting](https://reader035.fdocuments.in/reader035/viewer/2022081517/5681675d550346895ddc2b24/html5/thumbnails/18.jpg)
Poker Hands
There are 52 cards in a deck. Each card has a suit and a value.
4 suits (♠ ♥ ♦ ♣)13 values (2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A)
Five-Card Draw is a card game in which each player is initially dealt a hand, a subset of 5 cards.
How many different hands?
![Page 19: Counting](https://reader035.fdocuments.in/reader035/viewer/2022081517/5681675d550346895ddc2b24/html5/thumbnails/19.jpg)
Example 1: Four of a Kind
A Four-of-a-Kind is a set of four cards with the same value.
How many different hands contain a Four-of-a-Kind?
![Page 20: Counting](https://reader035.fdocuments.in/reader035/viewer/2022081517/5681675d550346895ddc2b24/html5/thumbnails/20.jpg)
Example 2: Full House
A Full House is a hand with three cards of one value and two cards of another value.
How many different hands contain a Full House?
![Page 21: Counting](https://reader035.fdocuments.in/reader035/viewer/2022081517/5681675d550346895ddc2b24/html5/thumbnails/21.jpg)
Example 3: Two Pairs
How many hands have Two Pairs; that is, two cards of one value, two cards of another value, and one card of a third value?
![Page 22: Counting](https://reader035.fdocuments.in/reader035/viewer/2022081517/5681675d550346895ddc2b24/html5/thumbnails/22.jpg)
Example 4: Every Suit
How many hands contain at least one card from every suit?
![Page 23: Counting](https://reader035.fdocuments.in/reader035/viewer/2022081517/5681675d550346895ddc2b24/html5/thumbnails/23.jpg)
Binomial Theorem
![Page 24: Counting](https://reader035.fdocuments.in/reader035/viewer/2022081517/5681675d550346895ddc2b24/html5/thumbnails/24.jpg)
Binomial Theorem
![Page 25: Counting](https://reader035.fdocuments.in/reader035/viewer/2022081517/5681675d550346895ddc2b24/html5/thumbnails/25.jpg)
Proving Identities
![Page 26: Counting](https://reader035.fdocuments.in/reader035/viewer/2022081517/5681675d550346895ddc2b24/html5/thumbnails/26.jpg)
Finding a Combinatorial Proof
A combinatorial proof is an argument that establishes an algebraic fact by relying on counting principles. Many such proofs follow the same basic outline:
1. Define a set S.2. Show that |S| = n by counting one way.3. Show that |S| = m by counting another way.4. Conclude that n = m.
![Page 27: Counting](https://reader035.fdocuments.in/reader035/viewer/2022081517/5681675d550346895ddc2b24/html5/thumbnails/27.jpg)
Proving Identities
Pascal’s Formula
![Page 28: Counting](https://reader035.fdocuments.in/reader035/viewer/2022081517/5681675d550346895ddc2b24/html5/thumbnails/28.jpg)
Combinatorial Proof
![Page 29: Counting](https://reader035.fdocuments.in/reader035/viewer/2022081517/5681675d550346895ddc2b24/html5/thumbnails/29.jpg)
More Combinatorial Proof
![Page 30: Counting](https://reader035.fdocuments.in/reader035/viewer/2022081517/5681675d550346895ddc2b24/html5/thumbnails/30.jpg)
If sets A and B are disjoint, then |A B| = |A| + |B|
A B
What if A and B are not disjoint?
Sum Rule
![Page 31: Counting](https://reader035.fdocuments.in/reader035/viewer/2022081517/5681675d550346895ddc2b24/html5/thumbnails/31.jpg)
For two arbitrary sets A and B
|||||||| BABABA
A B
Inclusion-Exclusion (2 sets)
![Page 32: Counting](https://reader035.fdocuments.in/reader035/viewer/2022081517/5681675d550346895ddc2b24/html5/thumbnails/32.jpg)
Inclusion-Exclusion (2 sets)
How many integers from 1 through 1000 are multiples of 3 or multiples of 5?
![Page 33: Counting](https://reader035.fdocuments.in/reader035/viewer/2022081517/5681675d550346895ddc2b24/html5/thumbnails/33.jpg)
A B
C
|A B C| = |A| + |B| + |C|
– |A B| – |A C| – |B C|
+ |A B C|
Inclusion-Exclusion (3 sets)
![Page 34: Counting](https://reader035.fdocuments.in/reader035/viewer/2022081517/5681675d550346895ddc2b24/html5/thumbnails/34.jpg)
Inclusion-Exclusion (3 sets)
From a total of 50 students: 30 know Java 18 know C++26 know C#9 know both Java and C++16 know both Java and C#8 know both C++ and C#47 know at least one language.
How many know none?
How many know all?
![Page 35: Counting](https://reader035.fdocuments.in/reader035/viewer/2022081517/5681675d550346895ddc2b24/html5/thumbnails/35.jpg)
sum of sizes of all single sets– sum of sizes of all 2-set intersections+ sum of sizes of all 3-set intersections– sum of sizes of all 4-set intersections…+ (–1)n+1 × sum of sizes of intersections of all n
sets
1 2 nA A A
1
1,2, ,1
( 1)n
ki
S nk i SS k
A
Inclusion-Exclusion (n sets)