CS101 - Discrete Math

Robert Batzinger
Dec 2 17

Unit 2 - Combinations, Permutations and Sequences

Unit 2
Combinations,
Permutations,
and
Sequences

Contents


  • Combinations and Permutations (1.3)
  • Combinatorial Proofs (1.4)
  • Stars and Bars (1.5)
  • Advanced Counting Using the Principle of Inclusion/Exclusion (1.6)
  • Sequences (2)
  • Definitions (2.1)
  • Arithmetic and Geometric Sequences (2.2)
  • Solving Recurrence Relations (2.4)
  • Induction and Proofs (2.5)

EX Awarding Prizes

One hundred ticket numbered \( 1,2,3,...,100 \) are sold to 100 people. There are 4 prizes, including a grand prize of a trip to Australia. How many are there to award the prizes?

  • No restrictions.
  • People holding 19, 47, 73 and 93 all win prizes.
  • The grand prize goes to one of the people holding 19, 47, 73, or 93
  • None of the people holding 19, 47, 73 or 93 win prizes.
  • The person holding 93 does not win any prize.
  • The person holding 93 wins a prize.
  • The person holding 93 wins the grand prize.

Combinations and Permutations without repetitions

Select 2 out of 4 \[ r = 2, n = 4 \]

\[ \begin{array}{l} Given\ X = \{a,b,c,d\}:\\ \quad Y = \{\forall x:\\ \qquad\qquad x \in {\cal P}(X):\\ \qquad\qquad\qquad|x| = 2 \}\\ \end{array} \]

  • Permutations: All recombinations without repetition \[ ab, ac, ad, ba, bc, bd, ca, cb, cd, da, db, dc \] \[ \left({n!\over (n-r)!}\right) \]

  • Combinations: All unique combinations without repetition \[ ab, ac, ad, bc, bd, cd \] \[ \left({n!\over r!\ (n-r)!}\right) \]

Combinations/Permutations with Repetition

\[ \]

Select 2 out of 4 \[ r = 2, n = 4 \]

\[ \begin{array}{l} Given\ X = \{a,b,c,d\}:\\ \quad Y = \{\forall x:\\ \qquad\qquad x \in {\cal P}(X):\\ \qquad\qquad\qquad|x| = 2 \}\\ \end{array} \]

  • Permutations: All recombinations with repetition \[ aa, ab, ac, ad, ba, bb, bc, bd, ca, cb, cc, cd, da, db, dc, dd \] \[ \left({n^r}\right)= 4^2 = 16 \]

  • Combinations: All unique combinations with repetition \[ aa, ab, ac, ad, bb, bc, bd, cc, cd, dd \] \[ \left({(n+r-1)!\over r!\ (n-1)!}\right) = {(4 + 2 -1)!\over 2! (4-1)!} = {5!\over 2! (3)!} = 5\cdot 2 = 10 \]

Permutations with repetition

\( n \) objects can be permuted \( n^r \) when repetition is allowed

How ways can 3 binary digits be combined?

\[ \begin{array}{rl} Permutations: & 000, 001, 010, 011, 100, 101, 110, 111 \\ Calculations:& 2^3 = 2\cdot2\cdot2 = 8 \\ \end{array} \]

Combination with repetitions

\[ Z = \forall X \subset Y: |Y| = n, |X| = r, repetition = TRUE \] \[ \left({n + r -1 \atop r}\right) \]

How many combinations of 2 pencils can be drawn from a box of 2 colors?

\[ \begin{array}{rl} & \\ Bar\ and\ star\ model: & *|*, **|, |** \\ Color Scripting: & R_1G_1, G_2, R_2 \\ Calculation & \left({2 + 2 - 1 \atop2}\right) = \left({3\atop2}\right) = \left({3!\over 2!}\right) = \left({3\cdot2!\over 2!}\right) = 3\\ \end{array} \]

More repetitive combinations

