Counting. Mukulika Ghosh. Fall Based on slides by Dr. Hyunyoung Lee

Similar documents
Lecture 4: Counting, Pigeonhole Principle, Permutations, Combinations Lecturer: Lale Özkahya

Discrete Mathematics & Mathematical Reasoning Chapter 6: Counting

Slides for a Course Based on the Text Discrete Mathematics & Its Applications (5 th Edition) by Kenneth H. Rosen

Counting. Math 301. November 24, Dr. Nahid Sultana

Counting Methods. CSE 191, Class Note 05: Counting Methods Computer Sci & Eng Dept SUNY Buffalo

Counting. Spock's dilemma (Walls and mirrors) call it C(n,k) Rosen, Chapter 5.1, 5.2, 5.3 Walls and Mirrors, Chapter 3 10/11/12

Introduction to Decision Sciences Lecture 11

Announcements. CSE 321 Discrete Structures. Counting. Counting Rules. Important cases of the Product Rule. Counting examples.

Binomial Coefficient Identities/Complements

Recursive Definitions

Statistical Inference

F 2k 1 = F 2n. for all positive integers n.

Basic counting techniques. Periklis A. Papakonstantinou Rutgers Business School

CS 210 Foundations of Computer Science

Notes. Combinatorics. Combinatorics II. Notes. Notes. Slides by Christopher M. Bourke Instructor: Berthe Y. Choueiry. Spring 2006

CSCE 222 Discrete Structures for Computing. Dr. Hyunyoung Lee

An Introduction to Combinatorics

Solutions to Homework Problems

The Inclusion Exclusion Principle

MATH 10B METHODS OF MATHEMATICS: CALCULUS, STATISTICS AND COMBINATORICS

CS Foundations of Computing

Combinatorics. But there are some standard techniques. That s what we ll be studying.

6 CARDINALITY OF SETS

Math.3336: Discrete Mathematics. Combinatorics: Basics of Counting

1. Determine (with proof) the number of ordered triples (A 1, A 2, A 3 ) of sets which satisfy

Solutions for Chapter Solutions for Chapter 17. Section 17.1 Exercises

Equivalence of Propositions

We might divide A up into non-overlapping groups based on what dorm they live in:

CSCE 222 Discrete Structures for Computing. Review for Exam 2. Dr. Hyunyoung Lee !!!

Named numbres. Ngày 25 tháng 11 năm () Named numbres Ngày 25 tháng 11 năm / 7

Discrete Mathematics 2007: Lecture 5 Infinite sets

Discrete Probability

