math 240: discrete structures - github pages

51
MATH 240: Discrete Structures Anna Brandenberger, Binyuan Sun July 6, 2018 This is a transcript of the lectures given by Prof. Ben Seamone during the winter semester of the 2017-2018 academic year (01-04 2018) for the Discrete Structures class (math 240). Subjects covered are: math- ematical foundations of logical thinking and reasoning, mathematical language and proof techniques, quantifiers, functions and relations, partially ordered sets and lattices, induction (Section 1); elementary number theory, modular arithmetic (Section 2); recurrence relations and asymptotics, combinatorial enumeration (Section 3); introduction to graphs, digraphs and rooted trees (Section 4). 1 Logic and Fundamentals 1.1 Propositional Logic Basic Terms Definition 1.1. A proposition or statement is something which can be verified as being either true or false. Examples of propositions and non propositions: Example x = 5 YES x + y NO "This statement is false." NO Definition 1.2. A sentence is a formula consisting of atoms: simple propositions connectors: operations joining atoms Sometimes parentheses are used to denote order of operations (if necessary.) Definition 1.3. The three connectors are: and: "P and Q" = P Q (both are true) or: "P or Q" = P Q (one or the other is true) not: "not P" = ¬P (takes on the opposite truth value of P) P Q P Q P Q ¬P T T T T F T F F T F F T F T T F F F F T Table 1: Basic Truth Table Order of operations: 1. Parentheses 2. ¬ 3. and 4. etc. Definition 1.4. A sentence is a: 1. Tautology if it is always true. 2. Contradiction if it is always false. 3. Contingency otherwise.

Upload: others

Post on 08-Jun-2022

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: MATH 240: Discrete Structures - GitHub Pages

MATH 240: Discrete StructuresAnna Brandenberger, Binyuan Sun

July 6, 2018

This is a transcript of the lectures given by Prof. Ben Seamone duringthe winter semester of the 2017-2018 academic year (01-04 2018) forthe Discrete Structures class (math 240). Subjects covered are: math-ematical foundations of logical thinking and reasoning, mathematicallanguage and proof techniques, quantifiers, functions and relations,partially ordered sets and lattices, induction (Section 1); elementarynumber theory, modular arithmetic (Section 2); recurrence relationsand asymptotics, combinatorial enumeration (Section 3); introductionto graphs, digraphs and rooted trees (Section 4).

1 Logic and Fundamentals

1.1 Propositional Logic

Basic Terms

Definition 1.1. A proposition or statement is something which canbe verified as being either true or false.

Examples of propositions and nonpropositions:

Example

x = 5 YES

x + y NO

"This statement is false." NO

Definition 1.2. A sentence is a formula consisting of

• atoms: simple propositions

• connectors: operations joining atoms

Sometimes parentheses are used to denote order of operations (ifnecessary.)

Definition 1.3. The three connectors are:

• and: "P and Q" = P ∧Q (both are true)

• or: "P or Q" = P ∨Q (one or the other is true)

• not: "not P" = ¬P (takes on the opposite truth value of P)

P Q P ∧Q P ∨Q ¬PT T T T FT F F T FF T F T TF F F F T

Table 1: Basic Truth Table

Order of operations:

1. Parentheses

2. ¬3. ∨ and ∧4. etc.

Definition 1.4. A sentence is a:

1. Tautology if it is always true.

2. Contradiction if it is always false.

3. Contingency otherwise.

Page 2: MATH 240: Discrete Structures - GitHub Pages

2 anna brandenberger, binyuan sun

Example 1.1. Determine if each sentence is a tautology, contradictionor contingency.

1. P ∧ ¬P: Contradiction (c.f. Table 2).

P ¬P P ∧ ¬PT F FF T F

Table 2: Table illustrating a Contradic-tion.

2. ¬(P ∧Q) ∨ (¬P ∨Q): Tautology (c.f. Table 3).P Q ¬P P ∧Q ¬P ∨Q FinalT T F T T TT F F F F TF T T F T TF F T F T T

Table 3: Table illustrating a Tautology.

Can we be more efficient in our logic? An identity is a statementthat two sentences have the same truth values for the same truthvalues of their atoms.

Some simple ones:1 1 Use T for a statement that is alwaystrue, F for a statement that is alwaysfalse.

• Identity:

P ∧T ≡ P

P ∨F ≡ P

• Idempotent:

P ∧ P ≡ P

P ∨ P ≡ P

• Complement:

P ∧ ¬P ≡ F

P ∨ ¬P ≡ T

• Double negation: ¬(¬P) ≡ P

• DeMorgan’s Laws:

¬(¬P ∨ ¬Q) ≡ P ∧Q

¬(¬P ∧ ¬Q) ≡ P ∨Q

• Associative:

P ∧ (Q ∧ R) ≡ (P ∧Q) ∧ R

P ∨ (Q ∨ R) ≡ (P ∨Q) ∨ R

• Distributive:

P ∧ (Q ∨ R) ≡ (P ∧Q) ∨ (P ∧ R)

P ∨ (Q ∧ R) ≡ (P ∨Q) ∧ (P ∨ R)

Conditional Statements

Definition 1.5. "P implies Q" written P =⇒ Q.

Equivalent Phrasings to "P implies Q":

• "If P, then Q".

• "Q if P".

• "P only if Q".

• "Q whenever P".

• "Whenever Q, then also P."

• "P is sufficient for Q."

• "Q is necessary for P."Example 1.2. P = "the sun is shining", Q = "teeth are purple". Thestatement given is P =⇒ Q. To show this is false, you must show Pis true and Q false.

¬(P =⇒ Q) ≡ P ∧ ¬Q

(P =⇒ Q) ≡ ¬(P ∧ ¬Q) double negation

≡ ¬P ∨ ¬(¬Q) DeMorgan’s Law

≡ ¬P ∨Q

P Q ¬P ∨QT T TT F FF T TF F T

Table 4: Table illustrating Example 1.2.

Page 3: MATH 240: Discrete Structures - GitHub Pages

math 240: discrete structures 3

Examples 1.3. using identities:

1. Verify P⇒ (Q ∨ ¬Q) is a tautology.

P⇒ (Q ∨ ¬Q) ≡ P⇒ T ("complement")

≡ ¬P ∨T ("implies")

≡ T (identity)

2. Determine if the following sentence is a tautology, contradiction,or contingency.

[¬P ∨ (¬P ∧Q)] ∧ P ≡ [¬P ∧ P] ∨ [(¬P ∧Q) ∧ P]

≡ F∨ [¬P ∧ P ∧Q]

≡ F∨ [F∧Q]

≡ F∨F ≡ F

Definition 1.6. The contrapositive of P⇒ Q is ¬Q⇒ ¬P.

S = this shape is a squareR = this shape is a rectangleS ⇒ R means if the shape is a squarethen it is a rectangle. ¬R ⇒ ¬S meansif the shape is not a rectangle then it isnot a square.

Proof. Show that (P⇒ Q) ≡ (¬Q⇒ ¬P).

P⇒ Q ≡ ¬P ∨Q

≡ Q ∨ ¬P

≡ ¬(¬Q) ∨ ¬P

≡ ¬Q⇒ ¬P

The converse of P⇒ Q is Q⇒ P. In general P⇒ Q & its converseneed not be related.

Biconditional Statements

Definition 1.7. P⇔ Q ≡ "P and Q are equivalent"

P Q P⇔ QT T TT F FF T FF F T

Table 5: Table illustrating biconditionalstatements.

Two new identities:

• P⇔ Q ≡ (P⇒ Q) ∧ (Q⇒ P)

• P⇔ Q ≡ (P ∧Q) ∨ (¬P ∧ ¬Q)Updated order of operations:

1. Parentheses

2. ¬3. ∨ and ∧4. =⇒ and⇔

Ambiguous statements:

1. A ∧ B ∨ C(A ∧ B) ∨ C ≡ (A ∨ C) ∧ (B ∨ C)A ∧ (B ∨ C) ≡ (A ∧ B) ∨ (A ∧ C)

Page 4: MATH 240: Discrete Structures - GitHub Pages

4 anna brandenberger, binyuan sun

2. P⇒ Q⇒ RCheck that:(P⇒ Q)⇒ R 6≡ P⇒ (Q⇒ R)¬(¬P ∨Q) ∨ R 6≡ ¬P ∨ (¬Q ∨ R)

Phrasing of⇔:

P⇔ Q ≡ P if and only if Q

≡ P if Q, and conversely

≡ P precisely when Q

≡ P is necessary and sufficient for Q

NECC: Q⇒ P, SUFF: P⇒ Q

A note: P ≡ Q and P ⇔ Q essentiallymean the same thing.

Symbolization

Examples 1.4.

1. If you study then, then you will pass 2: S⇒ P 2 S: you studyP: you pass

2. The ground gets wet whenever it rains 3: R⇒W 3 W: the ground gets wetR: it rains

3. The sun is out but it is raining 4: S ∧ R 4 W: the sun is outR: it is raining

4. You cannot scuba dive unless you have had lessons 5: 5 W: can scuba diveR: had lessonsS⇒ L or ¬L⇒ ¬S

5. If you only study under pressure , then you do not learn 6: 6 S: you studyP: you are under pressureL: you learn

(P⇔ S)⇒ ¬L

1.2 Predicate logicPredicate logic = 1st order logic

Justification:Consider a statement like: "Every

positive integer is the sum of twoprimes".

To construct a truth table, we wouldneed infinitely many columns (sincethis statement contains infinitely manyatoms). So this can’t be done in propo-sitional logic.

Definition 1.8. We introduce two quantifiers:

1. ∀ = "for all" = universal quantifier

2. ∃ = "there exists" = "existential quantifier"

Predicates

Definition 1.9. A predicate is a sentence containing variables that iseither true or false.

Examples 1.5. of symbolization:

1. Every even integer n greater than 2 can be expressed as the sum oftwo primes.

Z(n) = n is a positive integer

P(n) = n is the sum of 2 primes

∀n(Z(n)⇒ P(n))

Page 5: MATH 240: Discrete Structures - GitHub Pages

math 240: discrete structures 5

2. "Not everything is about you "7: ¬(∀xY(x)) 7 Y(x) = "x is about you"

3. "When it rains , everything gets wet 8": R⇒ (∀xW(x)) 8 R: "it rains"W(x): "x gets wet"

4. "Every person who wants wine gets asked for ID by the bar-tender"9: ∀x(W(x)⇒ I(x, b)) 9 W(x) = x wants wine;

I(x, y) = y asks x for ID;b = the bartender

We can use equality to symbolize:

Example 1.6. "Sue is the only person who knows how this works":K(x) : x knows how this works∀x(K(x)⇒ x = Sue)

When using multiple quantifiers, order matters (read L to R):

Example 1.7. F(x, y) = "x and y are friends":∀x∃yF(x, y)→ every person has a friend∃x∀yF(x, y)→ someone is friends with everyone

Functions, or variables which depend on other variables are al-lowed.

Example 1.8. "Matt brings a friend":B(x, y) : x brings yf (x) : a friend of xm : Matt

Updated Order of Operations

1. Parentheses

2. ¬3. ∀, ∃ (L to R)

4. ∧,∨5. ⇒,⇔

Theorem 1.1. Negation of predicates:

• ¬(∀xP(x)) ≡ ∃x¬P(x)

• ¬(∃xP(x)) ≡ ∀x¬P(x)

Examples 1.9.

• "Not everything is about you".10 10 Y(x) : x is about you

claim: Everything is about you: ∀xY(x)negation: There is a thing that is not about you: ¬(∀xY(x)) ≡∃x¬Y(x)

• "All cardinals are red".11 11 C(x) : x is a cardinalR(x) : x is red

claim: ∀x(C(x)⇒ R(x))negation: ∃x¬(C(x)⇒ R(x))

≡ ∃x¬(¬C(x) ∨ R(x))≡ ∃x(C(x) ∧ ¬R(x))

• "There is an even number greater than three which is prime".12 12 E(x) : x is evenG(x) : x is greater than 3