\[ \begin{array}{cccl} Pencils & Colors & Combinations & Calculation\\ \hline 1 & 2 & *|, |* & \left({2\atop1}\right) = 2\\ 3 & 1 & *** & \left({3\atop3}\right) = 1\\ 3 & 2 & *|**, **|*, ***|, |***, & \left({4\atop3}\right) = 4\\ 2 & 3 & *|*|, |*|*, *||*, **||, |**|, ||** & \left({4\atop2}\right) = 6\\ 3 & 3 & *|*|*, *|**|, *||**, **|*|, |*|**, & \left({5\atop3}\right) = 10\\ & & **||*, |**|*, ***||, |***|, ||*** & \\ 4 & 2 & **|**, *|***, ***|*, ****|, |**** & \left({5\atop4}\right) = 5\\ 4 & 2 & **|**, *|***, ***|*, ****|, |**** & \left({5\atop4}\right) = 5\\ \hline \end{array} \]

Combinations and Permutations

No repetitions

  • Permutations \[ \left({n! \over (n - r)!}\right) \]

  • Combinations \[ \left({n! \over r!\ (n - r)!}\right) \]

Repetition allowed

  • Permutations \[ \left(n^r\right) \]

  • Combinations: \[ \left({(n+r-1)! \over r!\ (n - 1)!}\right) \]

Reordering repeating objects

Given \( n \) items of \( k \) unique types of items, \[ n = \sum_{i=1}^{k}\ n_i \] the number of permutations equals \[ \left({n!\over n_1!\ n_2!\ n_3!\ n_4! \cdots n_k}\right) \]

toot has 2 t's and 2 o's: \( \hbox{toot, toto, ttoo,otot, oott, otto} \) \[ \left({4! \over 2!\ 2!}\right) = 2\cdot 3 = 6 \]

bee has 2 e's and 1 b: \( \hbox{bee, ebe, eeb} \) \[ \left({3! \over 2!}\right) = 3 \]

More examples

  • teethe has 3 e's, 2 t's and 1 h.

\[ \left({6!\over 3!\ 2! 1!}\right) = {6\cdot 5\cdot 2} = 60 \]

  • beekeeper has 5 e's and the letters bkpr have 1 each.

\[ \left({9!\over 4!\ 1!\ 1!\ 1!\ 1!}\right) = 9\cdot8\cdot7\cdot6\cdot5 = 15,120 \]

  • bookkeeper has 3 e's, 2 k's, 2 o's, 1 b and 1 r

\[ \left({10!\over 3!\ 2!\ 2!\ 1!\ 1!}\right) = 10\cdot9\cdot8\cdot7\cdot6\cdot5 = 151,200 \]

Distributing objects into boxes

Number of ways that \( n \) discrete items into \( k \) boxes of specific sizes \( n_1\dots n_k \) \[ \left({n!\over n_1!\ n_2!\cdots n_k!}\right) \]

  • Number of ways 3 people can choose 2 pencils each from a box of 12 colors:

\[ \left({10!\over 2!\ 2!\ 2!\ 1!}\right) = 10\cdot9\cdot8\cdot7\cdot6\cdot5\cdot3 = 453,600 \]

  • Number of ways 2 people can select 5 pencils each from a box of 10 colors:

\[ \left({10!\over5!\ 5!}\right) = 9\cdot4\cdot7 = 252 \]

Binomial Equalities

Lessons from Pascal's Triangle

\[ \begin{array}{rcl} \left({n \atop 0}\right) &=& \left({n\atop n}\right) = 1\\ \\ \left({n \atop k}\right) &=& \left({n\atop n-k}\right)\\ \\ \left({n \atop k}\right) &=& \left({n - 1\atop k - 1}\right) + \left({n - 1 \atop k}\right)\\ \\ \large 2^n &=& \left({n \atop 0}\right) + \left({n \atop 1}\right) + \left({n \atop 2}\right) + \dots + \left({n \atop n}\right) \end{array} \]

Sequences

Sequences

Sequence is an ordered list of numbers

What would you expect to the be next term?

  • 7, 7, 7, 7, 7, …
  • 3, −3, 3, −3, 3, …
  • 1, 5, 2, 10, 3, 15, …
  • 1, 2, 4, 8, 16, 32, …
  • 1, 4, 9, 16, 25, 36, …
  • 1, 2, 3, 5, 8, 13, 21, …

