Basic Counting Lecture 12: Oct 28. This Lecture We will study some basic rules for counting. Sum rule, product rule, generalized product rule Permutations,

Slides:



Advertisements
Similar presentations
9.5 Counting Subsets of a Set: Combinations
Advertisements

Counting. 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.
Mathematics in OI Bill Kwok 20/3/2010 HKOI 2010 Intermediate Training Acknowledgement: References and slides are extracted from: 1. Math in OI, ,
1 More Counting by Mapping Lecture 16: Nov 7. 2 This Lecture Division rule Catalan number.
Counting Chapter 6 With Question/Answer Animations.
Sets Lecture 11: Oct 24 AB C. This Lecture We will first introduce some basic set theory before we do counting. Basic Definitions Operations on Sets Set.
Great Theoretical Ideas in Computer Science.
CSCE 2100: Computing Foundations 1 Combinatorics Tamara Schneider Summer 2013.
Counting Principles The Fundamental Counting Principle: If one event can occur m ways and another can occur n ways, then the number of ways the events.
Counting Techniques: Combinations
Counting and Probability The outcome of a random process is sure to occur, but impossible to predict. Examples: fair coin tossing, rolling a pair of dice,
Multiplication Rule. A tree structure is a useful tool for keeping systematic track of all possibilities in situations in which events happen in order.
Discrete Structures & Algorithms Counting Counting I: One-To-One Correspondence and Choice Trees.
Discrete Structures & Algorithms More Counting. + + ( ) + ( ) = ? Counting II: Recurring Problems and Correspondences.
CSE115/ENGR160 Discrete Mathematics 04/17/12
Counting II: Recurring Problems And Correspondences Great Theoretical Ideas In Computer Science Steven RudichCS Spring 2004 Lecture 10Feb 12, 2004Carnegie.
Chapter 2 Section 2.4 Permutations and Combinations.
1 Section 5.1 Discrete Probability. 2 LaPlace’s definition of probability Number of successful outcomes divided by the number of possible outcomes This.
Combinations We should use permutation where order matters
Discrete Mathematics Lecture 6 Alexander Bukharovich New York University.
1 More Counting Techniques Possibility trees Multiplication rule Permutations Combinations.
Recursive Definitions Rosen, 3.4 Recursive (or inductive) Definitions Sometimes easier to define an object in terms of itself. This process is called.
COUNTING PRINCIPALS, PERMUTATIONS, AND COMBINATIONS.
4. Counting 4.1 The Basic of Counting Basic Counting Principles Example 1 suppose that either a member of the faculty or a student in the department is.
Combinatorics 3/15 and 3/ Counting A restaurant offers the following menu: Main CourseVegetablesBeverage BeefPotatoesMilk HamGreen BeansCoffee.
More Counting Lecture 16: Nov 9 A B …… f. This Lecture We will study how to define mappings to count. There will be many examples shown. Bijection rule.
Copyright © Cengage Learning. All rights reserved. CHAPTER 9 COUNTING AND PROBABILITY.
Counting. Techniques for counting Rule 1 Suppose we carry out have a sets A 1, A 2, A 3, … and that any pair are mutually exclusive (i.e. A 1  A 2 =
1 Melikyan/DM/Fall09 Discrete Mathematics Ch. 6 Counting and Probability Instructor: Hayk Melikyan Today we will review sections 6.4,
Advanced Mathematics Counting Techniques. Addition Rule Events (tasks) A and B are mutually exclusive (no common elements/outcomes) and n(A) = a, n(B)
Basic Counting. This Lecture We will study some basic rules for counting. Sum rule, product rule, generalized product rule Permutations, combinations.
Chapter 6 With Question/Answer Animations 1. Chapter Summary The Basics of Counting The Pigeonhole Principle Permutations and Combinations Binomial Coefficients.
Permutations and Combinations
Fall 2002CMSC Discrete Structures1 One, two, three, we’re… Counting.
© The McGraw-Hill Companies, Inc., Chapter 4 Counting Techniques.
Conditional Probability The probability that event B will occur given that A will occur (or has occurred) is denoted P(B|A) (read the probability of B.
1 CSC 321: Data Structures Fall 2013 Counting and problem solving  mappings, bijection rule  sequences, product rule, sum rule  generalized product.
Simple Arrangements & Selections. Combinations & Permutations A permutation of n distinct objects is an arrangement, or ordering, of the n objects. An.
COMPSCI 102 Discrete Mathematics for Computer Science.
Discrete Mathematics for Computer Science. + + ( ) + ( ) = ? Counting II: Recurring Problems and Correspondences Chapter 9 slides 1-54.
Great Theoretical Ideas in Computer Science.
Ch Counting Principles. Example 1  Eight pieces of paper are numbered from 1-8 and placed in a box. One piece of paper is drawn from the box, its.
1 Counting by Mapping Lecture 15: Nov 4 A B …… f.
CompSci 102 Discrete Math for Computer Science March 20, 2012 Prof. Rodger Lecture adapted from Bruce Maggs/Lecture developed at Carnegie Mellon, primarily.
Counting II: Recurring Problems And Correspondences Great Theoretical Ideas In Computer Science John LaffertyCS Fall 2005 Lecture 7Sept 20, 2005Carnegie.
Unit VI Discrete Structures Permutations and Combinations SE (Comp.Engg.)
Some other set notation We will use the notation to mean that e is an element of A. We will use the notation to mean that e is not an element of A.
Copyright © Ed2Net Learning Inc.1. 2 Warm Up Tell whether each event is dependent or independent 1. Selecting a name from a Chicago telephone book and.
Counting II: Recurring Problems And Correspondences Great Theoretical Ideas In Computer Science V. AdamchikCS Spring 2006 Lecture 6Feb 2, 2005Carnegie.
CS Lecture 8 Developing Your Counting Muscles.
2/24/20161 One, two, three, we’re… Counting. 2/24/20162 Basic Counting Principles Counting problems are of the following kind: “How many different 8-letter.
Introduction Suppose that a password on a computer system consists of 6, 7, or 8 characters. Each of these characters must be a digit or a letter of the.
Copyright © Peter Cappello 2011 Simple Arrangements & Selections.
Counting I: One To One Correspondence and Choice Trees Great Theoretical Ideas In Computer Science John LaffertyCS Fall 2005 Lecture 6Sept 15,
Section Basic Counting Principles: The Product Rule The Product Rule: A procedure can be broken down into a sequence of two tasks. There are n 1.
CS Lecture 6 How To Count Without Counting.
Permutations & Combinations: Selected Exercises. Copyright © Peter Cappello2 Preliminaries Denote the # of arrangements of some k elements of a set of.
Section The Product Rule  Example: How many different license plates can be made if each plate contains a sequence of three uppercase English letters.
COUNTING Discrete Math Team KS MATEMATIKA DISKRIT (DISCRETE MATHEMATICS ) 1.
Section 6.3. Section Summary Permutations Combinations.
Fifteen Puzzle Move: can move a square adjacent to the empty square to the empty square.
CSC 321: Data Structures Fall 2015 Counting and problem solving
CSE15 Discrete Mathematics 04/19/17
Sequences, Series, and Probability
CSC 321: Data Structures Fall 2016 Counting and proofs
Basic Counting.
More Counting A B … f Lecture 16: Nov 9.
COUNTING AND PROBABILITY
Basic Counting Lecture 9: Nov 5, 6.
Section 6.4 Counting and Combinations with Multiple Cases
Presentation transcript:

Basic Counting Lecture 12: Oct 28

This Lecture We will study some basic rules for counting. Sum rule, product rule, generalized product rule Permutations, combinations, poker hands

If sets A and B are disjoint, then |A  B| = |A| + |B| A B Sum Rule |S|: the number of elements in a set S.

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 = = lower case letters, 26 upper case letters, and 10 digits, so total characters = = 62

Recall that, given two sets A and B, the Cartisean product Product Rule 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) } Example: If there are 4 men and 3 women, there are possible married couples. Fact: If |A| = n and |B| = m, then |AxB| = mn.

