Week 4 notes

Comp 163-002, Spring 2022, MW 4:15-5:30, Mondays in Cuneo 117 (starting January 31) and Wednesdays online.

The primary goal of this course is to become familiar with some of the basic mathematical ideas used in programming.

Reading:

        Levin, 1.3, 1.4, maybe 1.5




Pascal's Triangle

                         1
                       1   1
                     1   2   1
                   1   3   3   1
                 1   4   6   4   1
               1   5  10  10   5   1
             1   6  15  20  15   6   1
           1   7  21  35  35  21   7   1
         1   8  28  56  70  56  28   8   1


Pascal's triangle modulo 2:

Pascal's Triangle mod 2

See also here.

Counting the single value at the top as row 0 (so the row (1 3 3 1) is row 3), we can prove by induction that all entries in row 2n of Pascal's Triangle are odd, and therefore in the mod-2 version are all 1. From this we can then prove the repeating pattern evident above.

Algebraic proof that all (2n-1 choose k) are odd

Numerator is (2n-1)(2n-2)...(2n-i)...(2n-k), denominator is 1*2*...*i*...*k.  Claim: each vertically aligned fraction (2n-i)/i is odd. Proof: any power of 2 dividing 2n-i also divides i.

Levin 1.3: Combinations and Permutations

Investigate! examples on page 81

What is a permutation? Counting them.

How many functions f:{1,...,8} -> {1,...,8} are bijections? Such functions are also known as permutations.

How many functions f: {1,...,3} -> {1,...,8} are bijections? These correspond to 3-element sequences of distinct values, or 3-permutations.

We can also talk about k-permutations of n elements: P(n,k) = n!/k!

= number of injective functions from k elements to n elements, n>=k

Divide number of 3-permutations of n things by 3! to get the number of 3-element sets.

Compare with (n k) = C(n,k) (or B(n,k))

Example of dinner party on page 85 of Levin

Example on page 89

Example 1.4.1 on page 90

Page 93: Example 1.4.5

Page 95: 4 A's, 3 B's, 2 C's, 1 D problem

Page 96 example 1.4.6

Page 97, example 1.4.7

Page 103: stars and bars counting: how many ways can we give 7 cookies to 4 kids?

Page 106: Example 1.5.1

Page 106: Example 1.5.2

Page 107: Example 1.5.3

Page 112 (PIE): 1.6.1

1.6.2

1.6.4: Derangements

1.6.5

Counting Techniques Summary

Additive: if you're making one choice from either of two disjoint sets
2-set PIE: if the sets are not disjoint

Multiplicative: if you're making two choices, one from each set, and the order matters (or can be inferred)

Count the complement and subtract (variation of additive rule)

Count with multiplicity, then divide, like the permutations/combinations trick

variants of counting subsets: counting lattice paths, bitstrings

Stars and bars: counting how many ways you can divide M identical things among N bins

3-set PIE