Two methods for specifying a sequence

  • Closed formula: a formula in which the value of any particular term \( a_n \) as a function of \( n \).

  • Recursive relationship: a formula in which the terms of any particular term \( a_n \) is a function of previous values of \( a_1 \) to \( a_{n-1} \)

Ex Examples

Find the value for \( n=10 \)

Closed formulas:

  • \( a_n = n^2 \)
  • \( a_n = {n(n+1)\over 2} \)
  • \( a_n = {2^n\over n+2} \)

Recursive formulas:

  • \( a_n = 2a_{n-1} \) with \( a_0 = 1 \)
  • \( a_n = 2a_{n-1} \) with \( a_0 = 27 \)
  • \( a_n = a_{n-1} + a_{n-2} \) with \( a_0 = 0, a_1 = 1 \)

Bank Interest as a recursive relationship

\[ \begin{array}{l} P_0 = 10000 \\ P_1 = P_0 + 1.05\ P_0\\ P_2 = P_1 + 1.05\ P_1 = P_0 + 1.05^2P_0\\ P_3 = P_2 + 1.05\ P_2 = P_0 + 1.05^3P_0\\ P_4 = P_3 + 1.05\ P_3 = P_0 + 1.05^4P_0\\ P_5 = P_4 + 1.05\ P_4 = P_0 + 1.05^5P_0\\ \qquad\qquad \vdots\\ P_{n} = P_{(n-1)} + 1.05\ P_{(n-1)} = P_0 + 1.05^n P_0\\ \\ P_{30} = P_{29} + 1.05\ P_{29} = P_0 + (1.05)^{30} P_0 = 53,219.42 \\ \end{array} \]

Rabbit Problem by Leonardo di Pisano

A pair of male/female rabbits are left on a island. The pair does not breed until they are 2 months old. After 2 months old, each pair produces another pair each month. Find the recurrence relation assuming no deaths. -Fibonacci 1202

Month Mating pairs Young pairs Total pairs
1 0 1 1
2 0 1 1
3 1 1 2
4 1 2 3
5 2 3 5
6 3 5 8
7 5 8 13
8 8 13 21

\[ Pairs_n = Pairs_{n-1} + Pairs_{n-2} \]

Polynomial sequences

  • Series: \( n_i = i^2 \)

\[ series: 1, 4, 9, 16, 25, 36, ... \] \[ differ_1: 3, 5, 7, 9, 11, ... \] \[ differ_2: 2, 2, 2, 2, ... \]

  • Series: \( n_i = i^2 + 2i + 1 \)

\[ series: 4, 9, 16, 25, 36, 49, 64, 81, ... \] \[ differ_1: 5, 7, 9, 11, 13, 15, 17, ... \] \[ differ_2: 2, 2, 2, 2, 2, 2, ... \]

Polynomial sequences of the order 4

  • Series: \( n_i = i^4 \)

\[ series: 1, 16, 81, 256, 625, 1296, ... \] \[ differ_1: 15, 65, 175, 450, 671, 1105, ... \] \[ differ_2: 50, 110, 194, 302, 434, ... \] \[ differ_3: 60, 84, 108, 132, ... \] \[ differ_4: 24, 24, 24, ... \]

  • Series: \( n_i = i^4 + 4 i^3 + 6 i^2 + 4i + 1 \)

\[ series: 16, 82, 258, 628, 1300, 2406, ... \] \[ differ_1: 66, 176, 370, 672, 1106, ... \] \[ differ_2: 110, 194, 302, 434, 590, ... \] \[ differ_3: 84, 108, 132, 156, ... \] \[ differ_4: 24, 24, 24, ... \]

Cannon Ball stacking

cannonball

  1. Determine the sequence
  2. Determine the order of magnitude of the polynomial
  3. Determine the polynomial
  4. Calculate the number in a stack 15 higher

Cannonball Calculation

Count 1 2 3 4 5 6
Number in level 1 3 6 10 15 21
Number in stack 1 4 10 20 35 56
Differ1 3 6 10 15 21 -
Differ2 2 3 4 5 6 -
Differ3 1 1 1 - - -