P(x) : x is primeclaim: ∃x(E(x) ∧ G(x) ∧ P(x))negation: ∀x¬((E(x) ∧ G(x) ∧ P(x))

≡ ∀x[¬E(x) ∨ ¬G(x) ∨ ¬P(x)]

Page 6: MATH 240: Discrete Structures - GitHub Pages

6 anna brandenberger, binyuan sun

A sentence of the form ∀x(P(x) ⇒ Q(x)) is called vacuously trueif P(x) is F ∀x. This is because P ⇒ Q is true whenever P is false.The rule holds because its never given a chance to fail.

Example 1.10. Every McGill prof with 200 years of experience is a

great golfer .13 13 M(x) : McGill profO(x) : 200 years of experienceG(x) : great golfer

Proposition 1.2. To disprove a claim ∀x(P(x) ⇒ Q(x)), we show ∃xfor which P(x) ∧ ¬Q(x) is true. This x is called a counterexample to theclaim.

Arguments

Definition 1.10 (Rule of inference). An argument is a finite collec-tion of statements A1, A2, . . . , An (called predicate, or hypothesis)followed by statement B called the conclusion. An argument is valid ifB is true whenever all A1, A2, . . . , An are true.

Proposition 1.3. To validate an argument:

1. Check a truth table (is B true when A1, A2, . . . , An are all true?)

2. Show A1 ∧ A2 ∧ . . . , An =⇒ B is a tautology

Some Rules of Inference(more posted on MyCourses)

1. Modus ponensArguments: p =⇒ qConclusion: p

q

2. Modus tollensP =⇒ Q¬Q¬P

1.3 Set Definitions and Operations

Definition 1.11. A set is a collection of distinct objects, called ele-ments or members.

Notation

a ∈ S means a is an element of the set Sa 6∈ S means a is not an element of the set S

Basic sets

N: the natural numbersZ: the integersR: the real numbers∅: the empty set

Writing down sets:

- list the elements in any order inside {}

- if the elements follow a pattern, we sometimes use ". . . " to denotethat the elements continues

Examples 1.11.

1. Integers from −2 to 2{−2,−1, 0, 1, 2}or {0, 1,−1, 2,−2}or {−2,−1, 0, 0, 1, 2}

2. Integers from 1 to 100{1, 2, 3, . . . , 100}

3. Natural numbersN = {1, 2, 3, . . . }

4. Some attributes of John Smith{John Smith, 12345678, [email protected], {MATH240, COMP251, COMP 273}}

Page 7: MATH 240: Discrete Structures - GitHub Pages

math 240: discrete structures 7

Definition 1.12. Set builder notation:{element | rule the element obeys to be in the set}

Examples 1.12.

1. Q the rational numbers{m

n |m ∈ Z, n 6= 0}2. C the complex numbers{a + b|a ∈ R, b ∈ R, i2 = −1}Theorem 1.4. Two sets are equal if and only if they either contain the same

elements or are both empty.

Examples 1.13.

1. {x ∈ R|x2 − 3 = 0} = {√

3,−√

3}

2. {x ∈N|x2 − 3 = 0} = ∅

3. {n ∈ Z|n2 + 1 = 0} = {x|x > 0∧ x < 0}

4. Q : {∅} ?= ∅ no! LHS contains an element ∅

Definition 1.13. We write A ⊆ B and say A is a subset of B if everyx ∈ A also obeys x ∈ B.

Example 1.14. ∅ ⊂ X for every set XN ⊆ R ⊆ C

{1, 2} ⊆ {1, 2, π}

Notation {1, 2} 6⊆ {1, 2}{1, 2} ⊂ {1, 2, π}

Proposition 1.5. If A ⊆ B and A 6= B, we can write as above and say A isa proper subset of B.

Examples 1.15.{a, b} ∈ {a, b, c}? F{a, b} ⊆ {a, b, c}? T{a, b} ∈ {a, b, {a, b}}? T{a, b} ⊆ {a, b, {a, b}}? T

Proposition 1.6. A = B⇔ A ⊆ B and B ⊆ A

Definition 1.14. U = the universal set = the set containing every-thing (that we are interested in).

Figure 1: A ∪ B Figure 2: A ∩ B

Figure 3: B \ A Figure 4: A

Figure 5: A⊕ B

Venn diagrams

– union: A ∪ B = {x | x ∈ A ∨ x ∈ B}

– intersection: A ∩ B = {x | x ∈ A ∧ x ∈ B}

– difference: A \ B = {x | x ∈ A ∧ x 6∈ B}

– complement: A = {x | x 6∈ A} = U \ A

– symmetric difference: A⊕ B = {x | (x ∈ A ∨ x ∈ B) ∧ x 6∈ A ∩ B}= {x | x ∈ A ∪ B ∧ x 6∈ A ∩ B}

Page 8: MATH 240: Discrete Structures - GitHub Pages

8 anna brandenberger, binyuan sun

Definition 1.15. Power set of A: P(A) = {B | B ⊆ A} Example 1.16. P({a, b, c}) ={∅, {a}, {b}, {c}, {a, b}, {b, c}, {a, c}, {a, b, c}}

Proof Methods

Most statements to prove are of the form P⇒ Q or P⇔ Q.

Proposition 1.7. Proof methods for P⇒ Q:

1. Direct proof: Assume P is true. Show Q is true, usually with someapplication of the transitive rule of inference.

2. Contrapositive proof: Prove the contrapositive (¬Q⇒ ¬P).

Examples 1.17. P⇒ R1 ⇒ R2 ⇒ QSet Identities (to be posted)

• complement law: A ∪ A = U, A ∩ A = ∅

• demorgan: A ∪ B = A ∩ B, A ∩ B = A ∪ B

• distributive: A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C),A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C)

Example 1.18. Prove A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C)Recall: X = Y ⇔ X ⊆ Y and Y ⊆ X. 14 14 We must show each of the sets in the

statement is contained in the other as asubset.Proof.

1. Show A ∩ (B ∪ C) ⊆ (A ∩ B) ∪ (A ∩ C):Let x ∈ A ∩ (B ∪ C)

⇒ x ∈ A & x ∈ (B ∪ C)

⇒ x ∈ A & (x ∈ B || x ∈ C)

⇒ (x ∈ A & x ∈ B) or (x ∈ A&x ∈ C)

⇒ x ∈ A ∩ B || x ∈ A ∩ C

⇒ x ∈ (A ∩ B) ∪ (A ∩ C)

2. Show (A ∩ B) ∪ (A ∩ C) ⊆ A ∩ (B ∪ C):Let y ∈ (A ∩ B) ∪ (A ∩ C)Either y ∈ A ∩ B or y ∈ A ∩ C ⇒ y ∈ A and either y ∈ B or y ∈ C

⇒ y ∈ (B ∪ C)

(A ∩ B) ∪ (A ∩ C) ⊆ A ∩ (B ∪ C)

A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C)

Definition 1.16. Another operation on sets is the Cartesian productof A and B denoted A× B = {(a, b) | a ∈ A, b ∈ B}

Page 9: MATH 240: Discrete Structures - GitHub Pages

math 240: discrete structures 9

Proposition 1.8. Two elements in A × B are equal precisely when they arein both coordinates: (a1, b1) = (a2, b2)⇔ a1 = a2 and b2 = b1

Example 1.19. A = {1, 2}, B = {3, 4}A× B = {(1, 3), (2, 3), (1, 4), (2, 4)}B× A = {(3, 1), (3, 2), (4, 1), (4, 2)}Example 1.20. Prove that A× (B ∪ C) ⊆ (A× B) ∪ (A× C)

Proof. ⇒ x ∈ A and y ∈ B ∪ CIf y ∈ C, then (x, y) ∈ A× C; if y ∈ B, then (x, y) ∈ A× BSo either (x, y) ∈ A× B or (x, y) ∈ A× C⇒ (x, y) ∈ (A× B) ∪ (A× C)⇒ A× (B ∪ C) ⊆ (A× B) ∪ (A× C)

1.4 Relations and Equivalence Relations

Definition 1.17. A binary relation R from A to B is a subset of A× B.

Using the example above, R ={(1, 3), (1, 4)} is a binary relationfrom A to B (one of many).Proposition 1.9. A binary relation on A is a subset of A2.

Example 1.21.{(x, y)|y = x2} is a bin. rel. on R.{(x, y)|x = y2} is a bin. rel. on R.{(m, n)|mn ∈ Z} is a bin rel on Z.

Definition 1.18. Useful properties: Let R be a binary relation on A.R is Definition

reflexive ∀a ∈ A, (a, a) ∈ Rsymmetric (a, b) ∈ R⇒ (b, a) ∈ R

antisymmetric (a, b) ∈ R and (b, a) ∈ R ⇒ a = btransitive (a, b), (b, c) ∈ R ⇒ (a, c) ∈ R

Example 1.22. Determine if the relation has any of the 4 propertiesdefined above: R = {(x, y) ∈ R2|x ≤ y}

– Reflexive: ∀x ∈ R, x ≤ x ⇒ (x, x) ∈ R

– Symmetric: (1, 2) ∈ R and (2, 1) 6∈ R

– Antisymmetric: If (x, y) ∈ R and (y, x) ∈ R, then x ≤ y andy ≤ x ⇒ x = y

– Transitive: If (x, y), (y, z) ∈ R, then x ≤ y ∩ y ≤ z ⇒ (x, z) ∈R �

Definition 1.19. A binary relation on A is a partial order on A is it isreflexive, antisymmetric, and transitive

Example 1.23. R = {(a, b) ∈ Z2 | a− b is even} Note: n is even⇔ n = 2k for somek ∈ Z

– Reflexive: ∀x ∈ Z, a− a = 0 is even ⇒ (a, a) ∈ R

– Symmetric: (a, b) ∈ R⇒ a− b even⇒ b− a even ⇒ (b, a) ∈ R

Page 10: MATH 240: Discrete Structures - GitHub Pages

10 anna brandenberger, binyuan sun

– Antisymmetric: (16, 8) ∈ R & (8, 16) ∈ R but 16 6= 8

– Transitive: If (a, b) ∈ R and (b, c) ∈ R, then

a− b = 2k

b− c = 2l⇒ a− c = 2k + 2l = 2(k + l) is even.

Definition 1.20. A binary relation on A is an equivalence relation onA if it is reflexive, symmetric, and transitive.

Definition 1.21. A total order on A is a partial order R where ∀a, b ∈A, either (a, b) or (b, a) is in R. (Linear order.)

Remark 1. Not every partial order is a total order.

Example 1.24. Let A be some set R = {(x, y)|x, y ∈ P(A), x ⊆ y}Why is this not a total order?A = {1, 2, 3}, M = {1}, N = {2, 3}(x, y) 6∈ R ∵ M 6⊆ N ∧ N 6⊆ MShow it is a partial order.

– Reflexive: ∀x ⊆ A, is (x, x) ∈ R?

– Antisymmetric: (x, y) ∈ R ∧ (y, x) ∈ R⇒ X ⊆ Y ∧Y ⊆ X⇒ X = Y

– Transitive: (X, Y) ∈ R, (Y, Z) ∈ R⇒ X ⊆ Y, Y ⊆ Z⇒ X ⊆ Z⇒ (X, Z) ∈ R

Equivalence RelationsRecall: Definition 1.20: an equivalencerelation is a relation R which is:

• Reflexive

• Symmetric

• Transitive

Definition 1.22. We say a is related to b in a equivalent relation R if(a, b) ∈ R, denoted as follows:

Notation 1.10. a is related to b in a equivalent relation R:

aRb a ∼R b a ∼ b (if R is understood)

Definition 1.23. If R is an equivalence relation, the equivalence classof an element a ∈ R is denoted [a] or a, is [a] = {x|x ∼ a}

Example 1.25. 1. Show R = {(x, y) ∈ Z2|x− y = 3k for some k ∈ Z}is an equivalence class.

2. What are [0], [1], [2], [3]?

Page 11: MATH 240: Discrete Structures - GitHub Pages

math 240: discrete structures 11

1. R: x− x = 0⇒ (x, x) ∈ RS: x− y = 3k⇒ y− x = 3k ⇒ (x, y) ∈ R⇒ (y, x) ∈ RI: (x, y) ∈ R, (y, z) ∈ R⇒ x− y = 3k, y− z = 3l ⇒ x− z = 3(k + l) ∈ Z⇒ (x, z) ∈ R

2. [0] = {x|x ∼ 0} = {x|x − 0 = 3k} = {x|x = 3k} =

{. . . ,−6,−3, 0, 3, 6, . . . }[1] = {x|x ∼ 1} = {x|x− 1 = 3k} = {x|x = 3k + 1, k ∈ Z}[2] = {x|x ∼ 2} = {x|x− 2 = 3k} = {x|x = 3k + 2, k ∈ Z}[3] = {x|x ∼ 2} = {x|x − 3 = 3k} = {x|x = 3k + 3, k ∈ Z} =

{x|x = 3(k + 1), k ∈ Z} = {x|x = 3l, l ∈ Z} = [0]

Theorem 1.11. Let a ∈ A, R an equivalence relation to A. For any x ∈ A,[x] = [a]⇔ x ∼ a.

To prove P ⇔ Q, prove P ⇒ Q andQ⇒ PProof. (⇐) Suppose [x] = [a] ∵ x ∈ [x]⇒ x ∈ [a]⇒ x ∼ a

(⇒) Suppose x ∼ a, We will show [x] ⊆ [a]︸ ︷︷ ︸(a)

and [a] ⊆ [x]︸ ︷︷ ︸(b)

(a) Let y ∈ [x]⇒ y ∼ x.Since x ∼ a, by transitivity, y ∼ a⇒ y ∈ [a]⇒ [x] ⊆ [a]

(b) z ∈ [a]⇒ z ∼ a⇒ z ∼ x (since x ∼ a)⇒ z ∈ [x]⇒ [a] ⊆ [x]

Together, this gives [a] = [x]

Theorem 1.12. Let a, b ∈ A, R an equivalence relation of A.[a] 6= [b]⇔ [a] ∩ [b] = ∅

Proof. (⇒) If [a] ∩ [b] = ∅ then since a ∈ [a], a 6∈ [b]⇒ [a] 6= [b].

(⇐) We will prove the contrapositive: show [a] ∩ [b] 6= ∅⇒ [a] = [b].[a] ∩ [b] 6= ∅ ⇒ ∃x, x ∈ [a] ∩ x ∈ [b] ⇒ x ∼ a ∩ x ∼ b ⇒ [x] =[a] ∩ [x] = [b]⇒ [a] = [b]

Recap: P ⇒ Q:Direct proof, Contraposi-tive (direct proof of ¬Q⇒ ¬P)

P ⇔ Q : P ⇒ Q ∧ Q ⇒ P, P ⇒ Q ∧¬P⇒ ¬Q, [¬Q⇒ ¬P ∧ ¬P⇒ ¬Q]1.5 Proof by Contradiction

principle: If your assumption leads, by logical steps, to somethingfalse (a contradiction), then the assumption must have been wrongand thus the opposite statement is right.Following are some proofs using this method:

Page 12: MATH 240: Discrete Structures - GitHub Pages

12 anna brandenberger, binyuan sun

Theorem 1.13.√

2 6∈ Q

Proof. Suppose√

2 ∈ Q

⇒√(2) =

mn

, m, n ∈ Q

We may assume, without loss of generality (WLOG), that mn is in

reduced form, i.e they share no common factors.√(2) =

mn⇒ 2 =

m2

n2

⇒ m2 = 2n2

⇒ m is even ⇒ m = 2k for some k ∈ Z

⇒ (2k)2 = 2n2 ⇒ 4k2 = 2n2 ⇒ 2k2 = n2

⇒ n is even

=⇒ m and n have a common factor of 2. ⇒⇐Thus our assumption

√2 ∈ Q was wrong.

Theorem 1.14 (Fundamental Theorem of Arithmetic). Every n ∈ N

can be written as a product of primes that is unique up to order.

Proof. given later (Section 2).

Theorem 1.15. There are infinitely many primes.

Proof. Suppose there are finitely may primes p1, p2, . . . , pn

Let q = p1 p2 . . . pn + 1. Theorem 1.14 (Fundamental Theorem ofArithmetic) states that q is divisible by some prime: wlog, p1 ⇒ q =

p1k for some k ∈ Z.

q− p1 p2 . . . pn = 1

p1k− p1 p2 . . . pn = 1

p1︸︷︷︸≥2

(k− p2 . . . pn)︸ ︷︷ ︸∈N

= 1 ⇒⇐

Thus our assumption that there are finitely many primes was wrong.

Proposition 1.16. Proving Existential Statements (∃xP(x))

1. Give the example.

2. When you can’t give the example, a "non constructive proof" can some-times be found.

Example 1.26. 1. "There exists an even prime". It’s 2.

