CS1800: More Counting. Professor Kevin Gold

Similar documents
CS100: DISCRETE STRUCTURES. Lecture 8 Counting - CH6

Chapter 7. Intro to Counting

Combinatorics: The Fine Art of Counting

Topics to be covered

Grade 7/8 Math Circles. Visual Group Theory

Counting (Enumerative Combinatorics) X. Zhang, Fordham Univ.

BMT 2018 Combinatorics Test Solutions March 18, 2018

Discrete Mathematics: Logic. Discrete Mathematics: Lecture 15: Counting

Lecture 2: Sum rule, partition method, difference method, bijection method, product rules

Compound Probability. Set Theory. Basic Definitions

Counting and Probability Math 2320

EECS 203 Spring 2016 Lecture 15 Page 1 of 6

CS 237: Probability in Computing

Introduction to Counting and Probability

Foundations of Computing Discrete Mathematics Solutions to exercises for week 12

CS1800: Permutations & Combinations. Professor Kevin Gold

Permutations and Combinations

Reading 14 : Counting

Sample Spaces, Events, Probability

Discrete Structures for Computer Science

Probability (Devore Chapter Two)

CSE 312: Foundations of Computing II Quiz Section #2: Inclusion-Exclusion, Pigeonhole, Introduction to Probability (solutions)

Lecture 14. What s to come? Probability. A bag contains:

CSE 312: Foundations of Computing II Quiz Section #1: Counting (solutions)

Grade 7/8 Math Circles. Visual Group Theory

IMLEM Meet #5 March/April Intermediate Mathematics League of Eastern Massachusetts

Discrete Mathematics and Probability Theory Fall 2016 Seshia and Walrand HW 8

1. Counting. 2. Tree 3. Rules of Counting 4. Sample with/without replacement where order does/doesn t matter.

Combinatorics. PIE and Binomial Coefficients. Misha Lavrov. ARML Practice 10/20/2013

CS1800: Intro to Probability. Professor Kevin Gold

Block 1 - Sets and Basic Combinatorics. Main Topics in Block 1:

The Product Rule The Product Rule: A procedure can be broken down into a sequence of two tasks. There are n ways to do the first task and n

CSE 312: Foundations of Computing II Quiz Section #2: Combinations, Counting Tricks (solutions)

CISC 1400 Discrete Structures

Exercises Exercises. 1. List all the permutations of {a, b, c}. 2. How many different permutations are there of the set {a, b, c, d, e, f, g}?

Solutions for the Practice Final

Counting. Chapter 6. With Question/Answer Animations

Chapter 4: Patterns and Relationships

Counting Things Solutions

In how many ways can we paint 6 rooms, choosing from 15 available colors? What if we want all rooms painted with different colors?

Notes on 4-coloring the 17 by 17 grid

Permutations and Combinations

The next several lectures will be concerned with probability theory. We will aim to make sense of statements such as the following:

Dependence. Math Circle. October 15, 2016

In how many ways can the letters of SEA be arranged? In how many ways can the letters of SEE be arranged?

Combinatorics: The Fine Art of Counting

MAT104: Fundamentals of Mathematics II Summary of Counting Techniques and Probability. Preliminary Concepts, Formulas, and Terminology

Discrete Mathematics and Probability Theory Spring 2018 Ayazifar and Rao Midterm 2 Solutions

CS1802 Week 3: Counting Next Week : QUIZ 1 (30 min)

Problem Set 2. Counting

1 Permutations. 1.1 Example 1. Lisa Yan CS 109 Combinatorics. Lecture Notes #2 June 27, 2018

Define and Diagram Outcomes (Subsets) of the Sample Space (Universal Set)

10-1. Combinations. Vocabulary. Lesson. Mental Math. able to compute the number of subsets of size r.

3 The multiplication rule/miscellaneous counting problems

I.M.O. Winter Training Camp 2008: Invariants and Monovariants

MATHEMATICS S-152, SUMMER 2005 THE MATHEMATICS OF SYMMETRY Outline #1 (Counting, symmetry, Platonic solids, permutations)

The Beauty and Joy of Computing Lab Exercise 10: Shall we play a game? Objectives. Background (Pre-Lab Reading)

Kenken For Teachers. Tom Davis January 8, Abstract

Section Introduction to Sets