Product Rule In general let A = {a 1, a 2, a 3, …, a m } and B = {b 1, b 2, …, b n }. We can arrange the elements into a table as follows. A  B = {(a 1,b 1 ), (a 1,b 2 ),…, (a 1,b n ), (a 2,b 1 ), (a 2,b 2 ),…, (a 2,b n ), (a 3,b 1 ), (a 3,b 2 ),…, (a 3,b n ), … (a m,b 1 ), (a m,b 2 ),…, (a m,b n ), } There are m rows, and each row has n elements, and so there are a total of mn elements. Fact: If |A| = n and |B| = m, then |AxB| = mn.

Product Rule Fact: |A 1 xA 2 x…xA k | = |A 1 |x|A 2 |x…x|A k |. We know that there are |A 1 |x|A 2 | choices for the first two entries. And there are |A 3 | choices for the third entry. By the product rule, there are (|A 1 |x|A 2 |)x|A 3 | for the first three entries. Similarly, there are (|A 1 |x|A 2 |x|A 3 |) choices for the first three entires, and there are |A 4 | choices for the fourth entry, and by the product rule there are (|A 1 |x|A 2 |x|A 3 |) x|A 4 | choices for the first four entries. By induction, we can see that |A 1 xA 2 x…xA k | = |A 1 |x|A 2 |x…x|A k |.

