unfried.
Streak:0 days XP:0

Formula sheet

Discrete math

Counting, probability, recurrences, graphs and Boolean algebra.

51 entries in 9 units. Free to use and share.

Jump to a unit (9 units)

Unit 1 Counting: sum and product rules

Multiplication principle

nk
number of choices at step k
k
number of steps

Applies: Steps in sequence, with the same number of choices on every branch (which choices remain may differ).

Careful: Adding the steps instead of multiplying is the classic slip; a 4-digit PIN has 104 options, not 40.

Taught in Lists and the multiplication principle

Addition principle and complement

Split into cases that don't overlap and add the counts. "At least one" is the total minus "none". PINs with a 7 number 104−94=3439⁠, not 4⋅1000⁠.

Careful: Overlapping cases double-count.

Taught in Addition, subtraction and complements

Address spaces

A k-bit field holds 2k values, and a block with f free bits holds 2f⁠. I²C has 27−2⋅23=112 device addresses; CAN 11-bit IDs number 211−24=2032⁠.

Taught in Addresses, codes and IDs

Counting by bijection

If f from a finite X to a finite Y is injective and surjective, then ∣X∣=∣Y∣⁠. Both halves matter.

Taught in Counting by bijection

Unit 2 Permutations, combinations, binomial theorem

Factorial and arrangements

Definition.

n
number of objects

Careful: A round table of n people has (n−1)! seatings; dividing out symmetry works only when every group has the same size.

Taught in Arrangements and overcounting

Arrangements with repeated letters

n
number of letters
a,b
how often each letter repeats

Applies: A word whose letters repeat a,b,… times. BANANA has 60.

Taught in Arrangements and overcounting

Binomial coefficient

n
objects
k
how many are chosen

Applies: Choosing a subset, order ignored. Also (nk)=(nn−k)⁠, and a grid route of a rights and b ups has (a+bb) choices.

Careful: With roles (order matters), it is n!/(n−k)!⁠.

Taught in Combinations: choosing a subset

Stars and bars

Choosing k items from n types with repeats, order ignored, gives (n+k−1k) choices. Whole-number solutions of x1+x2+x3=7 number (92)=36⁠; give each variable its required minimum first.

Taught in Choosing with repetition

Pascal's rule

n
set size
k
subset size, 1≤k≤n

Applies: Proved by splitting the subsets by whether they contain n⁠.

Careful: Checking one case doesn't prove it for every n⁠.

Taught in Combinatorial proof

Hamming distance

The Hamming distance between two words is the number of positions where they differ, the number of 1s in their XOR. Words at distance k from an n-bit word number (nk)⁠. A single parity bit misses every even number of flips.

Taught in Bit errors and Hamming distance

Unit 3 Pigeonhole, inclusion–exclusion

Pigeonhole principle

Putting k objects into n boxes with k>n⁠, some box holds at least two. To answer "how many to be sure", show this many always works and one fewer can fail.

Careful: It says a shared box exists, not which one.

Taught in The pigeonhole principle

Generalized pigeonhole principle

n
objects
k
boxes

Applies: Some box holds at least this many. To be sure of r in one box, take k(r−1)+1 objects.

Careful: Round up, not down; it guarantees one crowded box, not a minimum for every box.

Taught in The generalized pigeonhole principle

Inclusion–exclusion

A,B
finite sets

Applies: Any two finite sets. For three, add the singles, subtract the pairs and add back the triple.

Careful: Leaving out the triple overlap misses the elements in all three.

Taught in Inclusion–exclusion

Derangements

Dn
permutations of n items with none in its own place
n
number of items
k
index

Applies: Any n⁠; Dn is the whole number nearest n!/e⁠, and the share tends to 1/e≈0.368⁠.

Taught in Derangements

Lossless compression

There are 2n files of n bits but only 2n−1 shorter strings, so no lossless compressor shrinks every file. Hashes map many inputs to few values, so collisions are certain.

Taught in No compressor shrinks everything

Unit 4 Recurrences and generating functions

Recurrence from counting

