You are on page 1of 26

Counting Subsets

with Repetitions
ICS 6C
Sandy Irani
Multi-sets
• A Multi-set can have more than one copy of
an item.
– Order doesn’t matter
– The number of elements of each type does
matter:
{1, 2, 2, 2, 3, 4, 5, 7, 7}
{1, 2, 2, 2, 3, 4, 7, 5, 7}
{1, 2, 2, 3, 4, 5, 7, 7}
Counting Problem with Multi-sets
• You are purchasing a dozen donuts.
• The bakery has four varieties of donuts:
Chocolate, Glazed, Jelly, Maple
• Donuts of the same variety are the same.
• There is an unlimited supply of each variety.
(For this problem at least 12 of each variety).

• How many ways to select the donuts?


– Order doesn’t matter. All that matters is how many of
each variety you have in the box when you leave the
bakery .
Donut Selection
• Sample selection:
C C C G J J J J J J M M

 3 chocolate
 1 glazed
 6 jelly
 2 maple
Donut Selection
• Binary encoding that uniquely specifies a
selection of donuts:
• Bijection:
Selection of donuts ↔ Binary code word

Will count the


Number of valid
binary code words
Encoding Donut Selection
Select any
C C C G J J J J J J M M ordering of
the varieties:
1. Chocolate
2. Glazed
3. Jelly
4. Maple
Encoding Donut Selection
G G G G J J J J J J M M

Every code word has 12 0’s and 3 1’s: total of 15 bits


Encoding Donut Selection
C C C C J J J J J J M M

Every code word has 12 0’s and 3 1’s: total of 15 bits

Number of Number of
donuts varieties - 1
Code Words to Donut Selections
• 001000101000000

• 100010000100000

• 110000000000001
Donut Selection
• Bijection:
• Ways to select 12 donuts from 4 varieties
• Binary strings with 12 0’s and (4-1) 1’s

• # of ways to select 12 donuts from 4 varieties


12  4  1 15 
     
 4 1   3 
Selecting from Varieties
• The number of ways to select n items from a
set of m varieties
Items from the same variety are identical
There is at least n items from each variety

 n  m  1
  
 m 1 

(This is still true if n > m, m < n, or m = n)


Balls into Bins
• How many ways to throw n identical balls into
m distinct bins?

Bin 1 Bin 2 Bin 3 Bin 4

CCGGGGJJJJJM
001000010000010
Counting Multisets
• How many ways to distribute 10 identical
prizes to a class with 200 students?
Solution to Sums of Variables
• How many solutions are there to the following
equation, where each variable xi is a non-negative
integer?
x1 + x2 + x3 + x4 = 12
x1 = 2
x2 = 4
001000010000010
x3 = 5
x4 = 1
Lower Bounds
• How many ways to select 12 donuts from 4 varieties
(choc, glazed, jelly, maple) with the added constraint
that there are at least 2 chocolate donuts?
– First pick the 2 chocolate donuts.
– Then select the remaining 10 donuts with no restrictions.
Solution to Sums of Variables
• How many solutions are there to the following
equation, where each variable xi is a non-negative
integer?
x1 + x2 + x3 + x4 = 12

x2 ≥ 1 and x4 ≥ 3 .
Balls into Bins
• How many ways to throw 12 identical balls
into 4 distinct bins with at least two in each
bin?

Bin 1 Bin 2 Bin 3 Bin 4


Chocolate Bar Distribution
• How many ways to distribute 15 identical
chocolate bars to 5 kids if each kid gets at
least one?
Upper Bounds (by complement)
• How many ways to select 12 donuts from 4 varieties
(choc, glazed, jelly, maple) with the added constraint
that there are only 5 chocolate donuts available?
The number of ways The number of ways The number of ways
to select 12 donuts
from 4 varieties with = to select 12 donuts
from 4 varieties with - to select 12 donuts
from 4 varieties with
≤ 5 chocolates no constraints NOT(≤ 5 chocolates)
Balls into Bins
• m distinguishable bins
• n balls
At most 1 No limit on Same number
per bin number per bin in each bin

distinguishable
balls

indistinguishable
balls
Balls Into Bins
How many ways are there to put 3 indistinguishable balls
into 5 distinguishable bins with at most one per bin?

Bin 1 Bin 2 Bin 3 Bin 4 Bin 5


Balls Into Bins
How many ways are there to put 3 distinguishable balls
into 5 distinguishable bins with at most one per bin?

Bin 1 Bin 2 Bin 3 Bin 4 Bin 5

Bin 1 Bin 2 Bin 3 Bin 4 Bin 5


Balls Into Bins
How many ways are there to put 3 distinguishable balls
into 5 distinguishable bins with no limit on the number of
balls per bin?

Bin 1 Bin 2 Bin 3 Bin 4 Bin 5


Balls into Bins
• How many ways to throw n identical balls into
m distinct bins?

Bin 1 Bin 2 Bin 3 Bin 4 Bin 5


Balls into Bins
• How many ways to throw n distinct balls into
m distinct bins same number of balls in each
bin?

Bin 1 Bin 2 Bin 3 Bin 4 Bin 5


Balls into Bins
• How many ways to throw n identical balls into
m distinct bins same number of balls in each
bin?

Bin 1 Bin 2 Bin 3 Bin 4 Bin 5

You might also like