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.

Slides:



Advertisements
Similar presentations
Discrete Probability Rosen 5.1.
Advertisements

Combinatorics & Probability Section 3.4. Which Counting Technique? If the problem involves more than one category, use the Fundamental Principle of Counting.
Beginning Probability
CSC 2510 Test 3 1. Give the names of the formula or rule that provides the answer for each of the following problems. Do not try to solve the problems!
Counting and Gambling Section 4Objectives: Understand how to use the fundamental counting principle to analyze counting problems that occur in gambling.
9.5 Counting Subsets of a Set: Combinations
Great Theoretical Ideas in Computer Science for Some.
Mathematics in OI Bill Kwok 20/3/2010 HKOI 2010 Intermediate Training Acknowledgement: References and slides are extracted from: 1. Math in OI, ,
Basic Permutations and Combinations
5.3 Permutations and Combinations
Counting. Counting = Determining the number of elements of a finite set.
Counting Chapter 6 With Question/Answer Animations.
Counting Chapter 6 With Question/Answer Animations.
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 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,
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.
Combinations We should use permutation where order matters
Discrete Mathematics Lecture 5
Discrete Mathematics Lecture 6 Alexander Bukharovich New York University.
1 More Counting Techniques Possibility trees Multiplication rule Permutations Combinations.
Chapter 8 The principle of Inclusion and Exclusion Yen-Liang Chen Dept of Information Management National Central University.
Combinatorics 3/15 and 3/ Counting A restaurant offers the following menu: Main CourseVegetablesBeverage BeefPotatoesMilk HamGreen BeansCoffee.
Chapter The Basics of Counting 5.2 The Pigeonhole Principle
Counting. Why counting  Determine the complexity of algorithms To sort n numbers, how many instructions are executed ?  Count the number of objects.
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 =
Basic Counting Lecture 12: Oct 28. This Lecture We will study some basic rules for counting. Sum rule, product rule, generalized product rule Permutations,
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 The Basics of Counting 5.2 The Pigeonhole Principle
Binomial Coefficients, Inclusion-exclusion principle
9.3 Addition Rule. The basic rule underlying the calculation of the number of elements in a union or difference or intersection is the addition rule.
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.
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.
1 Counting by Mapping Lecture 15: Nov 4 A B …… f.
The Pigeonhole Principle. The pigeonhole principle Suppose a flock of pigeons fly into a set of pigeonholes to roost If there are more pigeons than pigeonholes,
1 Melikyan/DM/Fall09 Discrete Mathematics Ch. 6 Counting and Probability Instructor: Hayk Melikyan Today we will review sections 6.6,
Counting II: Recurring Problems And Correspondences Great Theoretical Ideas In Computer Science John LaffertyCS Fall 2005 Lecture 7Sept 20, 2005Carnegie.
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.
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.
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.
L14: Permutations, Combinations and Some Review EECS 203: Discrete Mathematics.
Section The Pigeonhole Principle If a flock of 20 pigeons roosts in a set of 19 pigeonholes, one of the pigeonholes must have more than 1 pigeon.
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.
L14: Permutations, Combinations and Some Review
CSC 321: Data Structures Fall 2015 Counting and problem solving
CSE15 Discrete Mathematics 04/19/17
Sequences, Series, and Probability
COCS DISCRETE STRUCTURES
CSC 321: Data Structures Fall 2016 Counting and proofs
Counting Chapter 6 With Question/Answer Animations
Discrete Math for CS CMPSC 360 LECTURE 27 Last time: Counting.
Mathematics for Computer Science MIT 6.042J/18.062J
Mathematics for Computer Science MIT 6.042J/18.062J
Basic Counting.
Combinatorics.
CSE 321 Discrete Structures
CSC 321: Data Structures Fall 2018 Counting and proofs
Basic Counting Lecture 9: Nov 5, 6.
Inclusion-Exclusion Principle
Counting I: Choice Trees and Correspondences
Presentation transcript:

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 to factor an integer?

How many different configurations for a Rubiks cube? How many weighings to nd the one counterfeit among 12 coins? How many different chess positions after n moves? Counting in Games

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

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.

Product Rule: Counting Strings The number of length-4 strings from alphabet B ::= {0,1} = |B B B B| = 2 · 2 · 2 · 2 = 2 4 The number of length-n strings from an alphabet of size m is mn.mn.

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}

Example: Counting Passwords

At Least One Seven How many # 4-digit numbers with at least one 7?

At Least One Seven How many # 4-digit numbers with at least one 7? count by 1st occurrence of 7: 7xxx + o7xx + oo7x + ooo · · = 3439 |4-digit numbers with at least one 7|= |4-digit numbers| |those with no 7s| = 10 4 – 9 4 = 3439 Method 1: Method 2:

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

Defective Dollars How common are nondefective dollars?

Defective Dollars How common are nondefective dollars? 10 possible choices for the first digit, 9 possible choices for the second digit, and so on… So, there are 10x9x8x7x6x5 = serial number 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

Example How many four-digit integers are divisible by 5?

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?

Permutations Stirlings formula:

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 Stirlings formula:

How many subsets of r elements of an n-element set? Combinations

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 k elements of an n-element set? Any ordering of the first k elements give the same subset!

How many subsets of r elements of an n-element set? Combinations

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?

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?

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

Binomial Theorem

Proving Identities

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.

Proving Identities Pascals Formula

Combinatorial Proof

More Combinatorial Proof

Let S be all n-card hands that can be dealt from a deck containing n red cards (numbered 1,..., n) and 2n black cards (numbered 1,..., 2n). The right hand side = # of ways to choose n cards from these 3n cards. The left hand side = # of ways to choose r cards from red cards x # of ways to choose n-r cards from black cards = # of ways to choose n cards from these 3n cards = the right hand side.

If sets A and B are disjoint, then |A B| = |A| + |B| AB What if A and B are not disjoint? Sum Rule

For two arbitrary sets A and B AB Inclusion-Exclusion (2 sets)

How many integers from 1 through 1000 are multiples of 3 or multiples of 5?

AB C |A B C| = |A| + |B| + |C| – |A B| – |A C| – |B C| + |A B C| 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?

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 Inclusion-Exclusion (n sets)