Mathematics Competition Practice Session 6. Hagerstown Community College: STEM Club November 20, :00 pm - 1:00 pm STC-170

Mathematics. Programming

(1). We have n different elements, and we would like to arrange r of these elements with no repetition, where 1 r n.

Counting Methods and Probability

CIS 2033 Lecture 6, Spring 2017

CSE 312: Foundations of Computing II Quiz Section #2: Inclusion-Exclusion, Pigeonhole, Introduction to Probability

PERMUTATIONS AND COMBINATIONS

Probability. The MEnTe Program Math Enrichment through Technology. Title V East Los Angeles College

Solutions for Exam I, Math 10120, Fall 2016

Probability: introduction

3. (8 points) If p, 4p 2 + 1, and 6p are prime numbers, find p. Solution: The answer is p = 5. Analyze the remainders upon division by 5.

Chapter 2. Permutations and Combinations

2015 ACM ICPC Southeast USA Regional Programming Contest. Division 1

The study of probability is concerned with the likelihood of events occurring. Many situations can be analyzed using a simplified model of probability

Discrete Structures Lecture Permutations and Combinations

Permutations. Example 1. Lecture Notes #2 June 28, Will Monroe CS 109 Combinatorics

n! = n(n 1)(n 2) 3 2 1

Mat 344F challenge set #2 Solutions

Topspin: Oval-Track Puzzle, Taking Apart The Topspin One Tile At A Time

Making Middle School Math Come Alive with Games and Activities

Week 3-4: Permutations and Combinations

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute. Module 6 Lecture - 37 Divide and Conquer: Counting Inversions

Rosen, Discrete Mathematics and Its Applications, 6th edition Extra Examples

2359 (i.e. 11:59:00 pm) on 4/16/18 via Blackboard

Difference Engine. 1. Make a sensible definition of boring and determine how many steps it takes for this process to become boring.

1. For which of the following sets does the mean equal the median?

2. Combinatorics: the systematic study of counting. The Basic Principle of Counting (BPC)

MATH 215 DISCRETE MATHEMATICS INSTRUCTOR: P. WENG

Midterm practice super-problems

Here are two situations involving chance:

Board Question 1. There are 5 Competitors in 100m final. How many ways can gold silver and bronze be awarded? May 27, / 28

ACTIVITY 6.7 Selecting and Rearranging Things

Combinational Mathematics - I

Olympiad Combinatorics. Pranav A. Sriram

Objective: the student will gain speed and accuracy in letter recognition.

Junior Circle Meeting 5 Probability. May 2, ii. In an actual experiment, can one get a different number of heads when flipping a coin 100 times?

CS 361: Probability & Statistics

! Denver, CO! Demystifying Computing with Magic, continued

Answer each of the following problems. Make sure to show your work.

Problem A To and Fro (Problem appeared in the 2004/2005 Regional Competition in North America East Central.)

Math 475, Problem Set #3: Solutions

Transcription:

CS1800: More Counting Professor Kevin Gold

Today Dealing with illegal values Avoiding overcounting Balls-in-bins, or, allocating resources Review problems

Dealing with Illegal Values Password systems often have rules such as must have at least one special character We could think of this as a union of many sets (passwords with exactly one s.c., exactly two, ) but this turns out to be both tricky and cumbersome It s often better to find the size of the set of values that aren t valid, and subtract: A - B = A - B

Example of Subtracting Illegal Values Suppose our passwords consist of 8 letters, either uppercase or lowercase (52 possibilities). If the password must contain at least one uppercase letter, how many possible passwords are there? All passwords of 8 uc/lc characters: 52 8 All passwords with no uppercase letters: 26 8 Total possibilities: 52 8-26 8 All passwords no uc

Multiple Categories of Illegal Values Often there s more than one rule about what is illegal, and an item could be excluded for multiple reasons. Inclusion-Exclusion ( A U B = A + B - A B etc) is likely to come into play in these cases. Suppose we re counting 8-character passwords of letters (26*2 = 52), digits (10), and special characters (12) with at least 1 digit and 1 special character (repetition allowed) We want all passwords - bad passwords = all passwords - no digits U no special characters all passwords - ( no digits + no special - no digits & no special ) (52+10+12) 8 - ((52+12) 8 + (52+10) 8-52 8 )