\[ Balls = a x^3 + b x^2 + c x + d \]

\[ \begin{array}{rcl} 0 &=& d\\ 1 &=& a + b + c \\ 4 &=& 8a + 4b + 2c\\ 10 &=& 27a + 9b + 3c\\ \end{array} \]

Cannonball Calculations

\[ \begin{array}{ccccc} 1a & 1b & 1c &=& 1\\ 8a & 4b & 2c &=& 4\\ 27a & 9b & 3c &=& 10\\ \hline 1 & 1 &1&=& 1\\ 0 & 1 &3/2&=& 1\\ 0 & 0 & 1&=& 1/3\\ \hline 1 & 0 & 0 & = & 1/6\\ 0 & 1 & 0 & = & 1/2\\ 0 & 0 & 1 & = & 1/3\\ \end{array} \]

\[ y = {x^3\over 6} + {x^2\over 2} + {x\over 3} \]

\[ y_{15} = 680 \]

Stacked Cans

Calculate the number of cans in stack 10 levels high

cans

Preferred Type of Potato

How many students hate potatoes?

  • 30 Student choose Mashed, French-fried, or Twice-baked Potatoes
  • 15 liked mashed, 20 liked French-fries, and 9 liked twice baked.
  • Like 2:
    • 12 students liked both mashed and fried potatoes,
    • 5 liked French fries and twice baked potatoes,
    • 6 liked mashed and baked
  • 3 liked all three styles.

Number of multiples

How many elements in \( n \in \{1,2,3,...,500}: \)

\( n \) is a multiple of one or more of 5, 6, or 7?

Another sequence

  • Series: 3,6,12,24,48,96,192

  • Differences: 3,6,12,24,48,96,

  • Recursive definition:

\[ \begin{array}{rcl} a_0 &=& 3 \\ a_n &=& 2\times a_{n-1}\\ \end{array} \]

  • Determining the fixed formula:

\[ \begin{array}{rcl} a_1 &=& 2a_0\\ a_2 &=& 2a_1 = 4a_0\\ a_3 &=& 2a_2 = 8a_0\\ \end{array} \]

  • Fixed formula

\[ a_n = 3\times 2^n \]

Arithmetric and Geometric Sequences

series

Arithmetic Sequence:

the terms differ by a constant

Recursive definition: \( a_0 = a \) \[ a_n = a_{n−1} + d \]

Closed formula: \( a_n = a + d n \)

Geometric Sequences

There is a constant ratio between successive terms

Recursive definition: \( a_0 = a \) \[ a_n = r a_{n−1} \]

Closed formula: \( a_n = a \times r^n \)

Sums

  • Arithmetic

\[ \sum_{i=1}^n a_i = 1+2+3+4+...+n = \frac{n(n+1)}{2} \]

  • Geometric