Example: Counting Strings Let B={0,1}. The set of 2-bit strings is just BxB. The set of 10-bit strings is just BxBxBxBxBxBxBxBxBxB, denoted by B 10. By the product rule, |BxB| = |B|x|B| = 2x2 = 4, and |B 10 | = |B|x|B|x|B|x|B|x|B|x|B|x|B|x|B|x|B|x|B| = |B| 10 = 2 10 = What is the number of 10-bit strings?

Example: IP Addresses An IP address is of the form There are four numbers, each is between 0 and 255. Let B={0,1,…,255}. Then the set of IP addresses is just B 4. By the product rule, |B 4 | = |B| 4 = = What is the number of IP addresses?

Example: Product Rule The number of length-n strings from an alphabet of size m is mn.mn. e.g. the number of length-n binary strings is 2 n the number of length-n strings formed by capital letters is 26 n In general we have: That is, |B n | = |B| n.

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} First we define the set of letters and the set of digits.

P6 =P6 = Example: Counting Passwords L ::= {a,b,…,z,A,B,…,Z} D ::= {0,1,…,9} We first count the number of passwords with a specific length. Let P n be the set of passwords with length n.

The set of Passwords: Example: Counting Passwords counting by partitioning by product rule by sum rule This is a common technique. Divide the set into disjoint subsets. Count each subset and add the answers.

Example: At Least One Seven How many # 4-digit numbers with at least one 7? count by 1st occurrence of 7: 7xxx + o7xx + oo7x + ooo7 where x represents any digit from 1 to 10, while o represent any digit from 1 to 10 except 7. Clearly, each number containing at least one 7 is in one of the above sets, and these sets are disjoint. Therefore, the answer to the question is: · · = 3439 Method 1: (counting by partitioning) The set of 4-digit numbers with 7 in the first digit. The set of 4-digit numbers with 7 in the second digit, but the first digit is not 7, and so on.

How many # 4-digit numbers with at least one 7? |4-digit numbers with at least one 7|= |4-digit numbers| - |those with no 7s| = 10 4 – 9 4 = 3439 Method 2: (counting the complement) Counting the complement is a useful technique. Example: At Least One Seven

Defective Dollars A dollar is defective if some digit appears more than once in the 6-digit serial number. How common are non-defective dollars?

Defective Dollars How common are non-defective dollars? 10 possible choices for the first digit, 9 possible choices for the second digit, and so on… So, there are 10x9x8x7x6x5 = serial numbers with all its digit different There are totally 10 6 = serial numbers. So, only about 15% of dollars are nondefective.

Generalized Product Rule Q a set of length-k sequences. If there are: n 1 possible 1 st elements in sequences, n 2 possible 2 nd elements for each first entry, n 3 possible 3 rd elements for each 1 st & 2 nd, … then, |Q| = n 1 · n 2 · n 3 · … · n k

Permutations 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? Ordering is important here. You can think of a permutation as a ranking of the elements. So the above question is asking how many rankings of an n-element set. Definition: A permutation of a set S is an ordered sequence that contains every element of S exactly once.

There are n choices for the first element. For each of these, there are n − 1 remaining choices for the second element. For every combination of the first two elements, there are n − 2 ways to choose the third element, and so forth. Thus, there are a total of n · (n − 1) · (n − 2) · · · 3 · 2 · 1 = n! permutations of an n-element set. How many permutations of an n-element set are there? Permutations Stirling’s formula (optional): This is called n factorial.

Suppose each digit is an element in {1,2,3,4,5,6,7,8,9}. How many 9-digit numbers are there where each nonzero digit appears once? Example: Permutation Each such number corresponds to a permutation of , and each permutation corresponds to such a number. So the numbers of such numbers is equal to the number of permutations of {1,2,3,4,5,6,7,8,9}. Hence there are exactly 9! such numbers. Alternatively, one can use the generalized product rule directly to obtain the same result, like what we did in nondefective dollars.