Split the objects of size n by their first choice; each case is a smaller object of the same kind. Bit strings with no two adjacent 1s satisfy an=an−1+an−2 with a1=2 and a2=3⁠.

Careful: A rule reaching back k terms needs k starting values.

Taught in Recurrences from counting

Two-term linear recurrence

r
root of the characteristic equation
c1,c2
coefficients of an=c1an−1+c2an−2
an
terms
A,B
constants from the initial values
r1,r2
two different roots
n
index

Applies: Two different roots. A double root r gives (A+Bn)rn⁠.

Careful: At n=1⁠, fit Ar1+Br2=a1⁠, not A+B=a1⁠.

Taught in Solving linear recurrences

Adding a constant

an
solution of an=c an−1+d
A
constant from the starting value
c
multiplier, not 1
n
index
p
particular (constant) solution
d
added constant

Applies: c≠1⁠. Find A after adding p⁠. The Tower of Hanoi gives Hn=2n−1⁠.

Careful: When c=1⁠, an=a0+dn instead.

Taught in Non-homogeneous recurrences: the Tower of Hanoi

Generating functions

Make the count for n the coefficient of xn⁠. Coins of value v give the factor 11−xv⁠, and multiplying factors adds exponents, so a product counts the ways to split n⁠.

Taught in Generating functions

One-line digital filter

yn
output
a
smoothing, 0<a<1
xn
input

Applies: A step input from y0=0 gives yn=1−an⁠, reaching fraction q after n≥ln⁡(1−q)/ln⁡a samples.

Taught in A one-line digital filter

Unit 5 Graphs: degree, paths, connectivity

Handshake lemma

v
vertices
deg⁡v
degree of v
E
set of edges

Applies: Any graph. So the number of odd-degree vertices is even.

Careful: An even sum is necessary but not enough for a degree list.

Taught in Graphs and the handshake lemma

Edges and connectivity

A connected graph on n vertices needs at least n−1 edges. Kn⁠, with every pair joined, has (n2) edges.

Careful: Enough edges doesn't make a graph connected.

Taught in Paths, cycles and connectivity

Euler paths and circuits

For a connected graph. An Euler path uses every edge once.

Odd-degree verticesEuler circuitEuler path
0yesyes
2noyes, odd vertex to odd vertex
4 or morenono

Taught in Euler paths and circuits

Hamilton cycles

A Hamilton cycle passes through every vertex exactly once and returns. No degree test decides it. With every pair of n cities joined, there are (n−1)!/2 tours.

Taught in Hamilton cycles

Walks and the adjacency matrix

(Ak)ij counts the walks of length k from i to j⁠. (A2)ii is the degree of i⁠.

Careful: A2 is the matrix product, not each entry squared.

Taught in Walks and adjacency matrices

Odd cycles and two-coloring

A graph with an odd cycle has no proper 2-coloring. A triangle and a 5-cycle can't be 2-colored; a 6-cycle and the cube can.

Taught in Odd cycles and two-coloring

Unit 6 Trees and graph algorithms

Trees

For a graph on n vertices, any two of "connected", "no cycles" and "exactly n−1 edges" give the third. A graph with no cycles and c components has n−c edges.

Careful: n−1 edges alone isn't enough.

Taught in Trees

Degrees in a tree

v
vertices
deg⁡v
degree
n
number of vertices

Applies: Any tree. The number of leaves is 2+∑(deg⁡v−2) over the non-leaves.

Taught in Trees

Which algorithm

Only BFS levels are distances, and only for unweighted edges.

JobAlgorithm
fewest hopsbreadth-first search
cheapest route, weights 0 or moreDijkstra
cheapest network joining everythingKruskal or Prim

Careful: Dijkstra needs every weight to be 0 or more; a minimum spanning tree minimizes the total, not each route.

Taught in Shortest paths: Dijkstra

Unit 7 Discrete probability

Equally likely outcomes

P
probability
E
event
S
sample space

Applies: Every outcome is equally likely. Two dice give 36 rolls, not 11 sums.