Chapter Summary. Sets (2.1) Set Operations (2.2) Functions (2.3) Sequences and Summations (2.4) Cardinality of Sets (2.5) Matrices (2.

Counting Strategies: Inclusion-Exclusion, Categories

Probability. Part 1 - Basic Counting Principles. 1. References. (1) R. Durrett, The Essentials of Probability, Duxbury.

Sets are one of the basic building blocks for the types of objects considered in discrete mathematics.

Unit I (Logic and Proofs)

Definition: Let S and T be sets. A binary relation on SxT is any subset of SxT. A binary relation on S is any subset of SxS.


Chapter 7. Inclusion-Exclusion a.k.a. The Sieve Formula

Discrete Mathematics with Applications MATH236

The integers. Chapter 3

Homework 7 Solutions, Math 55

Chapter Summary. Sets The Language of Sets Set Operations Set Identities Functions Types of Functions Operations on Functions Computability

CSCE 222 Discrete Structures for Computing

Name (please print) Mathematics Final Examination December 14, 2005 I. (4)

CS 2336 Discrete Mathematics

2 - Strings and Binomial Coefficients

Discrete Structures for Computer Science: Counting, Recursion, and Probability

SETS AND FUNCTIONS JOSHUA BALLEW

Some Review Problems for Exam 3: Solutions

MATH 802: ENUMERATIVE COMBINATORICS ASSIGNMENT 2

A function is a special kind of relation. More precisely... A function f from A to B is a relation on A B such that. f (x) = y

Some Review Problems for Exam 3: Solutions

Advanced Counting Techniques. Chapter 8

Notes Week 2 Chapter 3 Probability WEEK 2 page 1

The Inclusion Exclusion Principle and Its More General Version

Permutations and Combinations

Lecture 3: Miscellaneous Techniques

Advanced Counting Techniques

Department of Computer Science University at Albany, State University of New York Solutions to Sample Discrete Mathematics Examination II (Fall 2007)

Counting Strategies: Inclusion/Exclusion, Categories

Sets. A set is a collection of objects without repeats. The size or cardinality of a set S is denoted S and is the number of elements in the set.

Pascal s Triangle and III.3 Answers

CSCE 222 Discrete Structures for Computing. Review for the Final. Hyunyoung Lee

MATH 363: Discrete Mathematics

CSE 20 DISCRETE MATH. Fall

Trees/Intro to counting

2.6 Tools for Counting sample points

CSCI 150 Discrete Mathematics Homework 5 Solution

1 Basic Combinatorics

1 The Basic Counting Principles

Lecture 10: Everything Else

Discrete Mathematics for CS Spring 2007 Luca Trevisan Lecture 27

Notes on Sets, Relations and Functions

Number Theory and Counting Method. Divisors -Least common divisor -Greatest common multiple

Lecture 6: The Pigeonhole Principle and Probability Spaces

MATH 402 : 2017 page 1 of 6

Chapter 1 : The language of mathematics.

Combinations. April 12, 2006

CITS2211 Discrete Structures (2017) Cardinality and Countability

Counting with Categories and Binomial Coefficients

Warm-up Quantifiers and the harmonic series Sets Second warmup Induction Bijections. Writing more proofs. Misha Lavrov

Automata and Languages

BOOLEAN ALGEBRA INTRODUCTION SUBSETS

Updated Jan SESSION 4 Permutations Combinations Polynomials

Introduction to Decision Sciences Lecture 10

6 Permutations Very little of this section comes from PJE.

Contents. Counting Methods and Induction

Counting Strategies: Inclusion/Exclusion, Categories

MATH 61-02: PRACTICE PROBLEMS FOR FINAL EXAM

0 Logical Background. 0.1 Sets

Combinatorics & Discrete Probability Theory

{ 0! = 1 n! = n(n 1)!, n 1. n! =

1 Functions, relations, and infinite cardinality

CS Discrete Mathematics Dr. D. Manivannan (Mani)

Part IA Numbers and Sets

With Question/Answer Animations. Chapter 2

Notes on counting. James Aspnes. December 13, 2010

MATH 220 (all sections) Homework #12 not to be turned in posted Friday, November 24, 2017

Transcription:

Counting Mukulika Ghosh Fall 2018 Based on slides by Dr. Hyunyoung Lee

Counting Counting The art of counting is known as enumerative combinatorics. One tries to count the number of elements in a set (or, typically, simultaneously count the number of elements in a series of sets). Example Count the number of successful outcomes of an experiments The basic principles are extremely simple, but counting is a nontrivial task. Mukulika Ghosh Parasol Lab - Texas A&M University 2/41

Product Rule Product Rule Suppose that a task can be broken down into a sequence of two subtasks. If there are n 1 ways to solve subtask 1 and n 2 ways to solve subtask 2, then there must be n 1 n 2 ways to solve the task. Let S 1 and S 2 be sets describing the ways of the first and second subtasks, so n 1 = S 1 and n 2 = S 2. Then S 1 S 2 = n 1 n 2 Example How many rows are there in a truth table for a statement with n variables? Each variable can have 2 possible truth value. Hence for n variables, there can be 2 2...(ntimes) = 2 n Mukulika Ghosh Parasol Lab - Texas A&M University 3/41

Exercise Exercise How many possible SSN numbers can there be? (Remember ssn number is denoted as XXX-XX-XXXX) Mukulika Ghosh Parasol Lab - Texas A&M University 4/41

Product rule in Functions Product rule in Functions How many functions are there from a set with m elements to a set with n elements? For each of the m elements in the domain, we can choose any element from the codomain as a function value. Hence, by the product rule, we get n n... n = n m different functions Mukulika Ghosh Parasol Lab - Texas A&M University 5/41

Product rule in Functions How many injective functions are there from a set with m elements to a set with n elements? If m > n, then there are 0 injective functions. If m n, then there are n ways to choose the value for the first element in the domain, n 1 ways to choose the value for the second element (as one has to avoid the previously chosen value), n 2 for the third element of the domain and so forth. Thus, we have n(n 1)...(n m + 1) injective functions in this case. Mukulika Ghosh Parasol Lab - Texas A&M University 6/41

Sum Rule Sum Rule If a task can be done either in one of n 1 ways or in one of n 2 ways, where none of the set of n 1 ways is the same as any of the set of n 2 ways, then there are n 1 + n 2 ways to do the task. Let S 1 and S 2 be disjoint sets (i.e, S 1 S 2 = with n 1 = S 1 and n 2 = S 2. Then S 1 S 2 = n 1 + n 2. Example: A student can choose a computer project from one of three lists. The three lists contain 23, 15, and 19 possible projects, respectively. No project is on more than one lists. How many possible projects are there to choose from? There are 23 + 15 + 19 = 57 projects to choose from. Mukulika Ghosh Parasol Lab - Texas A&M University 7/41

Example Example How many sequences of 1s and 2s sum to n? Let s n denotes such sequence. s 0 = 1 = empty s 1 = 1 = {(1)} s 2 = 2 = {(1, 1), (2)} s 3 = 3 = {(1, 1, 1), (1, 2), (2, 1)} s 4 = 5 = {(1, 1, 1, 1), (1, 1, 2), (1, 2, 1), (2, 1, 1), (2, 2)} So for s n contains s n 1 sequences that starts with 1 and s n 2 sequences starting with 2. Mukulika Ghosh Parasol Lab - Texas A&M University 8/41

Example s n = s n 1 + s n 2 which is same as definition of Fibonacci numbers Mukulika Ghosh Parasol Lab - Texas A&M University 9/41

Exercise Exercise How many 5 letters word can be created that starts with a vowel? Mukulika Ghosh Parasol Lab - Texas A&M University 10/41

IPv4 IPv4 Computer addresses belong to one of the following 3 types: Class A: address contains a 7-bit netid 1 7, and a 24-bit hostid Class B: address has a 14-bit netid and a 16-bit hostid. Class C: address has 21-bit netid and an 8-bit hostid. Mukulika Ghosh Parasol Lab - Texas A&M University 11/41

IPv4 Hostids that are all 0s or all 1s are not allowed How many valid computer addresses are there? Number of address = (Class A) + (Class B) + (Class C) By sum rule, Class A = (valid netids) (valid hostids) by Product rule = (2 7 1).(2 2 4 2) Class B = 2 1 4 (2 1 6 2) Mukulika Ghosh Parasol Lab - Texas A&M University 12/41

IPv4 Class C = 2 2 1 (2 8 2) In total, 3, 737, 091, 842 (3.7 billion IP addresses) Mukulika Ghosh Parasol Lab - Texas A&M University 13/41

Subtraction Rule Subtraction Rule If a task can be done in either n 1 ways or n 2 ways, then the number of ways to do the task is n 1 + n 2 minus the number of ways to do the task that is common to the two different ways. Principle of Inclusion-and-Exclusion: Let S1 and S2 be sets. Then S 1 S 2 = S 1 + S 2 S 1 S 2 Mukulika Ghosh Parasol Lab - Texas A&M University 14/41

Example: Example: How many bit strings of length 8 either start with a 1 bit or end with the last two bits equal to 00? Let S 1 be the number of strings that start with a 1 bit = 2 7. Let S 2 be the number of strings that end with 00 = 2 6. The number of strings that start with 1 and end with 00 = 2 5. Hence, in total = 2 7 + 2 6 2 5 = 160 Mukulika Ghosh Parasol Lab - Texas A&M University 15/41

Example: Consider simple rules for passwords. Passwords must be 2 characters long. Each character must be 1. a letter [a-z], 2. a digit [0-9], or 3. one of the 10 special characters Mukulika Ghosh Parasol Lab - Texas A&M University 16/41

Example: Each password must contain at least 1 digit or special character. Number of password with 1 digit or special character in first character = (10 + 10)(10 + 10 + 26) = 20 46 Number of password with 1 digit or special character in second character = 20 46 Number of password with either a digit or special character in both places = 20 20 Total = 2(20 46) 20 20 = 1440 Mukulika Ghosh Parasol Lab - Texas A&M University 17/41

Exercise Exercise How many strings of two ASCII characters contain the character @ at least once? (Note: There 128 different ASCII characters) Mukulika Ghosh Parasol Lab - Texas A&M University 18/41

Pigeonhole Principle Pigeonhole Principle If k + 1 objects are assigned to k places, then at least one place must be assigned at least two objects. Mukulika Ghosh Parasol Lab - Texas A&M University 19/41

Generalized Pigeonhole Principle Generalized Pigeonhole Principle If N > k objects are assigned to k places, then at least one place must be assigned at least N k objects. Proof Suppose every place has less than N k objects; so at most N k 1 objects per place. Total number of objects = k( N k 1) k( N k 1) < k(( N k + 1) 1) = k( N k ) = N Mukulika Ghosh Parasol Lab - Texas A&M University 20/41

Generalized Pigeonhole Principle So there are fewer than N objects in total which contradicts the assumption that there are N objects. Mukulika Ghosh Parasol Lab - Texas A&M University 21/41

Example Example 1. Among 90 students, there are at least 90/12 = 8 who have birthdays in same month. 2. Ten points are given within a square of unit size. Then there are two points that are closer to each other than 0.48. Partition the square in 3 3 grid of 9 cells. By Pigeonhole principle, one grid must contain atleast 10/9 = 2 points. The points are far apart when they are at the opposite corners of the diagonal. Therefore, the points can be at most 1 3 2 + 1 3 2 < 0.48 apart. Mukulika Ghosh Parasol Lab - Texas A&M University 22/41

Exercise Exercise What is the minimum number of students, each of whom comes from one of the 50 states, who must be enrolled in a university to guarantee that there are at least 10 who come from the same state? Mukulika Ghosh Parasol Lab - Texas A&M University 23/41

Counting in Two Different Ways Counting in Two Different Ways When two different formulas enumerate the same set, then they must be the same. In other words, you count the elements of the set in two different ways. Mukulika Ghosh Parasol Lab - Texas A&M University 24/41

Counting in Two Different Ways Example: Consider a grid of (n+1) (n+1) = (n + 1) 2 points. Similarly, we can count the number of points as total of points in all the diagonals (main, upper and lower): n n (n + 1) 2 = (n + 1) + i + i i=1 i=1 n (n + 1) 2 (n + 1) = 2 i i=1 n(n + 1) 2 n = i i=1 Mukulika Ghosh Parasol Lab - Texas A&M University 25/41

Permutation Permutations and Combination Permutation Let S be a set with n elements. An ordered arrangement of r elements of S is called an r permutation of S. A permutation of S is an n permutation. The number of r permutations of a set with n elements is denoted by P (n, r). Example: S = {1, 2, 3, 4}. Then (2, 4, 3) and (4, 3, 2) are two distinct 3 permutations of S. Note: Order is important. Mukulika Ghosh Parasol Lab - Texas A&M University 26/41

Number of r-permutations Number of r-permutations Let n and r be positive integers, r n. Then P (n, r) = n(n 1)...(n r + 1). Proof: Let S be a set with n elements. The first element of the permutation can be chosen in n ways, the second in n 1 ways,..., the r th element can be chosen in (n r + 1) ways. By the product rule, the total number becomes n(n 1)...(n r + 1) Mukulika Ghosh Parasol Lab - Texas A&M University 27/41

Number of r-permutations Let n be a positive integer, and r an integer in the range 0 r n. Then P (n, r) = n! (n r)! Proof: For r in the range 1 r n, = n(n 1)...(n r + 1) n! (n r)! For r = 0, we have P (n, 0) = 1, which equals n!/(n 0)! = n!/n! = 1 Mukulika Ghosh Parasol Lab - Texas A&M University 28/41

Number of r-permutations Example How many permutations of the letters ABCDEFGH contain the string ABC? Let us regard ABC, D, E, F, G, and H as blocks. Any permutation of these 6 blocks will yield a valid permutation containing ABC. Therefore, we have 6! = 720 permutations of the letters ABCDEFGH that contain ABC as a block. Mukulika Ghosh Parasol Lab - Texas A&M University 29/41

Combinations Combinations Let S be a set of n elements. An r combination of S is a subset of r elements from S. Note: Order does NOT matter here The number of r combinations of a set S with n elements is denoted by C(n, r) or ( n) k Mukulika Ghosh Parasol Lab - Texas A&M University 30/41

Number of Combinations Number of Combinations The number of r combinations of a set with n elements is given by ( ) n = r n! (n r)!r! Proof. We can form all r permutations of a set with n elements by first choosing an r combination and then ordering the r elements in all possible ways. Thus, P (n, r) = C(n, r)p (r, r) Hence, C(n, r) = P (n,r) P (r,r) = n!/(n r)! r!/(r r)! Since (r r)! = 0! = 1, this yields C(n, r) = n! (n r)!r! Mukulika Ghosh Parasol Lab - Texas A&M University 31/41

Exercise Exercise There are six different candidates for governor of a state. In how many different orders can the names of candidates be printed on a ballot? Mukulika Ghosh Parasol Lab - Texas A&M University 32/41

Binomial Coefficient Identity Binomial Coefficient Identity It can be proved that ( n) ( r = n ) n r Proof: Let S be a set with n elements. Each subset A of S has its corresponding complement A c, which contains the elements of S that are not contained in A. By double counting: The number C(n, r) of subsets of cardinality r of S corresponds to the number of complements of subsets of cardinality r in S. Since A = r iff A c = n r, the complements of subsets of cardinality r of S correspond to subsets of cardinality n r of S. Thus, C(n, r) = Number of r subsets of S = Number of complements of r subsets of S = C(n, n r), as claimed Mukulika Ghosh Parasol Lab - Texas A&M University 33/41

Counting Subset Identity Counting Subset Identity For any non-negative integer n, we have n k=0 ( ) n = 2 n k Proof: Let S be a set with n elements. The number of subsets of S is 2 n. The number of subsets with 0, 1, 2,..., n elements is given by ( n 0 )( n 1 )( n 2 ) ( ) n... n Mukulika Ghosh Parasol Lab - Texas A&M University 34/41

Counting Subset Identity Since subsets of S need to have between 0 and n elements, the claim follows Mukulika Ghosh Parasol Lab - Texas A&M University 35/41

Binomial Theorem Binomial Theorem Let x and y be variables. Let n be a non-negative integer. Then (x+y) n = n ) x k y n k k=0 ( n k Proof: Let us expand the left hand side. The terms of the product in expanded form are x k y n k for 0 k n. To obtain the term x k y n k one must choose k x s from the n(x + y) terms. There are ( n k) ways to do that. Mukulika Ghosh Parasol Lab - Texas A&M University 36/41

Binomial Coefficient Identity Binomial Coefficient Identity Let n be a positive integer. Then ( ) n n ( 1) k = 0 k k=0 Proof: We have 0 = 0 n = ( 1 + 1) n. Expanding the right hand side with the help of the binomial theorem, we obtain the claim. This implies that the number of subsets with an even number of elements is equal to the number of subsets with an odd number of elements. Mukulika Ghosh Parasol Lab - Texas A&M University 37/41

Pascal s Identity Pascal s Identity Let n and k be positive integers with n k. Then ( ) n + 1 = k ( ) n + k 1 ( ) n k Proof: We are going to prove this by counting the number of subsets with k elements of a set T with n + 1 elements in two different ways: First way of counting: The set T clearly contains ( n+1) k subsets of size k Mukulika Ghosh Parasol Lab - Texas A&M University 38/41

Pascal s Identity Second way of counting: Recall that T is a set with n + 1 elements. Let us consider an element t of T. We will count the subsets of T of size k that : (a) contain the element t, and (b) do not contain the element t. (a) There are ( n k 1) subsets of T that contain t, since t is already chosen, but the remaining k 1 elements need to be chosen from T {t}, a set of size n. (b) There are ( n k) subset of T not containing t, since one can choose any k elements from the set T {t} with n elements. Since the two cases are exhaustive, C(n + 1, k) = C(n, k 1) + C(n, k) Mukulika Ghosh Parasol Lab - Texas A&M University 39/41

Vandermonde s Identity Vandermonde s Identity Let m, n, and r be non-negative integers, r min(n, m). Then ( ) m + n = r ( )( ) r m n r k k k=0 In particular, when choosing m = n = r, we get ( ) 2n = n n k=0 ( ) 2 n k Mukulika Ghosh Parasol Lab - Texas A&M University 40/41

Vandermonde s Identity Proof: We will prove this by counting in two different ways. Let S and T be two disjoint sets with m = S and n = T. Counting in the first way: We can choose r elements from S T in ( n+m) r ways. Counting in the second way: We can pick r elements from S T by picking r k elements from S and k elements from T, where 0 k r. By the product rule, this can be done in ( m n r k)( k) ways. Hence the total number of ways to pick r elements from S T is ( )( ) r m n r k k k=0 Mukulika Ghosh Parasol Lab - Texas A&M University 41/41