Page 13: MATH 240: Discrete Structures - GitHub Pages

math 240: discrete structures 13

2. "There is a real solution to x2 − x− 1 = 0". It’s 1±√

52 .

Example 1.27. "There are irrational numbers x, y such that xy ∈ Q.

Proof. We know√

2 6∈ Q.

Consider√

2√

2.

If√

2√

2 ∈ Q, then x =√

2, y =√

2 is our example.

If√

2√

2 6∈ Q, then consider√

2√

2, y =

√2 : (

√2√

2)√

2 =√

2√

2∗√

2=√

22= 2 ∈ Q.

In either case, we ave an example that proves such x, y exist.

Page 14: MATH 240: Discrete Structures - GitHub Pages

14 anna brandenberger, binyuan sun

2 Number TheoryThe study of properties of integers.

2.1 Division

Theorem 2.1 (Division Algorithm).If a, b ∈ Z, b 6= 0, then ∃q, r ∈ Z such that:a = qb + r, with 0 ≤ r < |b|.Furthermore, q and r are unique. t

The proof of this algorithm uses the following as main tool:

Lemma 2.2 (Well Ordering Principle). If A ⊆ N, then A has a smallestelement.

Proof. of the Division Algorithm (Theorem 2.1)Consider the case where a, b > 0. Look at the following multiples

of b : 0, b, 2b, 3b, 4b, · · · . There is some multiple of b > a. Let B =

Example 2.1. (2a)b = (2b)a ≥ 2a > a{kb|k ∈N, kb > a}By the Well Ordering Principle (Lemma 2.2), B has a smallest ele-

ment. Call it (q + 1)b.

qb ≤ a < (q + 1)b

Let r = a− qb, then:

a = qb + r

and:

0 ≤ a− qb < (q + 1)b− qb

0 ≤ r < b

what about uniqueness?Assume ∃q1, q2, r1, r2 such that a = q1b + r1, a = q2b + r2. We will

show q1 = q2 and r1 = r2, and so distinct solutions are impossible.0 = (q1 − q2)b + (r1 − r2), (q1 − q2)b = r2 − r1.But

0 ≤ r1 < b

−b < −r2 ≤ 0

⇒ −b < r1 − r2 < b

Since r1 − r2 is a multiple of b, we have r1 − r2 = (0)(b) ⇒ r1 = r2

and (q1 = q2)b = 0⇒ q1 = q2. Therefore q and r are unique.A note about proving the remainingcases: you can use the a > 0, b > 0 case.

Definition 2.1. b divides a ⇔ ∃q such that a = qb. Write b | a if b di-vides a and b - a if b does not divide a.

Page 15: MATH 240: Discrete Structures - GitHub Pages

math 240: discrete structures 15

Proposition 2.3. g is a divisor of a if g | a and g | b and if g is the largestsuch integer, we call g the greatest common divisor or a and b; we write g =

gcd(a, b).

Example 2.2. 87︸︷︷︸a

= 4( 21︸︷︷︸b

) + 3︸︷︷︸r

gcd(a, b) = 3gcd(b, r) = 3

If a 6= 0 then gcd(a, 0) = a.

Let’s prove some things about divisors.

Lemma 2.4. If c | a and c | b then, c | xa + yb ∀x, y ∈ Z.

Proof. ∃k, l ∈ Z such that a = kc, b = lc ⇒ xa + yb = x(kc) + y(lc) =(xk + yl)c⇒ c | (xk + yl)c = c | (xa + yb)

Lemma 2.5. If a = qb + r, then gcd(a, b) = gcd(b, r).

Proof. If a = b = 0 or b = r = 0, then the gcd’s are undefined. Ifa 6= 0, then gcd(a, 0) = a. Let g1 = gcd(a, b) and g2 = gcd(b, r). Wehave that g1 | a and g1|b.⇒ g1 | a− qb⇒ g1 | r⇒ g1 divides r and b⇒ g1 ≤ g2

Similarly, g2 | b and g2 | r⇒ g2 | qb + r (by lemma above)⇒ g2 ⇒ g2 ≤ g1 (because g2 | a & g2 | b)g1 = g2

Proposition 2.6 (Euclidean Algorithm).Suppose a > b (a, b ∈N). Then write:

a = q1b + r1 (0 ≤ r1 < b)

b = q1r1 + r2 (0 ≤ r2 < r1)

r1 = q2r2 + r3 (0 ≤ r3 < r2)

and continue until the remainder becomes 0, rk+1 = 0. Then rk = gcd(a, b)

Proof.does this terminate?This set has a smallest element by W.O.P., this is rk.does it work?By previous lemma,gcd(a, b) = gcd(b, r1) = gcd(r1, r2) = gcd(rk, 0) = rk

Example 2.3. Find gcd(630, 196) = 14

630 = 3(196) + 42

196 = 4(42) + 28

42 = 1(28) + 14

28 = 2(14) + 0

As a consequence of the EuclideanAlgorithm, ∃x, y such that gcd(a, b) =xa + yb:

14 = (42)− 1(28)

= (42)− 1[196− 4(42)]

= 5(42)− 1(196)

= [630− 3(196)]− 1(196)

⇒ 14 = 5(630)− 16(196)Definition 2.2. a, b ∈N are relatively prime if gcd(a, b) = 1.

Page 16: MATH 240: Discrete Structures - GitHub Pages

16 anna brandenberger, binyuan sun

Example 2.4. Show 91 and 8 are relatively prime:

91 = 11(8) + 3

8 = 2(3) + 2

3 = 1(2) + 1

2 = 2(1) + 0

Again, ∃s, t ∈ Z s.t. 91s + 8t = 1

1 = (3)− 1(2)

= 3− 1(8− 2(3))

= 3(3)− 1(8)

= 3(91− 11(8))− 1(8)

= 3︸︷︷︸s

(91)− 34︸︷︷︸t

(8)

Theorem 2.7. If a and b are relatively prime, then ∀n ∈N, ∃x, y ∈ Z s.t.

n = xa + yb

Proof.gcd(a, b) = 1

⇒∃s, t sa + tb = 1

⇒(sn)a + (tn)b = n

⇒xa + yb = n

Corollary 2.8. If gcd(a, b) = 1 and a | bc, then a | c.

Proof.∃x, y such that ax + by = 1

⇒ c = cax + cby

Since a | a and a | bc

a | a(xc) + bc(y)⇒ a | c(ax + by)

⇒ a | c

Definition 2.3. p ∈N is called prime if d | p⇒ d = 1 or p

Lemma 2.9. ∀n ∈N, n ≥ 2, ∃p | n, p prime.

Proof. Suppose n has no prime divisor. The set of all positive integerswith no prime divisors would be non-empty. By WOP (Lemma 2.2),it has a smallest element. Call this m.15. Since m | m, m is not prime. 15 Note: This variation on a proof by

contradiction uses a minimal counterex-ample

Thus ∃d, 1 < d < m such that d | m. By minimality of m, d has aprime divisor, say p. p | d and d | m⇒ p | m ⇒⇐

Page 17: MATH 240: Discrete Structures - GitHub Pages

math 240: discrete structures 17

Lemma 2.10. If n ∈ N, n composite, n ≥ 2, then ∃p ∈ N such that p | n,p prime and p ≤

√n.

Proof. n composite⇒ n = ab for some a, b ∈N. WLOG, a ≤ b.Claim: a ≤

√n.

If not, a >√

n and b ≥ a >√

n⇒ ab >√

n√

n = n ⇒⇐∃p | a, p prime⇒ p ≤ a ≤

√n (∃p | a, a | n⇒ p | n)

Lemma 2.11. p | ab, p prime =⇒ p | a or p | b

Proof. p | a =⇒ done.p - a =⇒ gcd(a, p) = 1 =⇒ p | b.

Corollary 2.12. p | a1 . . . ak ⇒ p | ai for some i

Theorem 2.13 (Fundamental Theorem of Arithmetic).For an n ∈ N, n ≥ 2, n = p1 p2 . . . pk for some primes p1, p2, . . . , pk.

This representation is unique.

Proof. Suppose n = p1 p2 . . . pk and n = q1q2 . . . ql (all pi, qi prime).⇒ p1 p2 . . . pk = q1q2 . . . ql . Cancel any common prime factors. Ifthere’s anything left, pi, then pi | qi ⇒ pi = qi. ⇒⇐

The two representations must be identical.

2.2 Congruence and Modular Arithmetic

Definition 2.4. Let n ∈ N. We say a, b ∈ Z are congruent modulo niff n | (a− b). We write a ≡ b (mod n).

Example 2.5.

13 ≡ 83 (mod 10)

736 ≡ −1044 (mod 2)

Theorem 2.14. Rn = {(a, b) ∈ Z2 | n|(a− b)} is an equivalence relation.

Proof. To be proved.

Lemma 2.15. For n ∈ N if a = qn + r for some q ∈ Z, 0 ≤ r < n, thena ∼ r.

Proof.a = qn + r

⇒a− r = qn

⇒n | a = r

⇒(a, r) ∈ Ri

Page 18: MATH 240: Discrete Structures - GitHub Pages

18 anna brandenberger, binyuan sun

Example 2.6. Find an integer 0 ≤ k ≤17 such that

1. 18 ≡ k (mod 17)⇒ k ≡ 1 (mod 17)

2. −18 ≡ (mod 17)−18 ≡ −1 ≡ 16 (mod 17)

Corollary 2.16. [a] = [r] in Rn where r is the remainder of a after divisionby n.

Corollary 2.17. The equivalence classes of Rn = {(a, b) ∈ Z2 | n | (a, b)}are [0], [1], . . . , [n− 1].

Equivalent statements:

1. a ≡ b (mod n)

2. n | (a− b)

3. a− b ≡ 0 (mod n)

4. a ∈ [b] ∈ Rn

5. b ∈ [a] ∈ Rn

6. [a] = [b] ∈ Rn

Operations

Lemma 2.18. If a ≡ b (mod n) and x ≡ y (mod n) then:

1. (a± x) ≡ (b± y) (mod n)

2. ax ≡ by (mod n)

Proof.

1. n | (a− b) and n | (x− y)⇒ n | (a± x)− (b± y)⇒ (a± x) ≡ (b± y) (mod n)

2. Note that ax− by = ax− ay + ay− by = a(x− y) + y(x− y)∵ n | (x− y) ∧ n | (a− b)

⇒ n | [a(x− y) + y(a− b)]

= n | (ax− by)

= ax ≡ by (mod n)

Example 2.7. Solve

2x + 3y ≡ 1 (mod 6)

x + 3y ≡ 5 (mod 6)

3x + 6y ≡ 6 (mod 6)

⇒ 3x ≡ 0 (mod 6)

=⇒ x = 0, 2, 4 (mod 6) are the possibilities.

Page 19: MATH 240: Discrete Structures - GitHub Pages

math 240: discrete structures 19

If x ≡ 0 mod 6⇒ 3y ≡ 5 (mod 6)

But 3 6 | 3y− 5⇒ 6 6 | 3y− 5

So 3y 6≡ 5 mod 6 ∀y ∈ Z

If x ≡ 2 mod 6⇒ 2 + 3y ≡ 5 mod 6

⇒ 3y ≡ 3 mod 6

⇒ y ≡ 1 mod 2

Check: y ≡6 0, 1, 6 2, 3, 6 4, 5

ka ≡ kb mod kn⇔ a ≡ b mod n

If x ≡ 4 mod 6⇒ 4 + 3y ≡ 5 mod 6

⇒ 3y ≡ 1 mod 6

But 3 6 | 3y− 1⇒ 6 6 | 3y− 1

So no solutions.

=⇒ Final Solutions:

x ≡ 2 mod 6

y ≡ 1, 3, 5 mod 6(y ≡ 1 mod 2)

Proposition 2.19. If ac ≡ bc mod n and gcd(c, n) ≡ 1, then a ≡ bmod n.

Proof.

ac ≡ bc mod n

⇒ n | ac− bc

⇒ n | c(a− b)

⇒ n | a− b since gcd(c, n) = 1⇒ a ≡ b mod n

Example 2.8. Solve 2x ≡ 1 mod 9

2x ≡ 1 mod 9

⇒ 2x ≡ 10 mod 9

since gcd(2, 9) = 1

⇒ x ≡ 5 mod 9

Theorem 2.20. Let n ∈ N, a ∈ Z. Then gcd(a, n) = 1 ⇔ ∃s ∈ Z suchthat sa ≡ 1 mod n, where we call s the multiplicative inverse.

Proof.

(⇒) : gcd(a, n) = 1⇒ ∃s, t ∈ Z such that sa + tn = 1⇒ n | (sa− 1)⇒ sa ≡ 1 mod n

(⇐) : If ∃s, sa ≡ 1 mod n⇒ ∃q such that sa− 1 = qn⇒ 1 = sa− qnIf ∃d s.t. d | a and d | n:⇒ d | 1⇒ gcd(a, n) = 1

Page 20: MATH 240: Discrete Structures - GitHub Pages

20 anna brandenberger, binyuan sun

Example 2.9. Find the inverse of 91 mod 190.

190 = 2(91) + 8

91 = 11(8) + 3

8 = 2(3) + 2

3 = 1(2) + 1

2 = 2(1) + 0

Backtracking gives: . . .

1 = (71)(91)− (34)(190)

(71)(91)− 1 = (34)(190)︸ ︷︷ ︸≡0 mod 190

⇒ (71)(91) ≡ 1 mod 190

⇒ 91−1 ≡ 71 mod 190

⇔ 71−1 ≡ 91 mod 190

since 190 | (1− (71)(91))

Example 2.10. Find x such that 2x ≡ 1 mod 9 (cont. Example 2.8),aka find 2−1 mod 9.

9 = 4(2) + 1⇒ 1 = 9− 4(2)

2 = 2(1) + 0

⇒ (−4)(2) ≡ 1 mod 9

2−1 ≡ −4 ≡ 5 mod 9

So:Not using inverse:

2x ≡ 1 mod 9

⇒ 10x ≡ 5 mod 9

⇒ (1)x ≡ 5 mod 9

⇒ x ≡ 5 mod 9

Using inverse:

2x ≡ 1 mod 9

⇒ x ≡ (1)(2−1) mod 9

⇒ x ≡ 5 mod 9

Why no solutions for g - b? (recallg = gcd(a, n))

ax ≡ b mod n

⇒ ax− b = kn