Taught in Equally likely outcomes

Exclusive or independent

QuantityExclusiveIndependent
P(A∩B)0P(A)P(B)
P(A∪B)P(A)+P(B)P(A)+P(B)−P(A)P(B)
P(B∣A)0P(B)

Careful: Exclusive events with positive chances are dependent.

Taught in Exclusive or independent?

Bayes' theorem

A,B
events
P
probability

Applies: Draw a table of 10,000 people first. A 99 % test with 5 % false positives at a 1 % base rate gives 1/6.

Careful: The base rate matters as much as the test's accuracy.

Taught in Bayes and base rates

Expectation and linearity

E
expected value
X,Y
random variables
x
values of X
P
probability

Applies: Linearity holds for any random variables, dependent or not. An indicator has E[I]=P⁠.

Taught in Random variables and expectation

Bit errors in a packet

P
probability
p
bit error rate
n
bits in the packet
k
number of errors

Applies: Independent bit errors.

Careful: 1−np adds chances as if errors were exclusive; bursts make bits dependent.

Taught in Bit errors and packet loss

Unit 8 Boolean algebra and logic circuits

Boolean laws

For bits 1+1=1⁠, because OR never carries, and cancellation fails.

LawOR formAND form
idempotentA+A=AAA=A
boundsA+1=1A⋅0=0
complementA+A‾=1AA‾=0
absorptionA+AB=AA(A+B)=A
distributiveA+BC=(A+B)(A+C)A(B+C)=AB+AC

Taught in Boolean expressions

De Morgan's laws

A,B
Boolean variables

Applies: Always: break the bar and flip the operator.

Careful: Keeping the operator when pushing the bar in fails on rows 01 and 10.

Taught in De Morgan and NAND

Sum of products and Karnaugh maps

OR the minterms of the rows where f=1⁠. On a Karnaugh map, with columns in the order 00, 01, 11, 10, cover the 1s with rectangles of 1, 2, 4 or 8 cells, as large and few as possible; each term keeps the variables fixed in its group.

Taught in Sum of products and Karnaugh maps

Full adder

S
sum bit
A,B
input bits
C
carry in
Cout
carry out, the majority function

Applies: One column of binary addition; a half adder has S=A⊕B and carry AB⁠.

Careful: An n-bit adder keeps n sum bits, so 1111 + 0001 gives 0000 with carry 1.

Taught in Adders

Bit tricks

The C operators apply AND, OR, NOT and XOR to every bit at once, so every Boolean law holds for whole bytes.

x & (x - 1)        // clears the lowest set bit; 0 for a power of 2
x & (~x + 1)       // keeps only the lowest set bit
reg &= ~(M1 | M2); // clears two bits (~ binds tighter than |)

Taught in Bit tricks are Boolean algebra

Unit 9 Asymptotics and big-O

Counting loop steps

Loops one after the other add. A call such as strlen(s) in a loop condition hides a whole loop.

LoopsCount
i < n, j < nn2
i < n, j < in(n−1)2
i < n, j < i, k < j(n3)
i = 1; i < n; i *= 2⌈log⁡2n⌉

Taught in Counting steps

Big-O

Definition.

f,g
cost functions
n
input size
C
positive constant
n0
threshold

Careful: O is an upper bound, not a step count, and it says nothing about small n⁠. Ω flips the inequality; Θ is both.

Taught in Big-O, Ω and Θ

Divide-and-conquer recurrences

RecurrenceWhere it arisesGrowth
T(n)=T(n/2)+1binary searchΘ(log⁡n)
T(n)=2T(n/2)+nmerge sortΘ(nlog⁡n)
T(n)=T(n/2)+none pass, then halfΘ(n)
T(n)=2T(n−1)+1Tower of HanoiΘ(2n)

Taught in Divide and conquer

Will it fit in the frame?

t
time
fclk
clock frequency

Applies: At 48 MHz a 10 ms frame holds 480,000 cycles.

Careful: A faster clock buys a constant factor; a better algorithm changes the growth rate.

Taught in Will it fit in the frame?