\[ \sum_{i=1}^n a_i = \left\{\ \begin{array}{l} \frac{a r^{n+1} - a}{r - 1} if r \neq 1 \\ a (n+1) if r = 1\\ \end{array}\right. \]

Useful summation formula

\[ \sum_{i=1}^n a_i = \frac{n(n+1)}{2} \]

\[ \sum_{i=1}^n a_i^2 = \frac{n(n+1)(2n+1)}{6} \]

\[ \sum_{i=1}^n a_i^3 = \frac{n^2(n+1)^2}{4} \]

\[ \sum_{k=0}^\infty x^k = \frac{1}{1-x} if |x| < 1 \]

\[ \sum_{k=1}^\infty kx^k = \frac{1}{(1-x)^2} if |x| < 1 \]

Markov Chain - Probabilitics Sequence of States

  • Models the flow through a network of nodes
  • The subsequent node is determined by a list of probabilities

Markov Chains

Markov Chains - Steady State

Weather Rain next day Sunny next day
Rain today 0.60 0.40
Sunny today 0.50 0.50

If it is sunny today, what is the 10 day prediction?

day rain sunny rain sunny
1 0.0000000 1.0000000 1.0000000 0.0000000
2 0.5000000 0.5000000 0.6000000 0.4000000
3 0.5500000 0.4500000 0.5600000 0.4400000
4 0.5550000 0.4450000 0.5560000 0.4440000
5 0.5555000 0.4445000 0.5556000 0.4444000
6 0.5555500 0.4444500 0.5555600 0.4444400
7 0.5555550 0.4444450 0.5555560 0.4444440
8 0.5555555 0.4444445 0.5555556 0.4444444
9 0.5555556 0.4444445 0.5555556 0.4444444
10 0.5555556 0.4444444 0.5555556 0.4444444

Steady State

\[ \begin{array}{|l|cc|} \hline & Rain & Sunshine \\ \hline R_n &.6R_n& .4R_n\\ S_n &.5S_n& .5S_n \\ \hline \end{array} \]

\[ \begin{array}{rcl} R_{n+1} &=& 0.6R_n + .5S_n = R_n\\ S_{n+1} &=& 0.4R_n + .5S_n = S_n\\ 1 &=& R + S\\ \end{array} \]

Solution: \[ R = 5/9; S= 4/9 \]

Markov Chains - Absorbing states

univ

Current Year Fresh Sopho Junior Senior Grad
Freshmen 0.10 0.90 0.00 0.00 0.00
Sophomore 0.00 0.10 0.90 0.00 0.00
Junior 0.00 0.00 0.10 0.90 0.00
Senior 0.00 0.00 0.00 0.10 0.90
Grad 0.00 0.00 0.00 0.00 1.00

Transit Time

Year Fresh Sopho Junior Senior Grad
1 1.0000 0.0000 0.0000 0.0000 0.0000
2 0.1000 0.9000 0.0000 0.0000 0.0000
3 0.0100 0.1800 0.8100 0.0000 0.0000
4 0.0010 0.0270 0.2440 0.7290 0.0000
5 0.0001 0.0036 0.0486 0.2916 0.6562
6 0.0000 0.0005 0.0081 0.0729 0.9185
7 0.0000 0.0000 0.0012 0.0146 0.9842
8 0.0000 0.0000 0.0002 0.0025 0.9973
9 0.0000 0.0000 0.0000 0.0004 0.9996
10 0.0000 0.0000 0.0000 0.0001 0.9999

Bangkok Air Polution

plot of chunk unnamed-chunk-14

  • Tally of level changes
Level 1 2 3 4 5 6
Good (1) 0 1 0 0 0 0
Moderate (2) 0 23 12 0 0 0
High (3) 0 8 17 9 0 1
Very high 4) 0 4 4 7 0 0
Hazardous (5) 0 0 1 0 0 0
Extreme (6) 0 0 0 0 1 1

Convert to markov chains (change probability table)

Level 1 2 3 4 5 6
Good (1) 0.000 1.000 0.000 0.000 0.000 0.000
Moderate (2) 0.000 0.657 0.343 0.000 0.000 0.000
High (3) 0.000 0.229 0.486 0.257 0.000 0.028
Very high 4) 0.000 0.267 0.267 0.466 0.000 0.000
Hazardous (5) 0.000 0.000 1.000 0.000 0.000 0.000
Extreme (6) 0.000 0.000 0.000 0.000 0.500 0.500

Model

Equalibrium Polution

  • Good (1) : 00.0%
  • Moderate (2) : 40.0%
  • High (3) : 38.4%
  • Very high 4) : 18.5%
  • Hazardous (5) : 10.7%
  • Extreme (6) : 2.1%

plot of chunk unnamed-chunk-16

2 day context

plot of chunk unnamed-chunk-17

12=>{3=>1.00},
22=>{2=>0.652,3=>0.348},
23=>{2=>0.231,3=>0.461,4=>0.308},
32=>{2=>0.625,3=>0.375},
33=>{2=>0.235,3=>0.471,4=>0.235,6=>0.059},
34=>{2=>0.2,3=>0.3,4=>0.4,6=>0.1},
36=>{5=>1.0},
42=>{2=>0.75,3=>0.25},
43=>{2=>0.25,3=>0.5,4=>0.25},
44=>{2=>0.4,3=>0.2,4=>0.4},
46=>{5=>1.0},
53=>{3=>1.00},
55=>{3=>1.00},
65=>{3=>0.5,5=>0.5}}}