A Tempting But Incorrect Approach to At Least One There s a strategy we often see students try to apply in this course that is incorrect. We ll illustrate on a small problem: How many 3-digit PIN numbers have at least one even digit? Strategy: Choose where the even digit goes: 3 ways. _ 5 possibilities for the even digit. 4 All the other numbers can be anything. 10 each. 4 3 4 3 * 5 * 10 * 10 = 1500 possibilities. Uh oh. That s more than 1000. But suppose we just subtract all PINs - all odd = 1000-5 3 = 875. This turns out to be correct but what went wrong the other way?

Be Careful Not to Choose Schemes that Double-Count Suppose we actually drew out the possibilities for the method we outlined in the previous slide. In one branch of our tree, we can choose: Pick first number even, pick even number = 4, pick 2nd=3, pick 3rd=4. 4 3 4 And in another branch of our tree, we can choose: Pick last number is even, pick even=4, pick 1st=4, pick 2nd=3. 4 3 4 These aren t different outcomes; they only differ in which digit we think is special. We have overcounted this number.

Be Careful Not to Choose Schemes that Double-Count Which place even? 1st even 2nd even 3rd even Even value? 4 Other value #1? 3 4 4 4 3 Other value #2? 4 3 4 [most of choice tree is abridged] 4 3 4 The method of multiplying choices assumes that different choice sequences lead to different outcomes. If that s not true, you need to correct for the overcounting or use a different method.

A Somewhat Messy Fix A fix for the method we just presented that didn t work is to use Inclusion-Exclusion. Our method essentially tried to count the union of three sets: first digit even, second digit even, third digit even. Those were the three initial options in the tree of choices. But as we just noted, these sets can overlap. In fact, all three can overlap (222, 224, ). EE E _ E EEE _EE E_E E E = even _ = other digit

A Somewhat Messy Fix Let A, B, C, be the sets where the first, second, or third digit is known to be even. Each of these has 5*10*10 possibilities (because 5 even digits). But they overlap. Each intersection like A B has two even digits, so 5*5*10 possibilities. A B C has three even digits; 5*5*5. AUBUC = A + B + C - A B - A C - B C + A B C = 5*10*10 + 10*5*10 + 10*10*5-5*5*10-5*10*5-10*5*5 + 5*5*5 = 500 + 500 + 500-250 - 250-250 + 125 = 875. It s not easier than the first method we saw, but it is correct! You ll never need to use 4+ set Inclusion-Exclusion in this course. If it comes to that, try subtracting the illegal set size instead.

Dealing With Overcounting Due to Symmetry There s going to be a dinner party of 8 guests sitting around a round table. How many ways are there to seat everyone around the table, assuming that we don t consider rotations of the table different? A G H B F H G C = E A F E D D C B

Dealing With Overcounting Due to Symmetry We can think of this as a permutation problem to start. There are 8! possible strings ABCDEFGH. Now we can mentally rotate through the equivalent positions to that. How many are there? One for each position for A; 8. G H F A E B D C ABCDEFGH H A Divide by this number, because every ordering will have this same issue. 8!/8 = 7!. B HABCDEFG

Dealing With Overcounting Due to Symmetry Another approach is to anchor the problem so that a choice that shouldn t matter is arbitrarily fixed. Imagine we tell A to just sit down somewhere; we ll think of how everyone will sit in relation to A. Now every possibility is genuinely different. There are 7! ways to rearrange the remaining guests, once we think of wherever A sits as the head of the table. A _ A _

Dealing With Overcounting Due to Symmetry If we also don t care about the difference between a seating arrangement and its mirror image, how many possibilities do we have? H A B B A H G C = C G F E D D E F

Dealing With Overcounting Due to Symmetry If we also don t care about the difference between a seating arrangement and its mirror image, how many possibilities do we have? Flipping the items to go clockwise instead of counterclockwise is just one counterpart for each ordering, if we also don t care about rotation. We divide the previous answer by two: 7!/2 H A B B A H G C = C G F E D D E F

Practicing a Choice of Approach: Counting Diagonals Let a diagonal be a line from a corner of an n-sided polygon to a non-adjacent corner. How many of these are there in general? The two diagonals from this corner

Practicing a Choice of Approach: Counting Diagonals One approach to this problem is a good - bad approach. There are C(N,2) = N(N-1)/2 ways to choose two corners. But N of these are bad, because they re actually sides. So we could say N(N-1)/2 - N.