⇒ b︸︷︷︸g-b

= ax− kn︸ ︷︷ ︸divisible by g

⇒ no solution.

Solving Algorithm (ax ≡ b mod n)

1 if gcd(a, n) = 12 find a−1 mod n backtracking from Euclidian Algorithm,3 return x ≡ a−1b mod n

// simplify to x = z mod n// all solutions: x = z + nk, k ∈ Z

4 else gcd(a, n) = g 6= 15 if g | b

6 return Solving Algorithm

(ag x ≡ b

g mod ng

)// solution has g equivalence classes mod n// i.e. x ≡ z + n

g k mod n where x < n7 else g - b8 return no solution.

Page 21: MATH 240: Discrete Structures - GitHub Pages

math 240: discrete structures 21

Example 2.11. Solve if possible:

1. 91x ≡ 10 mod 190gcd(91, 190) = 1⇒ there is a solution. Use 91−1 ≡ 71 mod 190.

91x ≡ 10 mod 190

⇒ x ≡ (10)(91−1) mod 190

≡ (10)(71) mod 190

≡ 710 mod 190

≡ 3(190) + 140 mod 190

⇒ x ≡ 140 mod 190

2. 92x ≡ 10 mod 196gcd(92, 166) = 4 using Euclidian Algorithm.

92 = 22 · 23

196 = 22 · 72 4 - 10 =⇒ no solution

3. 92x ≡ 12 mod 196gcd(92, 196) = 4: divide both sides of equation and modulus by 4.23x ≡ 3 mod 49gcd(23, 49) = 1⇒ 23−1 exists. Using Euclidian Algorithm:

49 = 2(23) + 3

23 = 7(2) + 2

3 = 1(2) + 1

2 = 2(1) + 0

1 = 3− 1(2)

Backtracking:

1 = 3− 1(23− 7(3))

= 8(3)− 1(23)

= 8(49− 2(23))− (23)

= 8(49)− 17(23)

1 ≡ 8(49)︸ ︷︷ ︸≡0

−17(23) mod 49

1 ≡ (−17)(23) mod 49

⇒ 23−1 ≡ −17 mod 49

≡ 32 mod 49

So:

92x ≡ 12 mod 196⇔ 23x ≡ 3 mod 49

x ≡ 3(23)−1 mod 49

x ≡ 3(32) mod 49

⇔ x ≡ 96 mod 49

⇔ x ≡ 47 mod 49

What if we wanted all solutions modulo196?

Every solution is x = 47 + 49k, k ∈ Z

For k = 0, 1, 2, 3: x = 47, 96, 145, 194.These correspond to the solution’sequivalence classes mod 196.

x ≡ 47, 96, 145, 194 mod 196

Page 22: MATH 240: Discrete Structures - GitHub Pages

22 anna brandenberger, binyuan sun

Theorem 2.21 (Fermat’s Little Theorem). If p is a prime and a is any in-teger, then ap−1 ≡ 1 mod p. (As a consequence: ap ≡ a mod p.) We canuse this to quickly simplify large powers mod p.

Proof. Later (posted).

Simplifying Algorithm (ax mod p)

1 if p prime2 Rewrite x = q(p− 1) + r

// q ∈ Z, 0 ≤ r < p3 return ax ≡ aq(p−1)+r

≡(

ap−1)q

ar mod p

≡ ar mod p

Example 2.12. Find 239674 mod 523We can check 523 is prime.

Rewrite 39674 by dividing by 522: 39674 = 76(522) + 2.

239674 ≡ 2(76)(522)+2 mod 523

≡ ( 2522︸︷︷︸≡1 by FLT

)76 ∗ 22 mod 523

≡ (1)764 mod 523 ≡ 4 mod 523

Example 2.13.

47625377 mod 13 ≡ [336(13) + 4]5367

≡ 45367 mod 13

≡ 4(447)(12)+3 mod 13

≡ ( (4)12︸ ︷︷ ︸≡1 by FLT

)447 ∗ 43 mod 13

≡ 64 mod 13

≡ 12 mod 13

Example 2.14. Show x97 − x− 1 ≡ 0 mod 97 has no solution.

x97 ≡ x mod 97 (FLT)

x− x + 1 ≡ 0 mod 97 =⇒ 1 ≡ 0 mod 97

1 6≡ 0 mod 97 ⇒⇐=⇒ no solution

end of material for midterm 1

2.3 RSA Encryption

Notes posted.

Page 23: MATH 240: Discrete Structures - GitHub Pages

math 240: discrete structures 23

3 CombinatoricsGlorified counting. How do we count?

3.1 Proof by Induction

Definition 3.1. Induction is used to prove a statement S(n) is true forall n ∈N by proving:

1. Base case: S(1) true,

2. Inductive step: S(n)⇒ S(n + 1).

why does this work — ? S(1)⇒ S(2)⇒ S(3)⇒ . . .

Example 3.1. Prove 1 + 2 + 3 + · · ·+ (n− 1) + n = n(n+1)2 for n ∈N

Proof. Base Case: n = 1: 1 = (1)(2)2 X

Inductive Step: Assume 1 + 2 + ... + n = n(n+1)2 (hypothesis).

Show 1 + 2 + · · ·+ (n + 1) = (n+1)(n+2)2

1 + 2 + · · ·+ (n) + (n + 1) =n(n + 1)

2+ (n + 1)

= (n + 1)(n2+ 1)

=(n + 1)(n + 2)

2

Example 3.2. Prove that the sum of odd

integersn∑

i=1(2i− 1) = n2.

1 = 1

1 + 3 = 4

1 + 3 + 5 = 9

1 + 3 + 5 + 7 = 16

Proof. Base case: n = 1:1∑

i=1(2i− 1) = 1

Inductive step :

Assumen∑

i=1(2i− 1) = n2

Show =⇒n+1∑

i=1(2i− 1) = (n + 1)2

n

∑i=1

(2i− 1) = n2 =n

∑i=1

(2i− 1)

= n2 + [2(n + 1) + 1]

= n2 + 2n + 1

= (n + 1)2Example 3.3. Proven∑

i=0(i)(i!) = (n + 1)!− 1

Note: this is a statement taking n ≥ 0 (an integer) as the variable.

Proof. Base case: n = 0n∑

i=0(i)(i!) = 0 X

Inductive step: Assumen∑

i=0(i)(i!) = (n + 1)!− 1

Show =⇒n+!∑

i=0(i)(i!) = (n + 2)!− 1

n+1

∑i=0

(i)(i!) =n

∑i=0

(i)(i!) + (n + 1)(n + 1)!

= [(n + 1)!− 1] + (n + 1)(n + 1)!

= (n + 1)![1 + (n + 1)]− 1

= (n + 1)!(n + 2)− 1

= (n + 2)!− 1

Example 3.4. n! ≥ 2n ∀ n ≥ 4.

Proof. Base case: n = 4: 24 > 16 X

Inductive step: Assume n! > 2n

(n + 1)! = (n!)(n + 1) > (n!)(2)

= (n!)(n + 1) > (2n(2)) = 2n+1

Example 3.5. Prove 5 | 8n − 3n for alln ≥ 0.

Proof. Base case: n = 0: 5 | 80 − 30X

Inductive Step: Assume 5 | 8n − 3n

8n+1 − 3n+1 = 8(8n)− 3(3n)

= (5 + 3)(8n)− 3(3n)

= 5(8n) + 3(8n − 3n)

5 | 5(8n) ∧ 5 | 3(8n − 3n)

⇒ 5 | 8n+1−3n+1

Page 24: MATH 240: Discrete Structures - GitHub Pages

24 anna brandenberger, binyuan sun

Example 3.6. Call a rotation of a "tromino". Take a (2n × 2n)

checkerboard (n ≥ 1) and delete any tile (square). Prove you can tileit with trominos.

Proof.

Base Case: n = 1:With a square removed from a (2× 2) board, the remaining part isexactly one tromino piece. X

Figure 6: Base case.

Inductive Step: Assume true for n, show true for n + 1:

2n+1

2n

2n

Figure 7: Inductive step.

Consider a (2n+1 × 2n+1) board. Place a tromino in the middle(one block covered - i.e. removed - in 3 of the 4 quadrants). Re-move one block from the fourth quadrant. Now each of the 42n × 2n boards can be tiled (by Inductive Hypothesis).

Example 3.7. Prove that a set with n elements has 2n subsets.

Proof. Base case: n = 0: ∅ has 1 subset, 1 = 20. X

Inductive Step: Assume true for n. Let A be a set with n+ 1 elements(write |A| = n + 1). Let x ∈ A, B = A \ {x}. B has 2n subset by IH.For each X ⊆ B, X and ∪{x} are distinct subsets of A.⇒ 2n + 2n = 2(2n) = 2n+1 subsets.

Common Mistakes

1. Finding incorrect patterns.claim: n2 + n + 41 is prime for all n ≤ 0. The proof works untiln = 39 but at n = 40, 402 + 40 + 41 = 412

2. Forgetting the base case.claim: n(n + 1) is odd for all n ≥ 1.Assume true for n.(n + 1)(n + 2) = n(n + 1)︸ ︷︷ ︸

odd

+ 2(n + 1)︸ ︷︷ ︸even

∴ odd

but this is false: We forgot the base case: n = 1 ⇒ (1)(2) =

2 ���ODD

3. Making an unstated (wrong) assumption.claim: All cows are the same colour.Let Cn denote a set of n cows.

Base case: n = 1: Any set of 1 cow has uniform colour.

Page 25: MATH 240: Discrete Structures - GitHub Pages

math 240: discrete structures 25

Inductive Step: Assume true for any Cn. Look at {c1, c2, . . . , cn+1}.By IH, {c1, c2, . . . , cn} all have same colour. By IH, {c1, c2, . . . , cn+1}all have same colour.

problem: S(1) 6⇒ S(2) because {c1} ∩ {c2} = ∅ (the two setsshare no common cow when n = 2).We have base case n = 1 but the statement is false when n = 2.

Definition 3.2. Strong Induction is a variation of induction in whichwe assume that the statement holds for all values preceding n, i.e.one proves:

1. S(1) true

2. (S(1) ∧ S(2) ∧ · · · ∧ S(n))⇒ S(n + 1)

Example 3.8. Prove that any square can be partitioned into n ≥ 6non-empty squares.

Proof.

Base case: n = 6 n = 7 n = 8

Inductive Step: Assume true for all integers k, 6 ≤ k ≤ n (n ≥ 8).Show true for n + 1. By I.H., true for n− 2. Take one square andquarter it, giving (n− 2)− 1 + 4) = n + 1.

Example 3.9. Prove that for any n ≥ 18,∃x, y,∈N∪ {0} s.t.

n = 4x + 7y

Proof. Base case: n = 18, 19, 20, 21

18 = 4(1) + 7(2)

19 = 4(3) + 7(1)

20 = 4(5) + 7(0)

21 = 4(0) + 7(3)

I.H. Assume true ∀ 18 ≤ k ≤ n,(n ≥ 21)By I.H. ∃x, y,∈ N ∪ {0} s.t. n− 3 =4 + 7y⇒ n + 1 = 4(x + 1) + 7y.Example 3.10. Prove every n ∈N can be written as

n = a020 + a121 + · · ·+ ak2k

for some k ∈N∪ {0}, where ai ∈ {0, 1}∀i. i.e. every n can be written in binary.

Proof. Base case: n = 1⇒ 1 = (1)20 X

Inductive Step: Assume true for all 1 ≤ k ≤ n− 1, prove true for n:

1. If n is odd, n− 1 is even. Thus n− 1 = (0)20 + a121 + · · ·+ ak2k

for some k (by I.H.)⇒ n = 1(2)0 + a121 + · · ·+ ak2k.

2. If n is even, look at n2 . n

2 = a020 + · · ·+ ak2k by (I.H.)⇒ n = a021 + · · ·+ ak2k+1.

Page 26: MATH 240: Discrete Structures - GitHub Pages

26 anna brandenberger, binyuan sun

3.2 Recursion

Definition 3.3. A sequence {a1, a2, . . . } is a recurrence relation if an

is a function of {a1, a2, . . . , an−1}.

notation: The first term can be for any k ≥ 0. A finite number ofinitial values must be given.

Example 3.11. Let a0 = 1, an = nan−1, n ≥ 1. Prove an = n!

a0 = 1

a1 = (1)a2 = 1

a2 = (2)a1 = 2(1)

a3 = (3)a2 = (3)(2)(1)Proof. Base case: n = 0 X

Inductive Step: Assume an = n!

⇒ an+1 = (n + 1)an = (n + 1)n! = (n + 1)!

Example 3.12. Let a1 = 1, an =√

6 + an−1, n ≥ 2. Prove an < 3.

Proof. Base case : n = 1⇒ a1 = 1 < 3.

Inductive Step: Assume true for n (an < 3) X.

an+1 =√

6 + an

<√

6 + 3 = 3

Example 3.13. Prove an = (n + 1)2n

where

a0 = 1a1 = 4an = 4an−1 − 4a−2, n ≥ 2

Proof. Base cases: n = 0, 1.

n = 0: (1) = (0 + 1)20

n = 1: (4) = (1 + 1)21

Inductive Step: Assume true for allk, 1 ≤ k ≤ n.

an+1 = 4an − 4nn−1

= 4(n + 1)2n − 4(n)2n−1

= 4 · 2n−1[2(n + 1)− n]

= 2n+1(n + 2)

Definition 3.4. Fibonacci numbers.

f1 = 1, f2 = 1, fn = fn−1 + fn−2, (n ≥ 3)

Example 3.14. How many subsets of {1, 2, 3, . . . , n} contain no con-secutive integers? Let S denote the number of such subsets from

n = 1: {1}, 2 : ∅, {1}n = 2: {1, 2}, 3 : ∅, {1}, {2}n = 3: {1, 2, 3}, 5 : ∅, {1}, {2}, {1, 3}

{1, . . . , n}.