Programming the Model

class Stoichastic
    attr_accessor :connect, :last, :current

    def initialize(list,start1,start2)
        @connect =list
        @last=start1
        @current = start2
    end

  def rotate(val)
    @last = @current
        @current = val
  end
end

The next method

def next
  choices = @connect[10*@last+@current]
  r = rand()
  rsum = 0
  k = choices.keys
  while rsum < r do
    kk = k.shift
    rsum = rsum + choices[kk]
    if rsum >= r 
          return rotate(kk)
    end
  end
end

Using the class

s = Stoichastic.new({
12=>{3=>1.00},  22=>{2=>0.652,3=>0.348},
23=>{2=>0.231,3=>0.461,4=>0.308},
32=>{2=>0.625,3=>0.375},  6=>0.059},
33=>{2=>0.235,3=>0.471,4=>0.235,
34=>{2=>0.2,3=>0.3,4=>0.4,6=>0.1},
36=>{5=>1.0}, 42=>{2=>0.75,3=>0.25},
43=>{2=>0.25,3=>0.5,4=>0.25},
44=>{2=>0.4,3=>0.2,4=>0.4},
46=>{5=>1.0},   65=>{3=>0.5,5=>0.5}
55=>{3=>1.00},  53=>{3=>1.00},  },1,2)

(1..400).each {|i|
  puts "#{s.next}"
}

Model based on Payap University

Payap Logo

\[ \tiny\begin{array}{lcccccc} State & 1st & 2nd & 3rd & 4th & Grd & With & Retir \\ \hline 1st & 0.1 & 0.7 & 0.0 & 0.0 & 0.0 & 0.2&0.0 \\ 2nd & 0.1 & 0.8 & 0.0 & 0.0 & 0.1 &0.0 & 0.0 \\ 3rd & 0.0 & 0.0 & 0.1 & 0.8 & 0.0 & 0.1 &0.0 \\ 4th & 0.0 & 0.0 & 0.0 & 0.1 & 0.8 & 0.1 &0.0 \\ Grad & 0.0& 0.0 & 0.0 & 0.0 & 1.0 & 0.0& 0.0 \\ With & 0.001&0.0& 0.0 & 0.0 & 0.0 &0.009& 0.99\\ Retire & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 &1.0\\ \hline \end{array} \]

Yr 1st 2nd 3rd 4th Grad With Retire
1 1000 0 0 0 0 0 0
2 100 700 0 0 0 200 0
3 10 140 560 0 0 92 198
4 1 21 168 448 0 73 289
5 0 3 34 179 358 65 361
6 0 0 6 45 502 22 425
7 0 0 1 9 538 5 447
8 0 0 0 2 545 1 452
9 0 0 0 0 547 0 453

Run Length of Binary Digits

State 0 Next 1 Next
0 0.5 0.5
1 0.5 0.5

\[ \begin{array}{ll} Pattern & Probability\\ 1 & 0.5 \\ 11 & 0.25 \\ 111 & 0.125 \\ 1111 & 0.0625 \\ 11111 & 0.03125 \\ 111111 & 0.015625 \\ \end{array} \]

Run Length Tallies

ID RANDOM STRING Run length tallies Ave Run Len
1 110000001101111001000101100001 1-4,2-3,3-1,4-2,6-1 2.31 +/- 1.54
2 001010101000101100011001000001 1-11,2-4,3-2,5-1 1.67 +/- 1.08
3 011110000011001111000000011010 1-4,2-3,4-2,7-1 2.73 +/- 2.00
4 110101101001011011111100001011 1-10,2-5,4-1,6-1 1.76 +/- 1.35
5 001111111001111001110000001001 1-2,2-4,6-1,7-1 3.00 +/- 2.05
6 011100000101000110000010001100 1-5,2-3,3-3,5-2 2.31 +/- 1.43

plot of chunk unnamed-chunk-22

Experiment 2 Data

plot of chunk unnamed-chunk-23

  • Comparison between binary run lengths in 5 random population and the experimental data