Practicing a Choice of Approach: Counting Diagonals Another approach could be to think about our individual choices. N choices for our starting vertex, then I can pick any vertex that isn t adjacent. N(N-3) possibilities. Am I done, or have I overcounted?

Practicing a Choice of Approach: Counting Diagonals Another approach could be to think about our individual choices. N choices for our starting vertex, then I can pick any vertex that isn t adjacent. N(N-3) possibilities. I have overcounted, because I could choose vertex A then B, or B then A, and that would be the same diagonal. N(N-3)/2. This is the same result as the other approach; N(N-1)/2 - N = (N 2 - N)/2-2N/2 = (N 2-3N)/2 = N(N-3)/2.

Considering Resources to be Interchangeable: Balls-in-Bins Intro There are a variety of problems in which there s some interchangeable resource, like money or points, that is being allocated (handed out) You have 3 $20 bills to hand out to ten people, possibly handing more than one to the same person. How many ways are there to do that? Suppose you said 10 3 for the problem above, because we could encode the allocation of as a string like (Bob, Bob, Alice). 10*10*10 possibilities. But if that s the same result as (Alice, Bob, Bob), we ve overcounted. How do we handle this kind of problem?

Deriving Balls-in-Bins Let s solve an easier problem to illustrate. How many ways can I put 3 balls in 5 bins, if I don t consider the balls different? Thus the counts are all that matters, like (0,2,0,0,1) Imagine the setup for one of these allocations.

Deriving Balls-in-Bins We re going to try to turn this setup into a string representation that we can easily count. First, the bottom isn t doing anything useful.

Deriving Balls-in-Bins Next, we re going to drop the outer sides. I ll still be able to tell there s nothing in the leftmost bin, and a ball in the rightmost bin.

Deriving Balls-in-Bins Now I can change this to a string. I ll write for a divider and O for a ball. Notice that the number of dividers is one less than the original number of bins. I don t really need to record empty spaces. I can still tell when nothing is in a bin. Every character will be either a ball or a divider. OO O

Deriving Balls-in-Bins If you think about it, these strings are different exactly when the allocation to bins is different. OO O OO O

Deriving Balls-in-Bins If there s exactly one of these strings for each allocation, then we just need to count the number of strings with a valid number of balls and bin dividers. We can rephrase the problem as, How many strings have exactly 3 O s and 4 characters? We ve reduced the problem to one we can solve! How many strings do have 3 O s and 4 characters? OO O OO O

Deriving Balls-in-Bins The answer was that there are C(7,3) = 35 ways of choosing 3 characters to be O, and the rest. Equivalently, there are 4 ways to choose which characters are the. That s C(7,4) = C(7,3). Recall that these two ways of counting will give the same answer. OO O OO O Choose 3 characters to be O (or 4 to be )

The Balls-in-Bins Equation (Sometimes Called Stars and Bars ) If you re trying to find the number of ways you could distribute N indistinguishable items to R receptacles, the answer is C(N+R-1, N). The first number is the number of characters in the encoding - balls (N) plus bin dividers (R-1). The second number is the number of balls (N). You can equivalently choose where the bin dividers go: C(N+R-1, R-1).

Back to the First Example You have 3 $20 bills to hand out to 20 people any way you want, as long as each bill is given out. How many ways are there to do that? Here, the people are the bins - we care about differences between people - and the $20 bills are the balls - we don t care about differences between $20 bills. 19 dividers, 3 bills. C(22,3) = 1540. OO O A string that could encode $40 and $20 for persons 2 and 4

Slightly More Abstract Balls and Bins You re planning on buying 6 bags of Halloween candy, and there are 5 different brands at the store. How many ways are there to buy 6 bags? We could give a particular solution as a tuple of counts, like (3, 2, 1, 0, 0), where each count corresponds to a different candy brand. We should count the number of such tuples that add to 6. That makes this a balls-in-bins problem. You can think of the balls here as your $5 bills (the price) - indistinguishable - and the bins as the candy manufacturers. 6 balls, 4 dividers = C(6+4,4) = 10*9*8*7/(4*3*2) = 210

Minimum Allocations I m dividing $5000 among 3 people, in increments of $1000, but I also need to give everyone at least $1000. What should I do about that?