Sn = (# with n) + (# without n) = Sn−2 + Sn−1

Sn−2 because because if n is in the set, n− 1 is not and we are count-ing subsets from {1, . . . , n− 2}; and Sn−1 because if n is not in, thenwe count subsets from {1, . . . , n− 1}. =⇒ Sn is fn+2.

Some proofs about { fn}∞n=1

Theorem 3.1. f1 + f2 + · · ·+ fn = fn+2 − 1

Proof. Base case: n = 1⇒ f1 = f3 − 1 = 2− 1 X

Inductive Step: Assume true for n. Want f1 + f2 + · · ·+ fn + fn+1 =

fn+3 − 1

f1 + f2 + · · ·+ fn + fn+1 = fn+2 − 1 + fn+1

= fn+3 − 1

Page 27: MATH 240: Discrete Structures - GitHub Pages

math 240: discrete structures 27

Theorem 3.2.P(n) : fn+1 fn + fn fn−1 = f2n

Q(n) : f 2n + f 2

n−1 = f2n−1

Proof. For now, omit base cases: computation.Assume P(n) and Q(n) true, =⇒ Prove Q(n + 1) true.

f 2n+1 + f 2

n = ( fn + fn−1)2 + f 2

n

= f 2n + 2 fn fn−1 + f 2

n−1 + f 2n

= ( f 2n + f 2

n−1) + fn fn−1 + fn fn−1 + f 2n

= f2n−1 + fn fn−1 + fn( fn−1 + fn)

= f2n−1 + fn fn−1 + fn fn+1

= f2n−1 + f2n = f2n+1

P(n + 1) true?

fn+2 fn+1 + fn+1 fn = ( fn+1 + fn) fn+1 + ( fn + fn−1) fn

= f 2n+1 + fn fn+1 + f 2

n + fn fn−1

= f 2n+1 + f 2

n︸ ︷︷ ︸Q(n+1)

+ fn fn+1 + fn fn−1︸ ︷︷ ︸P(n)

= f2n+1 + f2n

= f2n+2

3.3 Solving Recurrence Relations

Example 3.15. Consider an = an−1 +2an−2, a0 = 2, a1 = 1

a0 = 2 a1 = 1 a2 = 5 a3 = 7 a4 = 17

a5 = 31 a6 = 65 a7 = 127

· · ·an = 2n + (−1)n ?

We could prove this by induction, butwe would rather have a method morerigorous than "guess and check".

Definition 3.5. The characteristic polynomial of an = ran−1 + san−2

is x2 − rx− s. Its roots α, β are the characteristic roots of the relation.

Theorem 3.3. Consider an = ran−1 + san−2 with specified a0, a1. If x2 −rx− s has 2 distinct roots α, β then

an = c1αn + c2βn

where c1 and c2 solve a0 = c1 + c2, a1 = c1α + c2β.

Proof. Show an = c1αn + c2βn solves the relation an = ran−1 + san−2

c1αn + c2βn = r[c1αn−1 + c2βn−1] + s[c1αn−2 + c2βn−2]

c1αn − rc1αn−1 − sc1αn−2 = −c2βn − rc2βn−1 − sβn−2

c1αn−2[α2 − rα− s] = −c2βn−2[β2 − rβ− s]

0 = 0 X

an = c1αn + c2βn

n = 0 : a0 = c1 + c2

n = 1 : a1 = c1α + c2β

Page 28: MATH 240: Discrete Structures - GitHub Pages

28 anna brandenberger, binyuan sun

Example 3.16. (Back to Example 3.15) an = an−1 + 2an−2

⇒ x2 − x− 2 = 0 = (x + 1)(x− 2)⇒ let α = 2, β = −1

an = c12n + c2(−1)n

n = 0 : a0 = c1 + c2 ⇒ 2 = c1 + c2

n = 1 : a1 = 2c1 − c2 ⇒ 1 = 2c1 − c2

⇒ c1 = 1, c2 = 1⇒ an = 2n + (−1)n

Example 3.17. Fibonacci sequencefn = fn−1 + fn−2, f0 = 0, f1 = 1

Characteristic polynomial: x2 − x− 1

x =1±√

1 + 42

=1±

√(5)

2

⇒α =1 +√

52

, β =1−√

52

fn = c1(1 +√

52

)n + c2(1−√

52

)n

⇒c1 =1√5

, c2 = − 1√5

⇒ fn =1√5(

1 +√

52

)n − 1√5(

1−√

52

)n

What about relations of the form an = ran−1 + san−2 + tan−2 ( orhigher "order")? — Look at a characteristic polynomial whose degreeis equal to the order of the recurrence.

Example 3.18. an = 6an−1 − 11an−2 + 6an−3, a0 = 2, a1 = 5, a2 = 15C.P. x3 − 6x2 + 11x− 6 has three roots: α = 1, β = 2, γ = 3⇒ an = cn

1 + c2(2)n + c3(3)n

n = 0 : 2 = c1 + c2 + c3

n = 1 : 5 = c1 + 2c2 + 3c3

n = 2 : 15 = c1 + 4c2 + 9c3

Solve

1 1 1 21 2 3 51 4 9 15

∼1 0 0 1

0 1 0 −10 0 1 2

c1 = 1

c2 = −1

c3 = 2

⇒ an = 1− 2n + 2(3n)

Theorem 3.4. The recurrence relation an = ran−1 + san−2 + f (n) has so-lution pn + qn where pn is a particular solution of the recurrence (ignoringinitial conditions) and qn is the general solution to an = ran−1 + san−2,where constants c1, c2 in qn are found from initial conditions.

Note: the method for finding pn is theequivalent of the constant coefficientmethod for finding a particular solutionto a homogeneous second order ODE,i.e. guess a solution.

Example 3.19. an = 2an−1 + 3an−2 + 5n ⇒ guess pn = c5n

c5n = 2c5n−1 + 3c5n−2 + 5n

25c = 10c + 3c + 25

12c = 25⇒ c =2512

⇒ pn =2512

(5n)

an = 2an−1 + 3an−2

x2 − 2x− 3 = 0

(x− 3)(x + 1) = 0

α = 3, β = −1

qn = c13n + c2(−1)n

⇒ pn + qn =2512

(5n) + c13n + c2(−1)n

Page 29: MATH 240: Discrete Structures - GitHub Pages

math 240: discrete structures 29

Solve for c1 and c2:

n = 0 : − 2 =2512

+ c1 + c2

n = 1 : 1 =12512

+ 3c1 − c2

c1 = − 278

c2 = − 1724

an =2512

(5n)− 278(3n)− 17

24(−1)n

Example 3.20. an = 2an−1 + 3an−2 + 5n, a0 = 0, a1 = 1As above, qn = c13n + c2(−1)n

Guess pn = An + B

An + B = 2A(n− 1) + 2B + 3A(n− 2) + 3B + 5n

0 = (−2− 6)A + (−1 + 2 + 3)B + (−n + 2n + 3n)A + 5n

= 4B− 8A + 4An + 5n = (4B− 8A) + (4A + 5)n

4A + 5 = 0⇒ A = −54

4B− 8A = 0⇒ B = −52

pn = −54

n− 52

an = −54

n− 52+ c13n + c2(−1)n

n = 0 : 0 = −52+ c1 + c2

n = 1 : 1 = −52− 5

4+ 3c − c2

c1 = 2916

c2 = 1116

⇒ an = −54

n− 52+

2916

3n +1116

(−1)n

3.4 Functions

A function f from X to Y, written f : X → Y is a binary relationf ⊂ X × Y such that for every x ∈ X, there is at most one y ∈ Y suchthat (x, y) ∈ f . Since y is unique for x we can write y = f (x).

Definition 3.6. A surjection is a relation where ∀y ∈ Y ∃x ∈ X s.t.y = f (x). ( f is "onto".)

Figure 8: Surjective (non injective) map.

Figure 9: Injective (non surjective) map.Definition 3.7. A injection is a relation where ∀y ∈ Y ∃ at most onex ∈ X s.t. y = f (x). ( f is "one to one".)

Definition 3.8. A bijection is a relation where ∀y ∈ Y ∃!x ∈ X s.t. y =

f (x). ( f is both surjective and injective.)

Figure 10: Bijective map.

Page 30: MATH 240: Discrete Structures - GitHub Pages

30 anna brandenberger, binyuan sun

Relation to counting: Recall |x| denotes the cardinality of X (thenumber of elements)

1. ∃ a surjection, f : X → Y ⇔ |X| ≥ |Y|

2. ∃ an injection, f : X → Y using every element of X ⇔ |X| ≤ |Y|

3. ∃ a bijection, f : X → Y ⇔ |X| = |Y|

3.5 CountingCounting objects/structures.

Principles of counting:

1. |A1 ∪ A2 ∪ · · · ∪ An| =n∑

i=1|Ai|

if each pair (Ai, Aj) is disjoint (Ai ∩ Aj = ∅)

2. |A1 × A2 × · · · × An| =n∏i=1|Ai|

Translated Princips of Counting:Ai : ways in which a task can be done.

1. The number of ways which a collec-tion of tasks can be done if no twosets of ways of completing the tasksoverlap is the sum of ways of thenumbers of ways each task can bedone.

2. The number of ways a sequence oftasks can be done is the product ofthe number of ways each task can bedone.

Example 3.21. How many 4 digits number have no repeated digits?

Answer. The tasks are to choose each digit: 9× 9× 8× 7 = 4536.Since the first digit can’t be 0.

Example 3.22. How many 4 digit even numbers have no repeateddigits?

Answer. We split into 2 cases:

1. Last digit is 0: 9× 8× 7× 1 = 504

2. Last digit is not 0: 8× 8× 7× 4 = 1792

Total: 2296.

Some Questions:

1. How many functions are there from an n-set to a k-set? ("m-set" =set with m elements)Sequence of events: let |X| = n, |Y| = k. For each x ∈ X, choosey ∈ Y such that y = f (x).Number of functions: k× k× · · · × k︸ ︷︷ ︸

n times

= kn.

2. How many subsets of an n-set are there?Sequence of events: take each element and decide to put it in thesubset or not: n tasks with 2 possibilities each.Number of subsets: 2× 2× · · · × 2︸ ︷︷ ︸

n times

= 2n.

Page 31: MATH 240: Discrete Structures - GitHub Pages

math 240: discrete structures 31

3. How many bijections are there from an n-set to itself?1st element has n possible functions values. 2nd element has n− 1(since it’s a bijection). Etc.Number of bijections: (n)(n− 1)(n− 1) . . . (2)(1) = n!

Definition 3.9. A permutation of an n-set is an ordering of its ele-ments. This is precisely the same as a bijection, so there are n! per-mutations of an n-set.

X = {1, 2, 3, 4}BIJ: {(1, 4), (2, 1), (3, 2), (4, 3)}PERM: 4123

Example 3.23. How many ways can you choose a president, vicepresident, treasurer, secretary from a group of 7 people?

P(7, 4) = 7!3! = 840

Definition 3.10. A k-permutation of an n-set X is a choice of k ele-ments of X in some order. There are P(n, k) such k-permutations:

4. P(n, k) = (n)(n− 1) · · · (n− k + 1) = n!(n−k)!

5. How many subset of size k does an n-set have?Count the number of k-permutations again = (# of k-subsets)(k!)P(n, k) = n!

(n−k)! = (# of k-subsets)(k!)

⇒ number of k-subsets = n!k!(n−k)!

Definition 3.11. C(n, k) = (nk) =

n!k!(n−k)! pronounced "n choose k"

Proposition 3.5. (nk) = ( n

n−k)

Proof. 1. ( nn−k) =

n!(n−k)!(n−(n−k))! =

n!(n−k)!k! = (n

k)

2. Choosing k elements to be in your set is equivalent to choosing then− k elements in its complement.

3.6 The Binomial Theorem

Theorem 3.6. The Binomial Theorem says that if n ≥ 1 is an integer,

(x + y)n =n

∑k=0

(nk

)xkyn−k

where (nk) are called binomial coefficients.

Proof. For a positive integer n, what is the coefficient of xkyn−k in(x + y)n? (x + y)(x + y) · · · (x + y)

How many ways can we choose k x’s from the n factors and n− ky’s, choosing one variable from each factor? We only need to countthe number of ways to choose x’s (get y’s for free). Thus the coeffi-cient of xkyn−k is (n

k).

Page 32: MATH 240: Discrete Structures - GitHub Pages

32 anna brandenberger, binyuan sun

Lemma 3.7.n∑

k=0(n

k) = 2n.

Proof. Two methods:

Binomial Theorem: Let x = y = 1:

(x + y)n = 2n =n

∑k=0

(nk

)(1)(1)

Combinatorially:

2n =

(n0

)+

(n1

)+ · · ·+

(n

n− 1

)+

(nn

)where 2n is the number of subsets of an n-set, and (n

i ) is the num-ber of subsets with cardinality i.

Lemma 3.8. An n-set, n ≥ 1, has the same number of even subsets as oddsubsets.

Proof. Combinatorially: Fix some element x.

# odd subsets with x = # even without x

# odd subsets without x = # even with x

# odd = # even

Binomial Theorem: Pick x = −1, y = 1.

(−1 + 1)n =n

∑k=0

(−1)k(1)n−k

0 =

(n0

)−(

n1

)+

(n2

)−(

n3

)+

(n4

)+ . . .(

n1

)+

(n3

)+ . . . =

(n0

)+

(n2

)+

(n4

)+ . . .

Lemma 3.9. (nk) = (n−1

k ) + (n−1k−1)

Proof. (nk) is the number of subsets of size k. Define some k. (n−1

k ) isthe number of such subsets without x, and (n−1

k−1) is the number ofsuch subsets including x.

Lemma 3.10.n∑

k=0(n

k)2 = (2n

n )

Page 33: MATH 240: Discrete Structures - GitHub Pages

math 240: discrete structures 33

Proof. Rewrite what we want to prove:(2nn

)=

(n0

)(n0

)+

(n1

)(n1

)+

(n2

)(n2

)+ · · ·

=

(2nn

)=

(n0

)(nn

)+

(n1

)(n

n− 1

)+ · · ·+

(nk

)(n

n− k

)+ · · ·

{1, . . . , 2n} = {1, . . . , n} ∪ {1, . . . , n}

(2nn ): number of n-subsets

(nk)(

nn−k): number of ways to choose k elements from {1, . . . , n} and

the rest from {n + 1, . . . , 2n}.

Repetitions

1. If order matters:

Proposition 3.11. Let a1, a2, · · · , an be a set of elements that can be decom-posed into K subsets of elements that are repeated ik times (1 ≤ k ≤ K), i.e.each subset has size ik, ∑ ik = n. The number of permutations is n!

∏Kk=1 ik !

.

Example 3.24. How many anagrams of EASY are there? 4!What about CHEESE? Not 6! since we have repetition.If we take C1H1E1E2S1E3 we get 6! = (# of anagrams of CHEESE)(3!),

⇒ # of anagrams of CHEESE = 6!3!

For MISSISSIPPI, # of anagrams = 11!(1!)(4!)(4!)(2!)

2. If order doesn’t matter:

Proposition 3.12. "Balls & Boxes": The number of ways one can distributek identical balls between n boxes corresponds to a binary string of lengthn + k− 1 with n− 1 1’s & k 0’s, i.e. (n+k−1

n−1 ) = (n+k−1k ).

Visualize "Balls & Boxes" as choosingthe positions for the n− 1 separationsbetween boxes, between n − 1 + kpossible positions (positions includeelements and separation lines).

Example 3.25. Jim’s Morton’s offers 30 kinds of Jimbits. How manyways can you choose a dozen?

Answer. (30+12−129 )

Example 3.26. A sandwich shop offers3 kinds of bread, 4 kinds of meat and 10

kinds of toppings.

(a) How many possibilities are there ifeach sandwich has 1 bread, 1 meatand 3 toppings ?

Answer. Number of possiblesandwiches: (3

1)× (41)× (10

3 ) = 1440

How many platters?

Answer. 1440 boxes, 20 balls.(1440+20−1

20 ) ≈ 6.89× 1044

(b) What if you may now use atmost 1 bread, 2 meats and any oftoppings?

Answer. Number of possiblesandwiches: (3

1)× [(40) + (4

1) + (42)]×

210 = 33972Number of platters: (33782+20−1

20 ) ≈1.55× 1072

Example 3.27. How many non-negative integers solutions are thereto the equation: x1 + x2 + x3 = 48 ?

Answer. 48 balls, 3 boxes: (48+3−13 ) = 1225

What if we impose x1 ≥ 2 and x3 ≥ 5?

Answer. Let y1 = x1 − 2, y2 = x2, y3 = x3 − 5(41+3−1

2 ) = 903

Page 34: MATH 240: Discrete Structures - GitHub Pages

34 anna brandenberger, binyuan sun

Example 3.28. How many (non-negative) solutions are there to theequation: x1x2x3 = 48 ?

Answer. Notice 48 = 2× 2× 2× 2× 3. So we distribute four 2’s tothree boxes, and distribute one 3 to three boxes. (4+3−1

2 )× 3 = 45.

Counting Elements in Sets

i.e. How to count the amount of elements in sets |A1 ∪ A2 ∪ · · · ∪ An|if these sets are not disjoint?

n = 2: |A1 ∪ A2| = |A1|+ |A2| − |A1 ∩ A2|

n = 3: |A1 ∪ A2 ∪ A3| = |A1|+ |A2|+ |A3| − |A1 ∩ A2| − |A2 ∩ A3|− |A1 ∩ A3|+ |A1 ∩ A2 ∩ A3|

Example 3.29. 40 students: where 10 inANTH, 22 in BIOL, 16 in COMP; 6 inA&B, 8 in B&C, 4 in A&C; and 2 in all.How many students are not enrolled inany of the 3 courses?

i.e. first find how many in at least one:

|A1 ∪ A2 ∪ A3| = |A1|+ |A2|+ |A3| −|A1 ∩ A2| − |A2 ∩ A3| − |A1 ∩ A3| +|A1 ∩ A2 ∩ A3| = (10 + 22 + 16)− (6 +8 + 4) + 2 = 32

∴ There are 40− 32 = 8 students innone of the courses.Theorem 3.13. Principle of Inclusion-Exclusion (PIE).

If A1, A2, . . . , An are finite sets, then:

|A1 ∪ A2 ∪ · · · ∪ An| = ∑S⊆[n]S 6=∅

(−1)|S|−1|⋂i∈S

Ai|Here [n] represents [1, . . . , n].

Proof. Must show every x ∈ A1 ∪ · · · ∪ An is counted exactly once onthe RHS. Say x appears in k of the sets A1 ∪ · · · ∪ An. x is counted incollections of 1 set k times, of 2 sets (k

2) times, of 3 sets (k3) times, ...

So x counted (k1)− (k

2) + (k3)− (k

4) + · · ·+ (−1)k−1(kk) times in total.

Recall (n0

)−(

n1

)+

(n2

)−(

n3

)+

(n4

)+ · · · = 0

Therefore we take(k1

)−(

k2

)+

(k3

)−(

k4

)+ · · ·+ (−1)k−1

(kk

)= 1

so each x is counted once.

Example 3.30. n people put their phones in a box. If every persontakes a phone out, how likely is it that no one gets their phone back?The number of permutations of [n] (or bijections from [n] → [n])where no element is mapped to itself is denoted Dn, they are calledderangements.

Let Ai = Set of permuttions which map i to itself.

Dn = |A1 ∩ A2 ∩ · · · ∩ An|= |A1 ∪ A2 ∪ · · · ∪ An|= n!− A1 ∪ A2 ∪ · · · ∪ An

Page 35: MATH 240: Discrete Structures - GitHub Pages

math 240: discrete structures 35

However,

|S| = A1 ∪ A2 ∪ · · · ∪ An

= (|A1|+ |A2|+ . . . )− (|A1 ∩ A2|+ |A1 ∩ A3|+ . . . ) + . . .

= n · (n− 1)!−(

n2

)(n− 2)! +

(n3

)(n− 3)! + · · ·+ (−1)n−1

(nn

)(n− n)!

= n!− n!2!

+n!3!

+ · · ·+ (−1)n−1 n!n!

= n!(

1− 12!

+13!

+ · · ·+ (−1)n−1

n!

)Dn = n!− n!

(1− 1

2!+

13!

+ · · ·+ (−1)n−1

n!

)= n!

(1− 1 +

12!− 1

3!+ · · ·+ (−1)n

n!

)= n!

(10!− 1

1!+

12!− 1

3!+ · · ·+ (−1)n

n!

)= n!

n

∑k=0

(−1)k

k!

So calculating the probability: Recall ex =∞∑

k=0

xk

k! x ∈ R

P(a permutation is a derangement) =Dn

# permutations=

Dn

n!

=n

∑k=0

(−1)k

k!= e−1

So, as n→ ∞, P ≈ e−1 ≈ 0.36788, and Dn ≈ n!e .

Theorem 3.14. Pigeon Hole Principle (PHP). If one distributes > n ob-jects to n boxes, some box has more than one object.

Example 3.31. 22 soccer players on a field measuring 42m × 98m.Show there are two players no more than 20m apart.

Answer. Cut the field into 21 boxes of size 14× 14 m. There are 21

boxes and 22 players, therefore 2 players must be in the same squareby PHP. d ≤

√142 + 142 =

√196 + 196 <

√400 =

√400 = 20.

Example 3.32. Let S be a set of 9 points in R3 each with integercoordinates. Show ∃pi, pi ∈ S such that the midpoint of p1 p2 hasinteger coordinates.

Answer. Let pi = (xi, yi, zi), pj = (xj, yj, zj).

Wantxi+xj

2 ,yi+yj

2 ,zi+zj

2 ∈ Z⇔ xi + xj, yi + yj, zi + zj even.The possible parity combinations are shown in Table 6.

x y zE E EE E OE O EO E EE O OO E OO O EO O O

Table 6: Table for Example 3.32

Page 36: MATH 240: Discrete Structures - GitHub Pages

36 anna brandenberger, binyuan sun

8 parity combinations, 9 points⇒ 2 have same parity, i.e.

xi ≡ xj mod 2 yi ≡ yj mod 2 zi ≡ zj mod 2

Therefore xi + xj, yi + yj, zi + zj are all even.

Example 3.33. Show that if n + 1 numbers are chosen from [2n], thenthere are

(a) 2 which differ by 1:

Answer. Boxes: {1, 2}, {3, 4}, {5, 6}, . . . , {2n− 1, 2n}n boxes, n + 1 choices, therefore 2 integers in same box by PHPwhich differ by 1.

(b) 2 which sum to 2n + 1:

Answer. Boxes: {1, 2n}, {2, 2n− 1}, {3, 2n− 2}, . . .Each pair sums to 2n + 1. 2 of the n + 1 choices lie in one box byPHP.

Proposition 3.15. Strong version of PHP: If one has m > n, m objects, nboxes, then some box receives ≥ dm

n e objects.

Example 3.34. 16 students, in 18 chairs. Show there are 6 consecutiveoccupied seats.

Answer. Split into 3 blocks of 6 chairs. Distribute 16 people across 3

boxes therefore the same box must gets ≥ d 163 e = 6 people.

Example 3.35. A student has 37 days to prepare for an exam. If shestudies no more than 60 hours, but at least 1 hour each day, showthere is some set of consecutive days over which she studied exactly13 hours (whole hours each day).

Answer. Let si = number of hours studied n day i. Let ai = s1 + s2 +

· · ·+ si (number of hours studied from day 1 to day i).

1 ≤ a1 < a2 < · · · < a37 ≤ 60

14 ≤ a1 + 13 < a2 + 13 < · · · < a37 + 13 ≤ 73

Consider the list a1, a2, . . . , a37, a1 + 13, a2 + 13, . . . , a37 + 13. There are74 integers between 1 and 73 therefore 2 must be the same. ⇒ i, j s.t.ai = aj + 13⇔ ai − aj = 13⇔ sj+1 + sj+2 + · · ·+ si = 13

Page 37: MATH 240: Discrete Structures - GitHub Pages

math 240: discrete structures 37

4 Graph Theory

Figure 11: Bridges of Königsberg: canyou start anywhere in the city, crossevery bridge exactly once and finishwhere you started?

4.1 Introduction

Definition 4.1. A graph G is a pair (V, E) where V is a set (whoseelements are the vertices of the graph) and E is a set of unorderedpairs of elements of V (called the edges of G).

We often write V(G) and E(G) for the vertices/edges if G = (V, E).Also, for brevity, we write uv ∈ E(G) for the edge {u, v}.

Example 4.1. V = {v1, v2, v3, v4}E = {v1v2, v1v3, v1v4, v2v3, v2v4, v3v4} v3 v2

v4

v1

v4 v3

v1 v2

Figure 12: These two figures representidentical graphs (the one in Exer-cise 4.1).Graphs are often represented pictoriallywhere V(G) is a set of points or dots,and each edge is a segment or curvebetween points; but a drawing of agraph is not the graph itself.

Uses of Graphs:

1. Routing problems: V = locations, E = direct passage betweenlocations.

2. Social networks: V = users, E = friends.

3. Scheduling: V = events, E = pairs of events which cannot coin-cide.

Definition 4.2. Given v ∈ V(G) and e ∈ E(G), if v ∈ e, then we saythat e is incident to v. If uv ∈ E(G), we say that u and v are adjacent(neighbours).

Definition 4.3. The neighbourhood of v ∈ V(G) is:N(v) = {u | uv ∈ E(G)}

Definition 4.4. The degree of v ∈ V(G) in G is d(v) = |N(v)|. Wecan also write this as deg(v), or NG(v), dG(v) which make it clear towhich graph one is referring. In general, 0 ≤ degG(v) ≤ |V(G)| − 1

Definition 4.5. The degree sequence of G is a list of the degrees (inincreasing order).

Theorem 4.1. If G is a graph, then ∃u, v ∈ V(G) s.t. d(u) = d(v).

Proof. Case 1: Suppose deg(u) 6= 0 ∀u ∈ V(G). Let |V(G)| = n.Then 1 ≤ deg(n) ≤ n− 1. There are n vertices and n− 1 possibledegrees. By PHP, two vertices have the same degree.

Case 2: ∃u s.t. deg(n) = 0. Then 0 ≤ deg(n) ≤ n− 2. n− 1 possibledegrees & n vertices, so 2 must have the same degree by PHP.

Page 38: MATH 240: Discrete Structures - GitHub Pages

38 anna brandenberger, binyuan sun

Lemma 4.2 (Handshaking Lemma). In any graph G, there is an evennumber of vertices with odd degree.

Theorem 4.3. If G is a graph, then ∑v∈V(G) deg(v) = 2|E(G)|

Proof. Count the number of pairs (v, e) such that e is incident to v.Each vertex v appears deg(v) times in the set of pairs. Each edgeappears exactly twice.

∑v∈V(G)

deg(v) = ∑e∈E(G)

2 = 2|E(G)|

Proof. of Handshaking Lemma (Lemma 4.2).

∑v∈V(G)

deg(v) odd

deg(v) + ∑v∈V(G)

deg(v) even

deg(v)

︸ ︷︷ ︸even

= 2|E(G)|︸ ︷︷ ︸even

Figure 13: Complete Graphs.

Special graphs:

• empty graph: E(G) = ∅

• complete graph: E(G) = all possible pairs:

– denoted Kn if |V(G)| = n

– |E(Kn)| = (n2) [in general, 0 ≤ |E(G)| ≤ (n

2)]

• complete bipartite graph Km,n where :

– V(Km,n) = {u1, . . . , um, v1, . . . , vn}

– E(Km,n) = {uivj|1 ≤ i ≤ m, 1 ≤ j ≤ n}

=⇒ |V(Km,n)| = m + n

=⇒ |E(Km,n)| = m · n

• Path Pn: V(Pn) = {v1, . . . , vn}, E(Pn) = {v1v2, v2v3, . . . , vn−1vn}⇒ |E(Pn)| = n− 1

• Cycle Cn: V(Cn) = {v1, . . . , vn}E(Cn) = {v1v2, v2v3, . . . , vn−1vn, vnv1}⇒ |E(Cn)| = n

Figure 14: K2,3. Figure 15: K3,3.

Figure 16: The red part is a subgraph ofthe entire graph.

Definition 4.6. We say H is a subgraph of G if V(H) ⊆ V(G) andE(H) ⊆ E(G). Equivalent: obtain H from G by deleting edges and/orvertices. Note that when we delete v ∈ V(G), we delete all incidentedges as well. If V(H) = V(G) we say that H is a spanning sub-graph.

Page 39: MATH 240: Discrete Structures - GitHub Pages

math 240: discrete structures 39

Definition 4.7. A walk in G is a sequence of vertices v0, v1, v2, . . . , vk

where vi−1vi ∈ E(G) ∀1 ≤ i ≤ k.A path in a graph is a walk with no repeated vertices. A closed

walk is a walk where v0 = vk: v0 and vk are the ends of a walk.A closed path is a cycle.

Definition 4.8. A graph is connected if ∀u, v ∈ V(G) there is a walkwith ends u and v. The maximal connected subgraphs of G are calledits connected components.

Figure 17: Connected components.Note that a single vertex is a connectedcomponent.

Definition 4.9. A multigraph M is a set (of vertices) V(M) and alist of unordered pairs of vertices where repetition is allowed (i.e.vv ∈ E(M)).

Definition 4.10. An Eulerian walk in a graph (or multigraph M) is aclosed walk which uses every edge exactly once. If G has an Eulerianwalk, we call G Eulerian.

Figure 18: We can recall the Königsbergproblem: V are land masses and E arebridges.

Theorem 4.4 (Euler, 1736). G is Eulerian if and only if it is connected andall vertices have even degree.

Proof.(⇒) ∀ v ∈ V(G), the number of times an Eulerian walk enters v

equals the number of times it exits v. =⇒ deg(v) = k + k = 2k forsome k.

(⇐) Suppose G is connected and deg(v) even ∀ v ∈ V(G). Let Wbe a longest walk in G with no repeated edges W = v0, v1, . . . , vk.

Suppose W is not Eulerian.

Claim: W is closed.

Proof. Suppose it is not.⇒ we used odd number of edges incident to vk

⇒ ∃ an unused edge incident vk

⇒ we can extend W by 1. ⇒⇐ with maximality of W.

So there is some edge in E(G) not used by W. Because G is con-nected, there must be an edge uvi not used by W for some 0 ≤ i ≤ k.This contradicts maximality of W: u, vi, vi+1, . . . , vk = v0, v1, . . . , vi islonger. ⇒⇐. So G is Eulerian.

This result (Theorem 4.4) holds formultigraphs as well. Note that deg(v)counts a "loop" (edge between the samenode) w ∈ E(M) twice.

Definition 4.11. A path in G is Hamiltonian if it has |V(G)| ver-tices (it "spans" G). A Hamiltonian cycle is a cycle in G with |V(G)|vertices. A graph is Hamiltonian if it has a Hamiltonian cycle.

Page 40: MATH 240: Discrete Structures - GitHub Pages

40 anna brandenberger, binyuan sun

Finding Hamiltonian cycles, as a rule, is difficult (unless P = NP :’).Are there sufficient conditions for G to be Hamiltonian?

Theorem 4.5 (Bondy & Chvátal, 1972). If deg(u) + deg(v) ≥ |V(G)|∀ u, v ∈ V(G), then G is Hamiltonian⇔ G + uv is Hamiltonian whereuv 6∈ E(G).

Proof. Show G is Hamiltonian⇔ G + uv is Hamiltonian whereuv 6∈ E(G).

(⇒) Trivial.(⇐) If G is Hamiltonian, then done. Now suppose G is not Hamil-

tonian. ⇒ ∃ a Hamiltonian path from u to v in G, say P (Figure 19).u v1

· · ·v

Figure 19: Hamiltonian path P.Let S be the neighbors of u which lie on P. Let T be the vertices

which follow neighbors of v on P. |S|+ |T| ≥ |V(G)|By PHP, there must be some vertex in S ∩ T, say vi.

u· · · · · ·

vi v=⇒ vi, vi+1, · · · , v, vi−1, vi−2, · · · , v1, u, vi is a Hamiltonian cycle

of G.

Theorem 4.6 (Ore, 1960). If d(u) + d(u) ≥ |V(G)| ∀u, v ∈ V(G)

nonadjacent, then G is Hamiltonian. This leads straightforwardly to (Dirac,1952): If degG(v) ≥ |V(G)|

2 then G is Hamiltonian.

Proof. By adding edges to the graph and applying Theorem 4.5 re-peatedly, we get a complete graph, which is Hamiltonian. By the "iff"statements, G is Hamiltonian as well.

4.2 Trees

Figure 20:Binary tree.(Any k-ary K1,tis also a tree.)

Figure 21: Anypath Pn is atree.

Figure 22: A general tree.

Definition 4.12. A graph is a tree if it is connected and has no cycles.A leaf of a graph is a vertex of degree 1.

Theorem 4.7. If deg(v) ≥ 2 ∀ v ∈ V(G), then G contains a cycle.

Proof. Let P be a maximal path in G: P = v0, v1, v2, . . . , vk, vSince it has deg(v) ≥ 2, it has some neighbor other than vk.

By the maximality of P, this neighbor must be in P, say vi. Thusvivi+1 . . . vkvvi is a cycle.

Corollary 4.8. Every tree has a leaf.

Proof. Contrapositive proof. Left to the reader.

Theorem 4.9. A connected graph is a tree if and only if there is a uniquepath between any 2 vertices.

Page 41: MATH 240: Discrete Structures - GitHub Pages

math 240: discrete structures 41

Proof. (⇒) Since it is connected, there is at least one path betweenany two vertices. To prove uniqueness, suppose P1 and P2 are dis-tinct uv-paths. Let vi be the last vertex P1 and P2 have in commonaside from v. Let vj be the next vertex in P1 shared with P2. Thesubpaths of P1 and P2 from vi to vj together thus form a cycle.⇒⇐

(⇐) Let G be a connected graph that is not a tree. The G has a cycle,C. If u, v ∈ V(C), then there are ≥ 2 uv-paths.

Theorem 4.10. Every tree on ≥ 2 vertices has at least 2 leaves.

Proof. by induction, on the number of vertices.

Base: n = 2: the tree on two nodes has 2 leaves.

I.H.: Assume true for n− 1 vertices. Let T be an arbitrary tree with nvertices. Let x be a leaf of Ti, let T′ = T − x. T′ has n− 1 vertices,and is a tree because we are removing one node from T, a tree.If u, v ∈ V(T′), then there exists a unique path in T′ between them(the unique path in T could not contain x since deg(x) = 1).Then T′ has ≥ 2 leaves, say y, z. Since deg(x) = 1, x is adjacent toat most one of y and z.Then x and at least one of y, z are leaves in T.

Theorem 4.11. A connected graph is a tree⇔ the deletion of any edge dis-connects the graph.

Proof. c.f. textbook (LPV).

Theorem 4.12. An n-vertex tree has n− 1 edges.

Proof. Base: n = 1: one node, zero edges.

I.H.: Assume true for n − 1 vertices. Let T be an n-vertex tree, andlet x be a leaf. By the I.H., T − x has n− 2 edges (because it is an(n− 1)-vertex tree). Then T must have n− 1 edges.

Theorem 4.13. Adding an edge to a tree creates exactly one cycle.

Proof. Let u, v be non-adjacent vertices. There exists a uv-path, sayP = uv1 . . . vkv. Thus adding uv creates a cycle. Now we must provethat it creates exactly one. Suppose there are more than one.

Any cycle created must contain the edge uv. (Otherwise there isa cycle in the original tree⇒⇐). But then deleting uv from thesecycles gives distinct uv-paths in the tree, contradicting uniqueness(Theorem 4.9.)

Added clarification: we can let the al-leged two cycles created by addinguv be (u, v, · · · , a, b, · · · , u) and(u, v, · · · , x, y, · · · , u).

Removing uv, we get two pathsfrom v to u: (v, · · · , a, b, · · · , u) and(v, · · · , x, y, · · · , u). ⇒⇐ with pathuniqueness.

Page 42: MATH 240: Discrete Structures - GitHub Pages

42 anna brandenberger, binyuan sun

Definition 4.13. A spanning tree of a graph G is a subgraph T suchthat V(T) = V(G) and T is a tree.

Theorem 4.14. Every connected graph has a spanning tree.

Proof. Base: Trivially true for n = 1.

I.H.: Assume true for |V(G)| = n− 1.

Delete any vertex v from our graph, which does not disconnectit.16 The resulting (n− 1)-vertex graph has a spanning tree. Add 16 Exercise: Prove that any connected

graph has a vertex whose deletion doesnot disconnect the graph.

the edge vx to the tree for any x ∈ N(v). The resulting subgraph:

– uses every vertex

– is connected

– contains no cycles (any cycle would contain v which has degree1 in the subgraph).

Counting Trees

Theorem 4.15 (Cayley). ∃ nn−2 different trees on n labelled vertices.

Proof.

- See LPV for proof using bijection between trees and "Prufer codes".

- c.f. Kirchhoff’s Theorem, using linear algebra.

There is no theorem for the number of unlabelled trees on n ver-tices. However, we can find bounds.

Let Tn denote the number of unlabelled n-vertex trees.

nn−2 ≤ n!Tn (1)

nn−2

n!≤ Tn

Tn ≤(

2n− 2n− 1

)(2)

Start at root, draw the tree so that no edges cross and vertices atdistance i from root are at level i. Walk around the edges and recordD if you move down 1 edge and U if you move up one edge. Thusthe code has length 2|E(T)| = 2(n− 1) and has n− 1 U ’s and n− 1D’s, yielding a code that looks like UUDUDDUU . . . .

Thus the number of combinations of codes is (2n−2n−1 ).

Some trees are counted more than once, but each tree is counted atleast once.

=⇒ Tn ≤(

2n− 2n− 1

)

Page 43: MATH 240: Discrete Structures - GitHub Pages

math 240: discrete structures 43

Using Stirling’s Approximation, we can say that for large n,

en√

2πn5/2≤ Tn ≤

4n−1√

2πn− 1

Stirling’s Approximation:

limn→∞

n! =√

2πn( n

e

)n

4.3 Graph Colouring

Cliques and Independent Sets

Definition 4.14. Some more terminology:∆(G) = maximum degree of vertices in Gδ(G) = minimum degree of vertices in GG is d-regular if degG(v) = d ∀ v ∈ V(G)

(G is regular if it is d-regular for some d.)

Definition 4.15. A clique in a graph G is a set X ⊆ V(G) such thatuv ∈ E(G) ∀ u, v ∈ X, u 6= v, i.e. X is a complete subgraph of G.

The clique number of G isW(G) = size of largest clique in G.

Definition 4.16. An independent set (or stable set) is a set X ⊆ V(G)

such that uv 6∈ E(G) ∀u, v ∈ X, i.e. X is an empty subgraph of G.The independence number of G is α(G) = size of largest indepen-

dent set in G.

Definition 4.17. A proper vertex k-colouring is a map c : V(G) → [k]such that if uv ∈ E(G) then c(u) 6= c(v). The chromatic number of Gis X (G) = the smallest k for which a proper vertex k-colouring exists.

Example 4.2.

G δ ∆ W α XPn 1 2 2 d n

2 e 2

Cn 2 2

3 if n = 32 otherw.

b n2 c

2 if n even3 if n odd

Kn n− 1 n− 1 n 1 nKm,n m n 2 n 2

Definition 4.18. A graph is bipartite if V(G) can be partitioned intotwo independent sets.

Proper vertex k-colourings partition V(G) into k independent sets.G is bipartite⇔ X (G) ≤ 2

Theorem 4.16. G is bipartite⇔ G contains no odd cycles.

Page 44: MATH 240: Discrete Structures - GitHub Pages

44 anna brandenberger, binyuan sun

Lemma 4.17. If H is a subgraph of G, then X (H) ≤ X (G).

Proof. If c is a proper k-coloring of G, then ∀u, v ∈ V(H) which areadjacent, c(u) 6= c(v), so c is a proper k-colouring of H.

Lemma 4.18. Every closed odd walk of a graph contains an odd cycle wherelength is defined as the number of edges.

Proof. by strong induction on the length of the walk r.

Base: r = 3The only closed walk of length 3 is a cycle of length 3.

I.H. Assume true for all odd integers less than r = 2t + 1.

Take a close walk of length r: v0, v1, . . . , vr−1, vr = v0

If there are no repeated vertices (other than v0 = vr), then this is anodd cycle.If there are repeated vertices, i.e. ∃i, j such that vi = vj and 0 ≤ i <j < r. Let W1 = v0, v1, . . . , vi, vj+1, . . . , vr and W2 = vi, vi+1, . . . , vj. v1 vi/vj

vr

W1 and W2 together form the original odd closed walk. Since|W1| < |W| and |W2| < |W| and each of the two walks is a closedwalk, the induction hypothesis guarantees that whichever of W1 orW2 has odd length contains an odd cycle. This must be a cycle ofW as well.

Proof. of Theorem 4.16: G is bipartite⇔ G contains no odd cycles.

(⇒) If G has an odd cycle C, then 3 = X (C) ≤ X (G) ⇒ G is notbipartite. ⇒⇐

(⇐) Suppose G has no odd cycles. Let u ∈ V(G). Now define

X = {x ∈ V(G) | u and x have even distance}Y = {y ∈ V(G) | u and y have odd distance}

We must show any two vertices in X (or in Y) are nonadjacent.

"distance" is the length of the shortestpath between vertices.Note: u ∈ X since u is at distance 0

from itself.

Suppose not. Let x, x′ ∈ X and xx′ ∈ E(G). By construction thereis an even length path from u to x say P and from u to x′ say P′.Then P with xx′ with P′ is a closed walk of odd length in G,⇒ Ghas an odd cycle. ⇒⇐Similarly, if y, y′ ∈ Y and yy′ ∈ E(G), then we get a closed oddwalk from the odd uy-path, yy′ and the odd uy-path. ⇒⇐

General coloringsLower bounds on G

Page 45: MATH 240: Discrete Structures - GitHub Pages

math 240: discrete structures 45

Recall that X (G) ≥ X (H) ∀ subgraph H of G. If H is the largestcomplete subgraph, then:

X (G) ≥ W (G)

Since a proper k-colouring partitions V(G) into independent sets,

X (G) ≥ |V(G)|αG

To see this, let Ci = {v ∈ V(G)|c(v) = i} for some proper X (G)-colouring, then:

|V(G)| =X (G)

∑i=1|Ci| ≤

X (G)

∑i=1

α(G) = X (G)α(G)

Upper bounds on X (G)

Greedy Colouring Algorithm (G = (V , E))

1 order V(G) arbitrarily v1 , v2 , . . . , vn

2 colour V(G) in this order assigning c(vi) the smallest colour notyet assigned to its neighbours.

v1

1 v22

v51

v4

2

v3 1

v6 2

v1

1 v43

v32

v2

1

v6 3

v5 2

Figure 23: Left is an optimal coloring,right is non optimal. So the outputdepends on node ordering.

This algorithm doesn’t guarantee the optimal colouring. At anyvertex, the max number of forbidden colours is its degree. So thegreedy algorithm gives: X (G) ≤ ∆(G) + 1.

Theorem 4.19 (Brook, 1941). If G is not complete or an odd cycle, thenX (G) ≤ ∆(G).

Proof. Beyond the scope of this course.

Theorem 4.20. If G is not regular, then X (G) ≤ ∆(G).

Proof. by algorithm:

BFS (Breadth First Search) Algorithm (G = (V, E))

1 Insert any vertex into a first-in-first-out (fifo) queue Q.2 while Q 6= ∅3 Remove the next vertex x from Q and mark it "visited".4 Place any neighbors of x which are not yet marked "visited"

into the queue (and ignore other neighbors).

Output: ordering of V(G) in the order they are marked visited. We can build a "BFS" tree, but we don’tneed it here.

Choose a vertex v1 whose degree is not ∆(G): deg(v1) ≤ ∆(G)− 1.(We can do this since the graph is not regular.)

Now run BFS with v1 as the initial vertex, yielding an ordering ofV(G): v1, v2, . . . , vn−1, vn.

Page 46: MATH 240: Discrete Structures - GitHub Pages

46 anna brandenberger, binyuan sun

Every vi, i ≥ 2 has a neighbour vj with j < i because for vi to getplaced in the queue, we must have already visited some neighbourvj. We then colour the vertices in reverse order vn, . . . , v1.

For 2 ≤ i ≤ n, when we colour vi, at least one of its neighbourshas yet to be coloured (vj from discussion above), which means thatat most deg(vi)− 1 colours have been used on the neighbours of vi

while greedily colouring,⇒ at most ∆(G) − 1 forbidden colours atevery step, since deg(v1) ≤ ∆(G) − 1. ⇒ if we have ∆(G) colours,there will always be an available colour: ∴ X (G) ≤ ∆(G)

4.4 Planar Graphs

Definition 4.19. A graph is planar if it can be drawn in the Euclidianplane so that the edges do not cross (only meet at vertices).

Figure 24: K2,3 and K4 have planarrepresentations. K5 seems like it doesnot.

K5 seems like it cannot be planar since there are vertices that cannotbe joined without crossing other edges. But proofs along these linesrequire the Jordan Curve Theorem which will not be touched in Math240. We will use an alternate proof.

1

2

3 4

5

6

Figure 25: Example of a planar graph.Every drawing has an unbounded facecalled the outer face.

Note: The vertices of any face in adrawing can be made to be the verticesof the outer face.Note: Each edge touches at most 2

faces. If an edge touches exactly oneface, deleting it disconnects the graph.

Proofs are omitted since they use topology.

Definition 4.20. Given a plane drawing G∗ of a planar graph G, wedefine a face to be a maximal region bounded by edges.

Theorem 4.21 (Euler’s Formula).If G∗ is a plane drawing of a connected planar graph G with M vertices,

|E| edges, and |F| faces, then: |V| − |E|+ |F| = 2.

Proof. By induction on |E|.

Base: |F| = 1. If |F| = 1, then G∗ has no cycles⇒ G is a tree⇒ |E| =|V| − 1 and |V| − |E|+ |F| = |V| − (|V| − 1) + 1 = 2

I.H.: Suppose true for |F| = k− 1.Let G∗ have k ≥ 2 faces. Since G is not a tree, it has a cycle C.Let e be an edge of C. Consider G − e. It is still planar. It is alsostill connected any walk that used e can be modified by replacinge with C − e. Thus e touches 2 faces since its deletion doesn’tdisconnect G∗ (or G). Therefore deleting e merges the 2 faces into1. By induction, the new graph with |V′|, |E′|, |F′| satisfies

|V′| − |E′|+ |F′| = 2

⇒ |V| − (|E| − 1) + (|F| − 1) = 2

⇒ |V| − |E|+ |F| = 2

This means that |F| is invariant for a graph G: the number of facesdoes not depend on its drawing.

Page 47: MATH 240: Discrete Structures - GitHub Pages

math 240: discrete structures 47

Theorem 4.22. If G is a connected planar graph, with |V| ≥ 3, then

|E| ≤ 3|V| − 6

Proof. Count the number of pairs (e, f ) where e touches f . Call thisnumber T. Since each edge touches at most 2 faces, T ≤ 2|E|. Butevery face touches at least 3 edges (no self-touching edge or 2 edgeswith 2 vertices).

T ≥ 3|F|3|F| ≤ T ≤ 2|E|

|F| ≤ 23|E|

⇒ 2 = |V| − |E|+ |F| ≤ |V| − |E|+ 23|E|

⇒ 13|E| ≤ |V| − 2

|E| ≤ 3|V| − 6

Example 4.3. Show K5 is non-planar:

|V| = 5

|E| =(

52

)= 10

10 6≤ 3(5)− 6 = 9

Note: K3,3 is also non-planar. But it satisfies the above property.

Figure 26: Edge contraction.

Theorem 4.23 (Kuratowski, 1930). G planar⇔ G has no K5 or K3,3 sub-division.

Definition 4.21. A minor of G is a graph obtained by deleting ver-tices, deleting edges or contracting edges (Figure 26).

Theorem 4.24 (Wagner, 1937). G planar⇔ G has no K5 or K3,3 minor.

Proof. Beyond the scope of this course. ;-;

Theorem 4.25. If G is planar with no triangles⇒ |E(G)| ≤ 2|V(G)| − 4.

Proof. Count pairs (e, f ) where edge e touches face f . Let T be thenumber of such pairs.

4|F| ≤ T ≤ 2|E|

|F| ≤ 12|E|

=⇒ 2 = |V| − |E|+ |F| ≤ |V| − |E|+ 12|E|

=⇒ |E| ≤ 2|V| − 4

Example 4.4. K3,3 is bipartite =⇒ no odd cycles =⇒ no triangles.K3,3 planar =⇒ 9 ≤ 2(6)− 4 = 8.Contradiction, implying K3,3 non-planar.

Page 48: MATH 240: Discrete Structures - GitHub Pages

48 anna brandenberger, binyuan sun

Theorem 4.26. Every planar graph is 4-colourable (X (G) ≤ 4).

Proof. Appel and Haken, 1976. No human readable proof exists.

Theorem 4.27. Every planar graph is 5-colourable.

Lemma 4.28. If G is planar, then δ(G) ≤ 5.

Proof. Suppose δ(G) ≥ 6, so deg(v) ≥ 6 ∀v ∈ V(G).

∑v∈V(G)

deg(v) = 2|E|

⇒ 6|V| ≤ 2|E|⇒ |E| ≥ 3|V| ⇒⇐ since |E| ≤ 3|V| − 6

Proof. of Theorem 4.27, by induction on |V(G)|.

Base: Trivial if |V(G)| ≤ 5.

I.H.: Assume true for |V(G)| = n − 1 and let G be a planar graphwith n vertices. We know ∃v ∈ V(G) with deg(v) ≤ 5 (byLemma 4.28).

Case 1: deg(v) ≤ 4. Delete v and 5-colour V(G− v) by induction.At most 4 colours are used on the neighbours. of v, so there isan available colour for v.

Case 2: deg(5) = 5. Delete v and 5-colour V(G − v) If 4 or fewercolours are used on the neighbours of v then we have a colouravailable for v.If each neighbour of v got a distinct colour:Let N(v) = {x1, x2, x3, x4, x5}. Say c(xi) = i. Let G13 be thesubgraph of G consisting of all vertices coloured 1 or 3 and alledges of G between them.If x1 and x3 are not in the same connected component of G13,then we take the component of G13 containing x1 and "flip" thecolours of its vertices (3 to 1 and 1 to 3: Figure 27). This is still aproper colouring of G− v and now we can colour v with 1.

Figure 27: If x1 and x3 are not in thesame connected component, flip allvertices coloured 1 and 3.

If x1 and x3 are in the same connected component: then there isa path P13 in G13 from x1 to x3 (whose vertices are all coloured1 or 3). P13 ∪ {x1v, x3v} form a closed curve. One of x2 and x4

lies inside and one lies outside. Look at the subgraph of G − vwith vertices coloured 2 and 4. x2 and x4 cannot be in the sameconnected component, or else there is an x2x4-path with verticescoloured 2 and 4 which intersects P13 ∪ {x1v, x3v}. So we takethe component of G24 containing x2 and swap colours 2 and 4.

Figure 28: If x1 and x3 are in the sameconnected component, flip the colour ofx2 (and connected components).

This leaves the colour 2 available for v.

Proof. Alternate: see LPV p. 208-209.

Page 49: MATH 240: Discrete Structures - GitHub Pages

math 240: discrete structures 49

4.5 Weighted Graphs

Definition 4.22. A weighted graph is a graph G and a functionw : E(G)→ R where w(e) is the weight of e.

Notation 4.29. If H is a subgraph of G, we use w(H) = ∑e∈E(H) w(e).

Types of problems we might wish to solve:

1. Find a uv-path P where w(P) is minimum.c.f. Dijkstra’s Algorithm.

2. Find a spanning tree T with w(T) minimum.c.f. Kruskal’s Algorithm and Prim’s Algorithm.

3. Find a spanning closed walk W such that w(W) is minimum.c.f. Traveling Salesman Problem (difficult, but one can find W suchthat w(W) ≤ 3

2 w(Woptimal)).

Dijkstra’s Algorithm(G): find minimum weight uv-path.

1 Assign label (−, 0) to u// The elements in the tuple (a, b) are a: the preceding vertex;// b: the weight of the minimum path from u.

2 if v is unlabelled3 if ∃ no unlabelled vertex adjacent to a labelled vertex4 return no path.5 else for each xy ∈ E(G) s.t. x labelled (t, W) and y unlabelled6 compute W + w(xy)7 choose xy pair with minimum W + w(xy)8 label y (x, W + w(xy))9 else (v is labelled)

10 return the path iteratively obtained by taking v, the vertexfrom its label, the vertex from that vertex label, etc. (i.e. bybacktracking)

Figure 29: Minimum weight path forthis graph is AGFE.

A brief intro to complexity analysis: here we have two typesof steps - comparison and addition. At the kth iteration, we havelabelled k vertices. Thus there are ≤ k(n− k) additions.

Fact: to find the smallest (or largest) element from a set of size t,we need ≤ t− 1 comparisons. Therefore, ≤ k(n− k)− 1 comparisonsto chose xy. The worst case number of steps:

Recall:

t

∑k=1

k =t(t + 1)

2

t

∑k=1

k2 =t(t + 1)(2t + 1)

6

n−1

∑k=1

[k(n− k) + k(n− k)− 1] =n−1

∑k=1

2nk−n−1

∑k=1

2k2 −n−1

∑k=1

1

= 2nn(n− 1)

2− 2

(n− 1)(n)(2n− 1)6

− (n− 1)

=13

n3 − 43

n + 1

Page 50: MATH 240: Discrete Structures - GitHub Pages

50 anna brandenberger, binyuan sun

Kruskal’s Algorithm(G): find minimum weight spanning tree.

G is a connected weight graph.1 Find edge with minimum weight e1.2 k← 13 while k < n4 if ∃e ∈ E(G) such that {e} ∪ {e1, · · · , ek} has no cycle5 Set ek+1 as the unused edge having least weight

which does not make a cycle.6 k← k + 17 else return e1, e2, . . . , ek and exit.

Proof. Let Tk be the output. Tk = {e1, · · · , ek} satisfies the following:

- has no cycle: by construction.

- is spanning: if v 6∈ V(Tk) then any edge incident to v could still beadded (and the algorithm would not have stopped).

- is connected: let v, w ∈ V(G). Since G is connected, ∃ vw-path in G,say Pvw. If Pw is in Tk, then done.Else, let e ∈ E(Pvw) \ E(Tk). Adding e to Tk creates a cycle. Ife = xy, then Tk has an xy-path, Pxy. Take the path and replace theedge xy with Pxy (contained in Tk to get a new vw-walk with feweredges not in Tk).By iterating a finite number of times, we get a vw-walk in G, all ofwhose edges are in Tk, therefore Tk is connected.

We must now prove that the algorithm outputs the minimum weightspanning tree: Let Topt = MWST (and suppose w(Tk) > w(Topt))17. 17 No need, we didn’t end up using

contradiction.Tk = e1, e2, . . . , en−1 in the order added. Let ek be the first edgewhich is in Tk and Topt. Claim: There is an edge in Topt, say e, suchthat T = (Topt − e) + ek is a spanning tree. (To be proved in anassignment.)

=⇒ w(T) ≥ w(Topt)

=⇒ ����w(Topt)− w(e) + w(ek) ≥����w(Topt)

=⇒ w(ek) ≥ w(e)

If k = 1, then w(e1) was edge with minimum weight: w(e1) = w(e).If k > 1, by choice of k, e1, e2, . . . , ek−1 ∈ E(Topt), so the tree{e1, e2, . . . , ek−1} ∪ {e} ⊆ E(Topt)⇒ forms no cycles.

Since the algorithm chose ek over e, w(ek) ≤ w(e) ⇒ w(ek) =

w(e) ⇒ w(T)− w(Topt). And T shares more edges with Tk than Topt

did. Call T = T′opt. If Tk − T′opt. If Tk = T′opt, done. If not, repeatargument to get T′′opt which has minimum weight and more edges incommon with Tk than T′opt did, and so on. Eventually we stop whenwe get to Tk,⇒ w(Topt) = w(T′opt) = w(T′′opt) = · · · = w(Tk).

Page 51: MATH 240: Discrete Structures - GitHub Pages

math 240: discrete structures 51

Traveling Salesperson Problem: given n points (vertices) tovisit and a weight to each pair, i.e. a weighted complete graph, find aminimum weight Hamiltonian cycle Copt.

If the Triangle-Inequality is satisfied: w(xy)w(yz) ≥ w(xz) ∀x, y, z,then we can find a spanning closed walk W with w(W) ≤ 2w(Copt).

TSP Algorithm(G)

1 Take a mwst.2 Make a walk by starting at a root and walking down, then up

until you can walk down again, etc. Call the walk W.

Proof. As seen in Figure 30, w(W) = 2w(Topt). Also notice thatremoving any edge from Copt gives a spanning tree (Hamiltonianpath).

w(W) = 2w(Topt)

≤ 2w(Copt − e)

≤ 2w(Copt)

Figure 30: Example of the walk W ingray on the mwst.

Notes

- LPV stands for the textbook by L. Lovász, J. Pelikán and K. Veszter-gombi: Discrete Mathematics: Elementary and Beyond.

- Thanks to Suleman Malik for Figures 27 to 30.