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

24. Counting with Bijections

25. Repetitions & Binomial Theorem

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

Asymptotics

We need to measure the behavior of a function f(n)f(n) as nn grows larger. Here is where asymptotic notation comes to the rescue.

We have already seen a simple asymptotic equivalence example in the previous section to show that (n2+n)(n^2 + n) and n2n^2 are asymptotically equivalent, denoted as (n2+n)n2(n^2 + n) \sim n^2. The limit of their quotient goes to 11, and that's how we determined it.

If a function ff is asymptotically smaller than a function gg, then f(n)f(n) is equal to the little oh of g(x)g(x):

f(x)=o(g(x))f(x) = o(g(x))

That means, the limit of their quotient should go to 00 as xx approaches infinity:

limxf(x)g(x)=0\lim_{x \to \infty} \frac{f(x)}{g(x)} = 0

For example, 1000x1.91000x^{1.9} is asymptotically smaller than x2x^2.

Simplifying 1000x1.9x2\frac{1000x^{1.9}}{x^2}, we get 1000x0.1\frac{1000}{x^{0.1}}.

And, as xx approaches infinity, the whole thing approaches 00:

limx1000x0.1=0\lim_{x \to \infty} \frac{1000}{x^{0.1}} = 0

Given that aa and bb are nonnegative numbers,

xa=o(xb) for a<bx^a = o(x^b) \text{ for } a \lt b

Let's see.

xaxb=1xba\frac{x^a}{x^b} = \frac{1}{x^{b - a}}

ba>0b - a \gt 0 because of the given definitions: they are nonnegative and a<ba \lt b.
Therefore, as xx approaches infinity, 1xba\frac{1}{x^{b - a}} will approach 00. That means, xax^a is little oh of xbx^b.


The star of this show is the big oh notation, which is used to measure the upper bound on the growth of a function. In other words, it is to measure the worst-case scenario. If a function ff is big oh of a function gg, that is, f(x)=O(g(x))f(x) = O(g(x)), it means that the limit of their quotient as xx approaches infinity is finite. Let ff and gg be positive, if limnf(x)g(x)\lim_{n \to \infty} \frac{f(x)}{g(x)} exists*, then:

limxf(x)g(x)<\lim_{x \to \infty} \frac{f(x)}{g(x)} \lt \infty

An example is that 3n2=O(n2)3n^2 = O(n^2):

limn3n2n2=3\lim_{n \to \infty} \frac{3n^2}{n^2} = 3

33 is definitely less than infinity, it is indeed true that 3n2=O(n2)3n^2 = O(n^2).

The definition generally used is with limit superior:

limsupxf(x)g(x)<\lim\sup_{x \to \infty} \frac{|f(x)|}{g(x)} \lt \infty

Also, note that with big oh, constant factors don't really matter.

*Definition taken from Criterion 2 (Finite limit of ratio implies Big Oh).


When two functions ff and gg have the same order of growth, we can use theta: f=Θ(g)f = \Theta(g).
It means that, f=O(g)f = O(g) and g=O(f)g = O(f).
It's an equivalence relation.


One thing to keep in mind with big oh is that it defines a relation between the growth rates of two functions, not a quantity.
That's why writing it like O(g)=fO(g) = f is risky.

Let's look at an example.
Obviously, x=O(x)x = O(x), and usually with symmetry, we are supposed to be able to write it as O(x)=xO(x) = x as well.
But, 2x2x also has the same upper bound, that is, 2x=O(x)2x = O(x).
Now, we just wrote that O(x)=xO(x) = x, by that reasoning, it must also be that 2x=x2x = x. But, that is certainly false!

So, we can't say something like "a function ff is at least O(n2)O(n^2)", because O(n2)O(n^2) is not a quantity, it is a relation.