Combinations How many subsets of size k of an n-element set? Consider the set {1,2,3,4,5} where n=5. If k=2, then there are 10 possible subsets of size 2, i.e. {1,2}, {1,3}, {1,4}, {1,5}, {2,3}, {2,4}, {2,5}, {3,4}, {3,5}, {4,5}. If k=3, then there are also 10 possible subsets of size 3, i.e. {1,2,3}, {1,2,4}, {1,2,5}, {1,3,4}, {1,3,5} {1,4,5}, {2,3,4}, {2,3,5}, {2,4,5}, {3,4,5} Ordering is NOT important here. Think of it as the number of ways to form a committee of k people from n people.

There are n choices for the first element. For each of these, there are n − 1 remaining choices for the second element. There are n – k + 1 remaining choices for the last element. Thus, there are a total of n · (n − 1) · (n − 2) · · · (n – k + 1) to choose k elements. Combinations How many subsets of size k of an n-element set? So far we counted the number of ways to choose k elements, when the ordering is important. e.g. {1,2,3}, {1,3,2}, {2,1,3}, {2,3,1}, {3,1,2}, {3,2,1} will be counted as 6 different ways.

Thus, there are a total of n · (n − 1) · (n − 2) · · · (n – k + 1) ways to choose k elements, when the ordering is important. Combinations How many different ordering of k elements are (over)-counted? e.g. If we are forming subsets of size 3, then (1,2,3), (1,3,2), (2,1,3), (2,3,1), (3,1,2), (3,2,1) are counted as 6 different ways if the ordering is important. How many subsets of size k of an n-element set? In general, each subset of size k has k! different orderings, and so each subset is counted k! times in the above way of choosing k elements.

Thus, there are a total of n · (n − 1) · (n − 2) · · · (n – k + 1) ways to choose k elements, when the ordering is important. Each subset is counted, but is counted k! times, because each subset contributes k! different orderings to the above. So, when the ordering is not important, the answer is: Combinations How many subsets of size k of an n-element set? This is the shorthand for “n choose k”

Example: Team Formation There are m boys and n girls. How many ways are there to form a team with 3 boys and 3 girls? There are choices of 3 boys and choices for 3 girls. So by the product rule there are choices of such a team. If m < 3 or n < 3, then the answer should be zero. Don’t worry. We don’t like to trick you this way.

Example: Bit Strings with k Zeros How many n-bit sequences contain k zeros and (n − k) ones? We can think of this problem as choosing k positions (out of the n possible positions) and set them to zeroes and set the remaining positions to ones. So the above question is asking the number of possible positions of the k zeros, and the answer is:

Example: Unbalanced Bit Strings We say a bit string is unbalanced if there are more ones than zeroes or more zeros than ones. How many n-bit strings are unbalanced? If n is odd, then every n-bit string is unbalanced, and the answer is 2 n. If n is even, then the number of balanced strings is by choosing n/2 positions to zeroes. So the number of unbalanced n-bit strings is equal to the number of all n-bit strings minus the number of balanced strings, and so the answer is (counting the complement)

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?

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? One way to do this is to first map the problem into a problem of counting sequences.

A hand with a Four-of-a-Kind is completely described by a sequence specifying: 1. The value of the four cards. 2. The value of the extra card. 3. The suit of the extra card. There are 13 choices for (1), 12 choices for (2), and 4 choices for (3). By generalized product rule, there are 13x12x4 = 624 hands. Only 1 hand in about 4165 has a Four-of-a-Kind! Example 1: Four of a Kind

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?

There is a bijection between Full Houses and sequences specifying: 1. The value of the triple, which can be chosen in 13 ways. 2. The suits of the triple, which can be selected in (4 3) ways. 3. The value of the pair, which can be chosen in 12 ways. 4. The suits of the pair, which can be selected in (4 2) ways. By generalized product rule, there are Only 1 hand in about 634 has a Full House! Example 2: Full House

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?

1. The value of the first pair, which can be chosen in 13 ways. 2. The suits of the first pair, which can be selected (4 2) ways. 3. The value of the second pair, which can be chosen in 12 ways. 4. The suits of the second pair, which can be selected in (4 2) ways 5. The value of the extra card, which can be chosen in 11 ways. 6. The suit of the extra card, which can be selected in 4 ways. Number of Two pairs = Example 3: Two Pairs Double Count! So the answer is

Example 4: Every Suit How many hands contain at least one card from every suit? 1. The value of each suit, which can be selected in 13x13x13x13 ways. 2. The suit of the extra card, which can be selected in 4 ways. 3. The value of the extra card, which can be selected in 12 ways. Double count! So the answer is 13 4 x4x12/2 =