Minimum Allocations I m dividing $5000 among 3 people, in increments of $1000, but I also need to give everyone at least $1000. What should I do about that? Essentially, $3000 is spoken for, leaving only $2000 to divide up. I can just count the number of ways to distribute that. 3 people = 2 bins, 2 balls of $1000 each. C(4,2) = 6 ways to do it. OO O O O O OO O O OO (3,1,1) (2,2,1) (2,1,2) (1,3,1) (1,2,2) (1,1,3)

Trying to Decide How To Divide Up a Plane I have 30 rows of an airplane I m designing, and I m trying to decide how many of them should be first class, economy plus, or economy. Assuming these sections are always in the same order on the plane, and just differ in their number of rows (which can be 0), how many ways to do this?

Noticing Similarities to Our Encoding I have 30 rows of an airplane I m designing, and I m trying to decide how many of them should be first class, economy plus, or economy. How many ways to do this? This is an instance where the problem should just directly remind us of our balls-in-bins encoding, even if thinking of rows as balls (etc) is a little weird. 2 dividers and 30 rows: C(32,2) = 496 OOOO O

Practice Balls-in-Bins Suppose there s a video game where, every time a player gets an experience point, there are 3 scores that can be improved with it; so after 10 such points, the player might have Strength 3, Trapmaking 3, and Survival 4. How many possible builds (allocations of points) are there with 10 points?

Practice Balls-in-Bins Suppose there s a video game where, every time a player gets an experience point, there are 3 scores that can be improved with it; so after 10 such points, the player might have Strength 3, Trapmaking 3, and Survival 4. How many possible builds are there with 10 points? The scores to improve are the 3 bins; so 2 bin dividers. C(10+2, 2) = C(12,2) = 12*11/2 = 66.

A Mix of Practice Problems How many 6-character passwords have exactly 2 digits, 2 letters (lower or upper case), and 2 special characters (12 possible)? How many possible deals are there of 2 cards to each of 4 players, if I don t care about order in the hand, but I do care who got what cards? What if I don t care who got what cards? If I flip a coin ten times, how many possibilities have exactly the same number of heads and tails? How many don t have the same number? How many of those have more heads than tails? How many ways are there to interleave ABCDE and 12345 while keeping the letters in order and the numbers in order?

A Mix of Practice Problems How many 6-character passwords have exactly 2 digits, 2 letters (lower or upper case), and 2 special characters (12 possible)? Hint: Choose where everything goes, then fill things in. How many possible deals are there of 2 cards to each of 4 players, if I don t care about order in the hand, but I do care who got what cards? What if I don t care who got what cards? Hint (2nd part): How many ways could you rearrange the same 4 hands? If I flip a coin ten times, how many possibilities have exactly the same number of heads and tails? How many don t have the same number? How many of those have more heads than tails? Hint: Choose where the heads are in the sequence; then, think about how to avoid doing anything tedious. How many ways are there to interleave ABCDE and 12345 while keeping the letters in order and the numbers in order? Hint: After your first choice, what s left to choose?

The Password Problem How many 6-character passwords have exactly 2 digits, 2 letters (lower or upper case), and 2 special characters (12 possible)? Choose where digits go: C(6,2) Choose where letters go: C(4,2) Nothing left to choose for character positions Choose the digits: 10*10 Choose the letters: 52*52 Choose the special characters: 12*12 C(6,2)*C(4,2)*10 2 *52 2 *12 2

The Card Problem How many possible deals are there of 2 cards to each of 4 players, if I don t care about order in the hand, but I do care who got what cards? What if I don t care who got what cards? Choose the 4 hands: C(52,2)*C(50,2)*C(48,2)*C(46,2) (other strategies are possible) Don t care about who got them: Divide by 4!

The Coin Problem If I flip a coin ten times, how many possibilities have exactly the same number of heads and tails? How many don t have the same number? How many of those have more heads than tails? Think of the flips as encoded as a string, like TTTTTHHHHH There are C(10,5) ways to pick which ones are heads, if we have a tie (so exactly 5 heads) Since there are 2 10 possible flips in general, there are 2 10 - C(10,5) other possibilities By symmetry, half of those possibilities have heads ahead

The Interleaving Problem How many ways are there to interleave ABCDE and 12345 while keeping the letters in order and the numbers in order? Choose where the letters go among the 10 characters: C(10,5) The order of both sequences is determined, so there s nothing left to choose.