Bite-Sized Mathematics for Computer Science

Notes on MIT's 6.042J

Eda Eren
Table of Contents

Introduction

Prerequisites & Resources

Unit 1: Proofs

00. Introduction to Proofs

01. (Two) Proof Methods

02. The Well Ordering Principle

03. Logic & Propositions

04. Quantifiers and Predicate Logic

05. Sets

06. Binary Relations

07. Induction

08. State Machines — Invariants

09. Recursive Definitions

10. Infinite Sets

Unit 2: Structures

11. GCDs

12. Congruences

13. Euler's Theorem

14. RSA Encryption

15. Digraphs: Walks and Paths

16. Directed Acyclic Graphs

17. Partial Orders and Equivalence

18. Degrees & Isomorphism

19. Coloring & Connectivity

20. Trees

21. Stable Matching

Unit 3: Counting

22. Sums & Products

23. Asymptotics

24. Counting with Bijections

26. Pigeonhole Principle, Inclusion-Exclusion

Unit 4: Probability

27. Intro to Discrete Probability

28. Conditional Probability

29. Independence & Causality

30. Random Variables, Density Functions

31. Expectation

32. Deviation: Markov & Chebyshev Bounds

33. Sampling & Confidence

34. Random Walks & PageRank

Repetitions & Binomial Theorem

First, let's look at another rule, namely, the generalized bijection rule.

If we have a total function from set AA to set BB, and it is k-to-1 (each BB element is hit by exactly k elements), then the cardinality of AA is kk times the cardinality of BB:

A=kB|A| = k|B|

We can use a simple example.
Let's say we want to count how many people are in a room. Given that everybody has 22 shoes, we can count the number of shoes and divide the number by 22 to find the number of people. In this case, set AA is the set of shoes, and set BB is the set of all people.


The number of ways to choose the set of mm elements among nn is nn choose mm, denoted by the binomial coefficient notation: (nm)\binom{n}{m}.

It is defined as:

n!m!(nm)!\frac{n!}{m!(n - m)!}

Let's look at (1+x)2(1 + x)^2. We can expand it, and the result will be

1+2x+x21 + 2x + x^2

Now, let's look at (1+x)3(1 + x)^3. We get

1+3x+3x2+x31 + 3x + 3x^2 + x^3

What we're looking for here is a pattern.

And, that's where the binomial theorem comes in.

Let's look at (1+x)n(1 + x)^n.
There are 22 terms in (1+x)(1 + x), each term will correspond to selecting 11 or xx from each of the nn factors, which means we will have in total 2n2^n terms.
So, with (1+x)2(1 + x)^2, our nn is 22, and the factors are (1+x)(1+x)(1 + x)(1 + x).
Doing the computation, all the terms we have are 11, xx, xx, and x2x^2 — adding up to 1+2x+x21 + 2x + x^2.

The coefficient of xkx^k is the number of xkx^k's among the 2n2^n terms. In the case of our example, it is 11 (we don't need to write 1x21x^2).

We can call this coefficient ckc_k, then represent it as ck=(nk)c_k = \binom{n}{k}.

And, the binomial formula is:

(1+x)n=(n0)+(n1)x+(n2)x2+ ... +(nn)xn(1 + x)^n = \binom{n}{0} + \binom{n}{1}x + \binom{n}{2}x^2 + \ ... \ + \binom{n}{n}x^n

More generally, it can be written as:

(x+y)n=(n0)yn+(n1)xyn1+(n2)x2yn2+(nk)xkynk+ ... +(nn)xn(x + y)^n = \binom{n}{0}y^n + \binom{n}{1}xy^{n - 1} + \binom{n}{2}x^2y^{n - 2} + \binom{n}{k}x^ky^{n - k} + \ ... \ + \binom{n}{n}x^n

Even more precisely:

(x+y)n=k=0n(nk)=xkynk(x + y)^n = \displaystyle\sum_{k = 0}^{n} \binom{n}{k} = x^ky^{n - k}

There is also the multinomial coefficient, which is defined as:

(nn1, n2, ..., k)=n!n1!n2!...nk!\binom{n}{n_1, \ n_2, \ ..., \ k} = \frac{n!}{n_1! n_2! ... n_k!}

One example is to find the number of permutations of length-nn word with n1n_1 a's, n2n_2 b's, ..., nkn_k z's.

Let's look at how we can find the number of ways of rearranging the letters in the word "banana."

The question is, what is the coefficient of BA3N2BA^3N^2 in the expansion of (B+A+N)6(B + A + N)^6?

Well, we can write the multinomial coefficient, which will be (61, 3, 2)\binom{6}{1, \ 3, \ 2}.

Therefore, 6!1!3!2!=72012=60\frac{6!}{1! \cdot 3! \cdot 2!} = \frac{720}{12} = 60.