graph theory - stanford universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...sd nog port...

210
Graph Theory

Upload: others

Post on 08-Jul-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Graph Theory

Page 2: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

http://strangemaps.fles.wordpress.com/2007/02/fullinterstatemap-web.jpg

Page 3: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Chemical Bonds

http://4.bp.blogspot.com/-xCtBJ8lKHqA/Tjm0BONWBRI/AAAAAAAAAK4/-mHrbAUOHHg/s1600/Ethanol2.gif

Page 4: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

https://xkcd.com/1195/

Page 5: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

http://www.prospectmagazine.co.uk/wp-content/uploads/2009/09/163_taylor2.jpg

Page 6: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 7: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 8: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

What's in Common

● Each of these structures consists of● a collection of objects and● links between those objects.

● Goal: fnd a general framework for describing these objects and their properties.

Page 9: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

A graph is a mathematical structurefor representing relationships.

A graph consists of a set of nodes connected by edges.

Page 10: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

A graph is a mathematical structurefor representing relationships.

A graph consists of a set of nodes (or vertices) connected by edges (or arcs)

Page 11: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

A graph is a mathematical structurefor representing relationships.

A graph consists of a set of nodes (or vertices) connected by edges (or arcs)

Nodes

Page 12: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

A graph is a mathematical structurefor representing relationships.

A graph consists of a set of nodes (or vertices) connected by edges (or arcs)

Edges

Page 13: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Some graphs are directed.

Page 14: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

CAT SAT RAT

RANMAN

MAT

CAN

Some graphs are undirected.

Page 15: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Going forward, we're primarily going to focus on undirected graphs.

The term “graph” generally refers to undirected graphs with a fnite number of

nodes, unless specifed otherwise.

Page 16: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Formalizing Graphs

● How might we defne a graph mathematically?

● We need to specify● what the nodes in the graph are, and● which edges are in the graph.

● The nodes can be pretty much anything.● What about the edges?

Page 17: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Formalizing Graphs

● An unordered pair is a set {a, b} of two elements a ≠ b. (Remember that sets are unordered).● {0, 1} = {1, 0}

● An undirected graph is an ordered pair G = (V, E), where● V is a set of nodes, which can be anything, and● E is a set of edges, which are unordered pairs of nodes

drawn from V.● A directed graph is an ordered pair G = (V, E),

where● V is a set of nodes, which can be anything, and● E is a set of edges, which are ordered pairs of nodes

drawn from V.

Page 18: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Self-Loops

● An edge from a node to itself is called a self-loop.● In undirected graphs, self-loops are generally not

allowed.● Can you see how this follows from the defnition?

● In directed graphs, self-loops are generally allowed unless specifed otherwise.

✓×

Page 19: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Standard Graph Terminology

Page 20: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

CAT SAT RAT

RANMAN

MAT

CAN

Two nodes are called adjacent if there is an edge between them.

Page 21: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

CAT SAT RAT

RANMAN

MAT

CAN

Two nodes are called adjacent if there is an edge between them.

Page 22: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

CAT SAT RAT

RANMAN

MAT

CAN

Two nodes are called adjacent if there is an edge between them.

Page 23: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

CAT SAT RAT

RANMAN

MAT

CAN

Two nodes are called adjacent if there is an edge between them.

Page 24: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Using our Formalisms

● Let G = (V, E) be a graph.● Intuitively, two nodes are adjacent if

they're linked by an edge.● Formally speaking, we say that two

nodes u, v ∈ V are adjacent if {u, v} ∈ E.

Page 25: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

http://strangemaps.fles.wordpress.com/2007/02/fullinterstatemap-web.jpg

Page 26: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

http://strangemaps.fles.wordpress.com/2007/02/fullinterstatemap-web.jpg

Page 27: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

SF Sac

Port

Sea But

SLC

Mon

LV

Bar Flag

LA

SD Nog

Phoe

Page 28: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

SF Sac

Port

Sea But

SLC

Mon

LV

Bar Flag

LA

SD Nog

Phoe

From

To

Page 29: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

SLC

LA

SD

But

Mon

LV

Bar Flag

Nog

Phoe

SF Sac

Port

Sea

From

To

SF, Sac, Port, SeaSF, Sac, Port, Sea

Page 30: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

LA

SD

But

Mon

LV

Bar Flag

Nog

Phoe

SLCSF Sac

Port

Sea

From

To

SF, Sac, SLC, Port, SeaSF, Sac, SLC, Port, Sea

Page 31: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

SD Nog

Port

SLC

LA

But

Mon

LV

Bar Flag

Phoe

SF Sac

Sea

From

To

SF, Sac, LA, Phoe, Flag, Bar, LV, Mon, SLC, But, SeaSF, Sac, LA, Phoe, Flag, Bar, LV, Mon, SLC, But, Sea

Page 32: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

SD Nog

Port

SLC

LA

But

Mon

LV

Bar Flag

Phoe

SF Sac

Sea

From

To A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

SF, Sac, LA, Phoe, Flag, Bar, LV, Mon, SLC, But, SeaSF, Sac, LA, Phoe, Flag, Bar, LV, Mon, SLC, But, Sea

Page 33: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

SD Nog

Port

SLC

LA

But

Mon

LV

Bar Flag

Phoe

SF Sac

Sea

From

To A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

The length of the path v₁, …, vₙis n – 1.

The length of the path v₁, …, vₙis n – 1.

SF, Sac, LA, Phoe, Flag, Bar, LV, Mon, SLC, But, SeaSF, Sac, LA, Phoe, Flag, Bar, LV, Mon, SLC, But, Sea

Page 34: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

SD Nog

Port

SLC

LA

But

Mon

LV

Bar Flag

Phoe

SF Sac

Sea

From

To A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

The length of the path v₁, …, vₙis n – 1.

The length of the path v₁, …, vₙis n – 1.

SF, Sac, LA, Phoe, Flag, Bar, LV, Mon, SLC, But, SeaSF, Sac, LA, Phoe, Flag, Bar, LV, Mon, SLC, But, Sea

(This path has length 10, but visits 11 cities.)

(This path has length 10, but visits 11 cities.)

Page 35: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

SF Sac

Port

Sea But

SLC

Mon

LV

Bar Flag

LA

SD Nog

Phoe

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

The length of the path v₁, …, vₙis n – 1.

The length of the path v₁, …, vₙis n – 1.

Page 36: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

SF Sac

Mon

LV

Bar Flag

LA

SD Nog

Phoe

Port

Sea But A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

The length of the path v₁, …, vₙis n – 1.

The length of the path v₁, …, vₙis n – 1.

SLC

Sea, But, SLC, Port, SeaSea, But, SLC, Port, Sea

From/To

Page 37: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Flag

SF

SD Nog

Phoe

Sac

Mon

LV

Bar

LA

Port

Sea But A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

The length of the path v₁, …, vₙis n – 1.

The length of the path v₁, …, vₙis n – 1.

SLC

Sac, Port, Sea, But, SLC, Mon, LV, Bar, LA, SacSac, Port, Sea, But, SLC, Mon, LV, Bar, LA, Sac

From/To

Page 38: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Flag

SF

SD Nog

Phoe

Sac

Mon

LV

Bar

LA

Port

Sea But A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

The length of the path v₁, …, vₙis n – 1.

The length of the path v₁, …, vₙis n – 1.

SLC

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

Sac, Port, Sea, But, SLC, Mon, LV, Bar, LA, SacSac, Port, Sea, But, SLC, Mon, LV, Bar, LA, Sac

From/To

Page 39: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Flag

SF

SD Nog

Phoe

Sac

Mon

LV

Bar

LA

Port

Sea But A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

The length of the path v₁, …, vₙis n – 1.

The length of the path v₁, …, vₙis n – 1.

SLC

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

Sac, Port, Sea, But, SLC, Mon, LV, Bar, LA, SacSac, Port, Sea, But, SLC, Mon, LV, Bar, LA, Sac

(This cycle has length nine and

visits nine diferent cities.)

(This cycle has length nine and

visits nine diferent cities.)

From/To

Page 40: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

SF Sac

Port

Sea But

SLC

Mon

LV

Bar Flag

LA

SD Nog

Phoe

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

The length of the path v₁, …, vₙis n – 1.

The length of the path v₁, …, vₙis n – 1.

Page 41: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Sac

Port

Sea But

SLC

Mon

LV

Bar Flag

LA

SD Nog

Phoe

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

The length of the path v₁, …, vₙis n – 1.

The length of the path v₁, …, vₙis n – 1.

SF

SFSF

Page 42: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Port

Sea But

SLC

Mon

LV

Bar Flag

LA

SD Nog

Phoe

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

The length of the path v₁, …, vₙis n – 1.

The length of the path v₁, …, vₙis n – 1.

SacSF

SF, SacSF, Sac

Page 43: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Port

Sea But

SLC

Mon

LV

Bar Flag

SD Nog

Phoe

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

The length of the path v₁, …, vₙis n – 1.

The length of the path v₁, …, vₙis n – 1.

SacSF

LA

SF, Sac, LASF, Sac, LA

Page 44: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Port

Sea But

SLC

Mon

LV

Bar Flag

SD Nog

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

The length of the path v₁, …, vₙis n – 1.

The length of the path v₁, …, vₙis n – 1.

SacSF

PhoeLA

SF, Sac, LA, PhoeSF, Sac, LA, Phoe

Page 45: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Port

Sea But

SLC

Mon

LV

Bar

SD Nog

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

The length of the path v₁, …, vₙis n – 1.

The length of the path v₁, …, vₙis n – 1.

SacSF

PhoeLA

Flag

SF, Sac, LA, Phoe, FlagSF, Sac, LA, Phoe, Flag

Page 46: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Port

Sea But

SLC

Mon

LV

SD Nog

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

The length of the path v₁, …, vₙis n – 1.

The length of the path v₁, …, vₙis n – 1.

SacSF

PhoeLA

FlagBar

SF, Sac, LA, Phoe, Flag, BarSF, Sac, LA, Phoe, Flag, Bar

Page 47: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Port

Sea But

SLC

Mon

LV

SD Nog

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

The length of the path v₁, …, vₙis n – 1.

The length of the path v₁, …, vₙis n – 1.

SacSF

PhoeLA

FlagBar

SF, Sac, LA, Phoe, Flag, Bar, LASF, Sac, LA, Phoe, Flag, Bar, LA

Page 48: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Port

Sea But

SLC

Mon

LV

SD Nog

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

The length of the path v₁, …, vₙis n – 1.

The length of the path v₁, …, vₙis n – 1.

SacSF

PhoeLA

FlagBar

SF, Sac, LA, Phoe, Flag, Bar, LASF, Sac, LA, Phoe, Flag, Bar, LA

Page 49: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A simple path in a graph is path that does not repeat any nodes or edges.

A simple path in a graph is path that does not repeat any nodes or edges.

The length of the path v₁, …, vₙis n – 1.

The length of the path v₁, …, vₙis n – 1.

Port

Sea But

SLC

Mon

LV

SD Nog

SacSF

PhoeLA

FlagBar

SF, Sac, LA, Phoe, Flag, Bar, LASF, Sac, LA, Phoe, Flag, Bar, LA

Page 50: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A simple path in a graph is path that does not repeat any nodes or edges.

A simple path in a graph is path that does not repeat any nodes or edges.

The length of the path v₁, …, vₙis n – 1.

The length of the path v₁, …, vₙis n – 1.

Port

Sea But

SLC

Mon

LV

SD Nog

SacSF

PhoeLA

FlagBar

SF, Sac, LA, Phoe, Flag, Bar, LASF, Sac, LA, Phoe, Flag, Bar, LA

(A path, not a simple path.)

(A path, not a simple path.)

Page 51: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A simple path in a graph is path that does not repeat any nodes or edges.

A simple path in a graph is path that does not repeat any nodes or edges.

The length of the path v₁, …, vₙis n – 1.

The length of the path v₁, …, vₙis n – 1.

Port

Sea But

SLC

Mon

LV

SD Nog

SacSF

PhoeLA

FlagBar

SF, Sac, LA, Phoe, Flag, Bar, LASF, Sac, LA, Phoe, Flag, Bar, LA

(This path has length six.)

(This path has length six.)

Page 52: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A simple path in a graph is path that does not repeat any nodes or edges.

A simple path in a graph is path that does not repeat any nodes or edges.

The length of the path v₁, …, vₙis n – 1.

The length of the path v₁, …, vₙis n – 1.

Port

Sea But

SLC

Mon

LV

SD Nog

SacSF

PhoeLA

FlagBar

Page 53: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A simple path in a graph is path that does not repeat any nodes or edges.

A simple path in a graph is path that does not repeat any nodes or edges.

The length of the path v₁, …, vₙis n – 1.

The length of the path v₁, …, vₙis n – 1.

Port

Sea But

SLC

Mon

LV

SD Nog

SF

PhoeLA

FlagBar

Sac

SacSac

Page 54: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A simple path in a graph is path that does not repeat any nodes or edges.

A simple path in a graph is path that does not repeat any nodes or edges.

The length of the path v₁, …, vₙis n – 1.

The length of the path v₁, …, vₙis n – 1.

Port

Sea But

Mon

LV

SD Nog

SF

PhoeLA

FlagBar

Sac SLC

Sac, SLCSac, SLC

Page 55: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A simple path in a graph is path that does not repeat any nodes or edges.

A simple path in a graph is path that does not repeat any nodes or edges.

The length of the path v₁, …, vₙis n – 1.

The length of the path v₁, …, vₙis n – 1.

Sea But

Mon

LV

SD Nog

SF

PhoeLA

FlagBar

Sac SLC

Port

Sac, SLC, PortSac, SLC, Port

Page 56: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A simple path in a graph is path that does not repeat any nodes or edges.

A simple path in a graph is path that does not repeat any nodes or edges.

The length of the path v₁, …, vₙis n – 1.

The length of the path v₁, …, vₙis n – 1.

Sea But

Mon

LV

SD Nog

SF

PhoeLA

FlagBar

Sac SLC

Port

Sac, SLC, Port, SacSac, SLC, Port, Sac

Page 57: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A simple path in a graph is path that does not repeat any nodes or edges.

A simple path in a graph is path that does not repeat any nodes or edges.

The length of the path v₁, …, vₙis n – 1.

The length of the path v₁, …, vₙis n – 1.

Sea But

Mon

LV

SD Nog

SF

PhoeLA

FlagBar

Sac SLC

Port

Sac, SLC, Port, Sac, SLCSac, SLC, Port, Sac, SLC

Page 58: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A simple path in a graph is path that does not repeat any nodes or edges.

A simple path in a graph is path that does not repeat any nodes or edges.

The length of the path v₁, …, vₙis n – 1.

The length of the path v₁, …, vₙis n – 1.

Sea But

Mon

LV

SD Nog

SF

PhoeLA

FlagBar

Sac SLC

Port

Sac, SLC, Port, Sac, SLC, PortSac, SLC, Port, Sac, SLC, Port

Page 59: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A simple path in a graph is path that does not repeat any nodes or edges.

A simple path in a graph is path that does not repeat any nodes or edges.

The length of the path v₁, …, vₙis n – 1.

The length of the path v₁, …, vₙis n – 1.

Sea But

Mon

LV

SD Nog

SF

PhoeLA

FlagBar

Sac SLC

Port

Sac, SLC, Port, Sac, SLC, Port, SacSac, SLC, Port, Sac, SLC, Port, Sac

Page 60: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A simple path in a graph is path that does not repeat any nodes or edges.

A simple path in a graph is path that does not repeat any nodes or edges.

The length of the path v₁, …, vₙis n – 1.

The length of the path v₁, …, vₙis n – 1.

Sea But

Mon

LV

SD Nog

SF

PhoeLA

FlagBar

Sac SLC

Port

A simple cycle in a graph is cycle that does not repeat any nodes or edges except the frst/last node.

A simple cycle in a graph is cycle that does not repeat any nodes or edges except the frst/last node.Sac, SLC, Port, Sac, SLC, Port, SacSac, SLC, Port, Sac, SLC, Port, Sac

Page 61: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A simple path in a graph is path that does not repeat any nodes or edges.

A simple path in a graph is path that does not repeat any nodes or edges.

The length of the path v₁, …, vₙis n – 1.

The length of the path v₁, …, vₙis n – 1.

Sea But

Mon

LV

SD Nog

SF

PhoeLA

FlagBar

Sac SLC

Port

A simple cycle in a graph is cycle that does not repeat any nodes or edges except the frst/last node.

A simple cycle in a graph is cycle that does not repeat any nodes or edges except the frst/last node.Sac, SLC, Port, Sac, SLC, Port, SacSac, SLC, Port, Sac, SLC, Port, Sac

(A cycle, not a simple cycle.)

(A cycle, not a simple cycle.)

Page 62: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A cycle in a graph is a path from a node back to itself. (By convention, a cycle cannot have length zero.)

A simple path in a graph is path that does not repeat any nodes or edges.

A simple path in a graph is path that does not repeat any nodes or edges.

The length of the path v₁, …, vₙis n – 1.

The length of the path v₁, …, vₙis n – 1.

Sea But

Mon

LV

SD Nog

SF

PhoeLA

FlagBar

Sac SLC

Port

A simple cycle in a graph is cycle that does not repeat any nodes or edges except the frst/last node.

A simple cycle in a graph is cycle that does not repeat any nodes or edges except the frst/last node.Sac, SLC, Port, Sac, SLC, Port, SacSac, SLC, Port, Sac, SLC, Port, Sac

(This cycle has length 6.)

(This cycle has length 6.)

Page 63: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

Sea But

Mon

LV

SD Nog

SF

PhoeLA

FlagBar

Sac SLC

Port

Page 64: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

Sea But

Mon

LV

SD Nog

SF

PhoeLA

FlagBar

Sac SLC

Port

Page 65: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

Sea But

Mon

LV

SD Nog

SF

PhoeLA

FlagBar

Sac SLC

Port

Page 66: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

Sea But

Mon

LV

SD Nog

SF

PhoeLA

FlagBar

Sac SLC

PortFrom

To

Page 67: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

Sea But

Mon

LV

SD Nog

SF

PhoeLA

FlagBar

Sac SLC

PortFrom

To

Page 68: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

Sea But

Mon

LV

SD Nog

SF

PhoeLA

FlagBar

Sac SLC

PortFrom

To

Two nodes in a graph are called connected if there is a path between them.

Two nodes in a graph are called connected if there is a path between them.

Page 69: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

Sea But

Mon

LV

SD Nog

SF

PhoeLA

FlagBar

Sac SLC

PortFrom

To

Two nodes in a graph are called connected if there is a path between them.

Two nodes in a graph are called connected if there is a path between them.

(These nodes are not connected. No Grand Canyon

for you.)

(These nodes are not connected. No Grand Canyon

for you.)

Page 70: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

Sea But

Mon

LV

SD Nog

SF

PhoeLA

FlagBar

Sac SLC

Port

Two nodes in a graph are called connected if there is a path between them.

Two nodes in a graph are called connected if there is a path between them.

A graph G as a whole is called connected if all pairs of nodes in G are connected.

A graph G as a whole is called connected if all pairs of nodes in G are connected.

Page 71: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

Sea But

Mon

LV

SD Nog

SF

PhoeLA

FlagBar

Sac SLC

Port

Two nodes in a graph are called connected if there is a path between them.

Two nodes in a graph are called connected if there is a path between them.

A graph G as a whole is called connected if all pairs of nodes in G are connected.

A graph G as a whole is called connected if all pairs of nodes in G are connected.

(This graph is not

connected.)

(This graph is not

connected.)

Page 72: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Connected Components

Page 73: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 74: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 75: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 76: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 77: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 78: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 79: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Page 80: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Page 81: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Connected Components

● Let G = (V, E) be a graph. For each v ∈ V, the connected component containing v is the set

[v] = { x ∈ V | v is connected to x }● Intuitively, a connected component is a “piece”

of a graph in the sense we just talked about.● Question: How do we know that this

particular defnition of a “piece” of a graph is a good one?

● Goal: Prove that any graph can be broken apart into diferent connected components.

Page 82: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

We’re trying to reason about some way of partitioning the nodes in a graph into

diferent groups.

What structure have we studied that captures the idea of a partition?

Page 83: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Connectivity

● Claim: For any graph G, the “is connected to” relation is an equivalence relation.● Is it refexive?● Is it symmetric?● Is it transitive?

Page 84: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Connectivity

Claim: For any graph G, the “is connected to” relation is an equivalence relation.● Is it refexive?

Is it symmetric?

Is it transitive?

∀v ∈ V. Conn(v, v)∀v ∈ V. Conn(v, v)

Page 85: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

Sea But

Mon

LV

SD Nog

SF

PhoeLA

FlagBar

Sac SLC

Port

Two nodes in a graph are called connected if there is a path between them

Two nodes in a graph are called connected if there is a path between them

Page 86: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Connectivity

Claim: For any graph G, the “is connected to” relation is an equivalence relation.● Is it refexive?

Is it symmetric?

Is it transitive?

∀v ∈ V. Conn(v, v)∀v ∈ V. Conn(v, v)

vA path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

A path in a graph G = (V, E) is a sequence of one or more nodes v₁, v₂, v₃, …, vₙ such that any two consecutive nodes in the sequence are adjacent.

Page 87: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Connectivity

Claim: For any graph G, the “is connected to” relation is an equivalence relation.

Is it refexive?● Is it symmetric?

Is it transitive?

∀x ∈ V. ∀y ∈ V. (Conn(x, y) → Conn(y, x))∀x ∈ V. ∀y ∈ V. (Conn(x, y) → Conn(y, x))

yx

Page 88: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Connectivity

Claim: For any graph G, the “is connected to” relation is an equivalence relation.

Is it refexive?● Is it symmetric?

Is it transitive?

∀x ∈ V. ∀y ∈ V. (Conn(x, y) → Conn(y, x))∀x ∈ V. ∀y ∈ V. (Conn(x, y) → Conn(y, x))

yx

Page 89: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Connectivity

Claim: For any graph G, the “is connected to” relation is an equivalence relation.

Is it refexive?

Is it symmetric?● Is it transitive?

∀x ∈ V. ∀y ∈ V. ∀z ∈ V. (Conn(x, y) ∧ Conn(y, z) → Conn(x, z))∀x ∈ V. ∀y ∈ V. ∀z ∈ V. (Conn(x, y) ∧ Conn(y, z) → Conn(x, z))

x

y

z

Page 90: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Connectivity

Claim: For any graph G, the “is connected to” relation is an equivalence relation.

Is it refexive?

Is it symmetric?● Is it transitive?

∀x ∈ V. ∀y ∈ V. ∀z ∈ V. (Conn(x, y) ∧ Conn(y, z) → Conn(x, z))∀x ∈ V. ∀y ∈ V. ∀z ∈ V. (Conn(x, y) ∧ Conn(y, z) → Conn(x, z))

x

y

z

Page 91: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Theorem: Let G = (V, E) be a graph. Then the connectivity relationover V is an equivalence relation.

Proof: Consider an arbitrary graph G = (V, E). We will prove thatthe connectivity relation over V is refexive, symmetric, andtransitive.

To show that connectivity is refexive, consider any v ∈ V. Then the singleton path v is a path from v to itself. Therefore, v is connected to itself, as required.

To show that connectivity is symmetric, consider any x, y ∈ V where x is connected to y. We need to show that y is connected to x. Since x is connected to y, there is some path x, v₁, …, vₙ, y from x to y. Then y, vₙ, …, v₁, x is a path from y back to x, so y is connected to x.

Finally, to show that connectivity is transitive, let x, y, z ∈ V be arbitrary nodes where x is connected to y and y is connected to z. We will prove that x is connected to z. Since x is connected to y, there is a path x, u₁, …, uₙ, y from x to y. Since y is connected to z, there is a path y, v₁, …, vₖ, z from y to z. Then the pathx, u₁, …, uₙ, y, v₁, …, vₖ, z goes from x to z. Thus x is connected to z, as required. ■

Page 92: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Putting Things Together

● Earlier, we defned the connected component of a node v to be

[v] = { x ∈ V | v is connected to x }● Connectivity is an equivalence relation! So

what’s the equivalence class of a node v with respect to connectivity?

[v]conn = { x ∈ V | v is connected to x }

● Connected components are equivalence classes of the connectivity relation!

Page 93: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Theorem: If G = (V, E) is a graph, then every node in Gbelongs to exactly one connected component of G.

Proof: Let G = (V, E) be an arbitrary graph and let v ∈ V beany node in G. The connected components of G are justthe equivalence classes of the connectivity relation in G.The Fundamental Theorem of Equivalence Relationsguarantees that v belongs to exactly one equivalenceclass of the connectivity relation. Therefore, v belongs toexactly one connected component in G. ■

Page 94: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Time-Out for Announcements!

Page 95: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Problem Set Three

● The checkpoint problems for PS3 were due at 3:00PM today.● We'll try to have it graded and returned by

Wednesday morning.● The remaining problems from PS3 are

due on Friday at 3:00PM.● Have questions? Stop by ofice hours or ask

on Piazza!

Page 96: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Back to CS103!

Page 97: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

The Pigeonhole Principle

Page 98: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

The Pigeonhole Principle

● Theorem (The Pigeonhole Principle): If m objects are distributed into n bins and m > n, then at least one bin will contain at least two objects.

Page 99: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

The Pigeonhole Principle

● Theorem (The Pigeonhole Principle): If m objects are distributed into n bins and m > n, then at least one bin will contain at least two objects.

Page 100: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

The Pigeonhole Principle

● Theorem (The Pigeonhole Principle): If m objects are distributed into n bins and m > n, then at least one bin will contain at least two objects.

Page 101: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

The Pigeonhole Principle

● Theorem (The Pigeonhole Principle): If m objects are distributed into n bins and m > n, then at least one bin will contain at least two objects.

Page 102: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

m = 4, n = 3

Page 103: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Some Simple Applications● Any group of 367 people must have a pair of

people that share a birthday.● 366 possible birthdays (pigeonholes)● 367 people (pigeons)

● Two people in San Francisco have the exact same number of hairs on their head.● Maximum number of hairs ever found on a

human head is no greater than 500,000.● There are over 800,000 people in San Francisco.

Page 104: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Proving the Pigeonhole Principle

Page 105: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Theorem: If m objects are distributed into n bins and m > n,then there must be some bin that contains at least two objects.

Proof: Suppose for the sake of contradiction that, for some m andn where m > n, there is a way to distribute m objects into nbins such that each bin contains at most one object.

Number the bins 1, 2, 3, …, n and let xᵢ denote the number of objects in bin i. There are m objects in total, so we know that

m = x₁ + x₂ + … + xₙ.

Since each bin has at most one object in it, we know xᵢ ≤ 1 for each i. This means that

m = x₁ + x₂ + … + xₙ≤ 1 + 1 + … + 1 (n times)= n.

This means that m ≤ n, contradicting that m > n. We’ve reached a contradiction, so our assumption must have been wrong. Therefore, if m objects are distributed into n bins with m > n, some bin must contain at least two objects. ■

Page 106: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Pigeonhole Principle Party Tricks

Page 107: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 108: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 109: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 110: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Degrees

● The degree of a node v in a graph is the number of nodes that v is adjacent to.

● Theorem: Every graph with at least two nodes has at least two nodes with the same degree.● Equivalently: at any party with at least two

people, there are at least two people with the same number of friends at the party.

1

2 1

0 3

3 3

3

Page 111: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

A

B C

D

EF

0 1 2 3 4 5

AB CD

E

F

Page 112: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

0 1 2 3 4 5

A

B C

D

EF

Page 113: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

0 1 2 3 4 5

A

B C

D

EF

With n nodes, there are n possible

degrees(0, 1, 2, …, n – 1)

With n nodes, there are n possible

degrees(0, 1, 2, …, n – 1)

Page 114: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

0 1 2 3 4 5

A

B C

D

EF

Page 115: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

0 1 2 3 4 5

A

B C

D

EFCan both of

these buckets be nonempty?

Can both of these buckets be nonempty?

Page 116: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

1 2 3 4 0 / 5

A

B C

D

EF

Page 117: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Theorem: In any graph with at least two nodes, there areat least two nodes of the same degree.

Proof 1: Let G be a graph with n ≥ 2 nodes. There are npossible choices for the degrees of nodes in G, namely,0, 1, 2, …, and n – 1.

We claim that G cannot simultaneously have a node u of degree 0 and a node v of degree n – 1: if there were such nodes, then node u would be adjacent to no other nodes and node v would be adjacent to all other nodes, including u. (Note that u and v must be diferent nodes, since v has degree at least 1 and u has degree 0.)

We therefore see that the possible options for degrees of nodes in G are either drawn from 0, 1, …, n – 2 or from1, 2, …, n – 1. In either case, there are n nodes and n – 1 possible degrees, so by the pigeonhole principle two nodes in G must have the same degree. ■

Page 118: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Theorem: In any graph with at least two nodes, there areat least two nodes of the same degree.

Proof 1: Let G be a graph with n ≥ 2 nodes. There are npossible choices for the degrees of nodes in G, namely,0, 1, 2, …, and n – 1.

We claim that G cannot simultaneously have a node u of degree 0 and a node v of degree n – 1: if there were such nodes, then node u would be adjacent to no other nodes and node v would be adjacent to all other nodes, including u. (Note that u and v must be diferent nodes, since v has degree at least 1 and u has degree 0.)

We therefore see that the possible options for degrees of nodes in G are either drawn from 0, 1, …, n – 2 or from1, 2, …, n – 1. In either case, there are n nodes and n – 1 possible degrees, so by the pigeonhole principle two nodes in G must have the same degree. ■

Page 119: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Theorem: In any graph with at least two nodes, there areat least two nodes of the same degree.

Proof 1: Let G be a graph with n ≥ 2 nodes. There are npossible choices for the degrees of nodes in G, namely,0, 1, 2, …, and n – 1.

We claim that G cannot simultaneously have a node u of degree 0 and a node v of degree n – 1: if there were such nodes, then node u would be adjacent to no other nodes and node v would be adjacent to all other nodes, including u. (Note that u and v must be diferent nodes, since v has degree at least 1 and u has degree 0.)

We therefore see that the possible options for degrees of nodes in G are either drawn from 0, 1, …, n – 2 or from1, 2, …, n – 1. In either case, there are n nodes and n – 1 possible degrees, so by the pigeonhole principle two nodes in G must have the same degree. ■

Page 120: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Theorem: In any graph with at least two nodes, there areat least two nodes of the same degree.

Proof 1: Let G be a graph with n ≥ 2 nodes. There are npossible choices for the degrees of nodes in G, namely,0, 1, 2, …, and n – 1.

We claim that G cannot simultaneously have a node u of degree 0 and a node v of degree n – 1: if there were such nodes, then node u would be adjacent to no other nodes and node v would be adjacent to all other nodes, including u. (Note that u and v must be diferent nodes, since v has degree at least 1 and u has degree 0.)

We therefore see that the possible options for degrees of nodes in G are either drawn from 0, 1, …, n – 2 or from1, 2, …, n – 1. In either case, there are n nodes and n – 1 possible degrees, so by the pigeonhole principle two nodes in G must have the same degree. ■

Page 121: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Theorem: In any graph with at least two nodes, there areat least two nodes of the same degree.

Proof 1: Let G be a graph with n ≥ 2 nodes. There are npossible choices for the degrees of nodes in G, namely,0, 1, 2, …, and n – 1.

We claim that G cannot simultaneously have a node u of degree 0 and a node v of degree n – 1: if there were such nodes, then node u would be adjacent to no other nodes and node v would be adjacent to all other nodes, including u. (Note that u and v must be diferent nodes, since v has degree at least 1 and u has degree 0.)

We therefore see that the possible options for degrees of nodes in G are either drawn from 0, 1, …, n – 2 or from1, 2, …, n – 1. In either case, there are n nodes and n – 1 possible degrees, so by the pigeonhole principle two nodes in G must have the same degree. ■

Page 122: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Theorem: In any graph with at least two nodes, there areat least two nodes of the same degree.

Proof 1: Let G be a graph with n ≥ 2 nodes. There are npossible choices for the degrees of nodes in G, namely,0, 1, 2, …, and n – 1.

We claim that G cannot simultaneously have a node u of degree 0 and a node v of degree n – 1: if there were such nodes, then node u would be adjacent to no other nodes and node v would be adjacent to all other nodes, including u. (Note that u and v must be diferent nodes, since v has degree at least 1 and u has degree 0.)

We therefore see that the possible options for degrees of nodes in G are either drawn from 0, 1, …, n – 2 or from1, 2, …, n – 1. In either case, there are n nodes and n – 1 possible degrees, so by the pigeonhole principle two nodes in G must have the same degree. ■

Page 123: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Theorem: In any graph with at least two nodes, there areat least two nodes of the same degree.

Proof 1: Let G be a graph with n ≥ 2 nodes. There are npossible choices for the degrees of nodes in G, namely,0, 1, 2, …, and n – 1.

We claim that G cannot simultaneously have a node u of degree 0 and a node v of degree n – 1: if there were such nodes, then node u would be adjacent to no other nodes and node v would be adjacent to all other nodes, including u. (Note that u and v must be diferent nodes, since v has degree at least 1 and u has degree 0.)

We therefore see that the possible options for degrees of nodes in G are either drawn from 0, 1, …, n – 2 or from1, 2, …, n – 1. In either case, there are n nodes and n – 1 possible degrees, so by the pigeonhole principle two nodes in G must have the same degree. ■

Page 124: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Theorem: In any graph with at least two nodes, there areat least two nodes of the same degree.

Proof 1: Let G be a graph with n ≥ 2 nodes. There are npossible choices for the degrees of nodes in G, namely,0, 1, 2, …, and n – 1.

We claim that G cannot simultaneously have a node u of degree 0 and a node v of degree n – 1: if there were such nodes, then node u would be adjacent to no other nodes and node v would be adjacent to all other nodes, including u. (Note that u and v must be diferent nodes, since v has degree at least 1 and u has degree 0.)

We therefore see that the possible options for degrees of nodes in G are either drawn from 0, 1, …, n – 2 or from1, 2, …, n – 1. In either case, there are n nodes and n – 1 possible degrees, so by the pigeonhole principle two nodes in G must have the same degree. ■

Page 125: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Theorem: In any graph with at least two nodes, there areat least two nodes of the same degree.

Proof 1: Let G be a graph with n ≥ 2 nodes. There are npossible choices for the degrees of nodes in G, namely,0, 1, 2, …, and n – 1.

We claim that G cannot simultaneously have a node u of degree 0 and a node v of degree n – 1: if there were such nodes, then node u would be adjacent to no other nodes and node v would be adjacent to all other nodes, including u. (Note that u and v must be diferent nodes, since v has degree at least 1 and u has degree 0.)

We therefore see that the possible options for degrees of nodes in G are either drawn from 0, 1, …, n – 2 or from1, 2, …, n – 1. In either case, there are n nodes and n – 1 possible degrees, so by the pigeonhole principle two nodes in G must have the same degree. ■

Page 126: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Theorem: In any graph with at least two nodes, there areat least two nodes of the same degree.

Proof 2: Assume for the sake of contradiction that thereis a graph G with n ≥ 2 nodes where no two nodeshave the same degree. There are n possible choicesfor the degrees of nodes in G, namely 0, 1, 2, …, n – 1,so this means that G must have exactly one node ofeach degree. However, this means that G has a nodeof degree 0 and a node of degree n – 1. (These can'tbe the same node, since n ≥ 2.) This frst node isadjacent to no other nodes, but this second node isadjacent to every other node, which is impossible.

We have reached a contradiction, so our assumption must have been wrong. Thus if G is a graph with at least two nodes, G must have at least two nodes of the same degree. ■

Page 127: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

The Generalized Pigeonhole Principle

Page 128: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

The Pigeonhole Principle

Page 129: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

The Pigeonhole Principle

? ? ? ?

?

?

Page 130: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

The Pigeonhole Principle

Page 131: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

The Pigeonhole Principle

Page 132: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

The Pigeonhole Principle

Page 133: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

The Pigeonhole Principle

11

5= 2

1

5

Page 134: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

A More General Version● The generalized pigeonhole principle says

that if you distribute m objects into n bins, then● some bin will have at least ⌈m/ₙ⌉ objects in it, and● some bin will have at most ⌊m/ₙ⌋ objects in it.

⌈m/ₙ⌉ means “m/ₙ, rounded up.”⌊m/ₙ⌋ means “m/ₙ, rounded down.”

⌈m/ₙ⌉ means “m/ₙ, rounded up.”⌊m/ₙ⌋ means “m/ₙ, rounded down.”

m = 11 n = 5

⌈m / n⌉ = 3⌊m / n⌋ = 2

Page 135: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

A More General Version● The generalized pigeonhole principle says

that if you distribute m objects into n bins, then● some bin will have at least ⌈m/ₙ⌉ objects in it, and● some bin will have at most ⌊m/ₙ⌋ objects in it.

⌈m/ₙ⌉ means “m/ₙ, rounded up.”⌊m/ₙ⌋ means “m/ₙ, rounded down.”

⌈m/ₙ⌉ means “m/ₙ, rounded up.”⌊m/ₙ⌋ means “m/ₙ, rounded down.”

m = 11 n = 5

⌈m / n⌉ = 3⌊m / n⌋ = 2

Page 136: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

A More General Version● The generalized pigeonhole principle says

that if you distribute m objects into n bins, then● some bin will have at least ⌈m/ₙ⌉ objects in it, and● some bin will have at most ⌊m/ₙ⌋ objects in it.

⌈m/ₙ⌉ means “m/ₙ, rounded up.”⌊m/ₙ⌋ means “m/ₙ, rounded down.”

⌈m/ₙ⌉ means “m/ₙ, rounded up.”⌊m/ₙ⌋ means “m/ₙ, rounded down.”

m = 11 n = 5

⌈m / n⌉ = 3⌊m / n⌋ = 2

×11

Page 137: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

m = 8, n = 3

Page 138: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Theorem: If m objects are distributed into n > 0 bins, then somebin will contain at least ⌈m/ₙ⌉ objects.

Proof: We will prove that if m objects are distributed into n bins, thensome bin contains at least m/ₙ objects. Since the number of objects ineach bin is an integer, this will prove that some bin must contain atleast ⌈m/ₙ⌉ objects.

To do this, we proceed by contradiction. Suppose that, for some m and n, there is a way to distribute m objects into n bins such that each bin contains fewer than m/ₙ objects.

Number the bins 1, 2, 3, …, n and let xᵢ denote the number of objects in bin i. Since there are m objects in total, we know that

m = x₁ + x₂ + … + xₙ.

Since each bin contains fewer than m/ₙ objects, we see thatxᵢ < m/ₙ for each i. Therefore, we have that

m = x₁ + x₂ + … + xₙ< m/ₙ + m/ₙ + … + m/ₙ (n times)= m.

But this means that m < m, which is impossible. We have reached a contradiction, so our initial assumption must have been wrong. Therefore, if m objects are distributed into n bins, some bin must contain at least ⌈m/ₙ⌉ objects. ■

Page 139: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

An Application: Friends and Strangers

Page 140: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Friends and Strangers

● Suppose you have a party of six people. Each pair of people are either friends (they know each other) or strangers (they do not).

● Theorem: Any such party must have a group of three mutual friends (three people who all know one another) or three mutual strangers (three people, none of whom know any of the others).

Page 141: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 142: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 143: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 144: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 145: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 146: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 147: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

This graph is called a 6-clique,

by the way.

This graph is called a 6-clique,

by the way.

Page 148: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 149: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 150: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 151: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 152: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Friends and Strangers Restated

● From a graph-theoretic perspective, the Theorem on Friends and Strangers can be restated as follows:

Theorem: Any 6-clique whose edges are colored red and blue contains a red triangle or a blue triangle (or both).

● How can we prove this?

Page 153: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 154: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 155: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 156: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 157: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 158: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 159: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Observation 1: If we pick any node in the graph, that node

will have at least ⌈5/2⌉ = 3 edges of

the same color incident to it.

Observation 1: If we pick any node in the graph, that node

will have at least ⌈5/2⌉ = 3 edges of

the same color incident to it.

Page 160: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 161: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 162: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 163: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 164: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 165: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 166: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 167: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 168: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Theorem: Consider a 6-clique in which every edge is coloredeither red or blue. Then there must be a triangle of rededges, a triangle of blue edges, or both.

Proof: Color the edges of the 6-clique either red or bluearbitrarily. Let x be any node in the 6-clique. It is incidentto fve edges and there are two possible colors for thoseedges. Therefore, by the generalized pigeonhole principle,at least ⌈⁵/₂⌉ = 3 of those edges must be the same color.Call that color c₁ and let the other color be c₂.

Let r, s, and t be three of the nodes adjacent to node x along an edge of color c₁. If any of the edges {r, s}, {r, t}, or {s, t} are of color c₁, then one of those edges plus the two edges connecting back to node x form a triangle of color c₁. Otherwise, all three of those edges are of color c₂, and they form a triangle of color c₂. Overall, this gives a red triangle or a blue triangle, as required. ■

Page 169: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Ramsey Theory

● The proof we did is a special case of a broader result.

● Theorem (Ramsey’s Theorem): For any natural number n, there is a smallest natural number R(n) such that if the edges of an R(n)-clique are colored red or blue, the resulting graph will contain either a red n-clique or a blue n-clique.● Our proof was that R(3) ≤ 6.

● A more philosophical take on this theorem: true disorder is impossible at a large scale, since no matter how you organize things, you’re guaranteed to fnd some interesting substructure.

Page 170: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

A Little Math Puzzle

Page 171: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

“In a group of n > 0 people …

· 90% of those people enjoyed Get Out, · 80% of those people enjoyed Lady Bird, · 70% of those people enjoyed Arrival, and · 60% of those people enjoyed Zootopia.

No one enjoyed all four movies. How many people enjoyed at least one of Get Out and Arrival?”

“In a group of n > 0 people …

· 90% of those people enjoyed Get Out, · 80% of those people enjoyed Lady Bird, · 70% of those people enjoyed Arrival, and · 60% of those people enjoyed Zootopia.

No one enjoyed all four movies. How many people enjoyed at least one of Get Out and Arrival?”

(Adapted from here.)

Page 172: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Other Pigeonhole-Type Results

Page 173: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

If m objects are distributed into n boxes, then [condition] holds.

Page 174: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

If m objects are distributed into n boxes, then some box is loaded to at

least the average ᵐ/ₙ, and some box is loaded to at most the average ᵐ/ₙ.

Page 175: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

If m objects are distributed into n boxes, then [condition] holds.

Page 176: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 177: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 178: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 179: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 180: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)
Page 181: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Theorem: If m objects are distributed into n bins, then there is a bin containing more than ᵐ/ₙ objects if and only if there is a bin

containing fewer than ᵐ/ₙ objects.

Page 182: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Lemma: If m objects are distributed into n bins and there are no binscontaining more than ᵐ/ₙ objects, then there are no bins containingfewer than ᵐ/ₙ objects.

Proof: Assume for the sake of contradiction that m objects are distributedinto n bins such that no bin contains more than ᵐ/ₙ objects, yet somebin has fewer than ᵐ/ₙ objects.

For simplicity, denote by xᵢ the number of objects in bin i. Without loss of generality, assume that bin 1 has fewer than ᵐ/ₙ objects, meaning that x₁ < ᵐ/ₙ. Adding up the number of objects in each bin tells us that

m = x₁ + x₂ + x₃ + … + xₙ

< ᵐ/ₙ + x₂ + x₃ + … + xₙ

≤ ᵐ/ₙ + ᵐ/ₙ + ᵐ/ₙ + … + ᵐ/ₙ.

This third step follows because each remaining bin has at most ᵐ/ₙ objects. Grouping the n copies of the ᵐ/ₙ term here tells us that

m < ᵐ/ₙ + ᵐ/ₙ + ᵐ/ₙ + … + ᵐ/ₙ

= m.

But this means m < m, which is impossible. We’ve reached a contradiction, so our assumption was wrong, so if m objects are distributed into n bins and no bin has more than ᵐ/ₙ objects, no bin has fewer than ᵐ/ₙ objects either. ■

Page 183: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Lemma: If m objects are distributed into n bins and there are no binscontaining more than ᵐ/ₙ objects, then there are no bins containingfewer than ᵐ/ₙ objects.

Proof: Assume for the sake of contradiction that m objects are distributedinto n bins such that no bin contains more than ᵐ/ₙ objects, yet somebin has fewer than ᵐ/ₙ objects.

For simplicity, denote by xᵢ the number of objects in bin i. Without loss of generality, assume that bin 1 has fewer than ᵐ/ₙ objects, meaning that x₁ < ᵐ/ₙ. Adding up the number of objects in each bin tells us that

m = x₁ + x₂ + x₃ + … + xₙ

< ᵐ/ₙ + x₂ + x₃ + … + xₙ

≤ ᵐ/ₙ + ᵐ/ₙ + ᵐ/ₙ + … + ᵐ/ₙ.

This third step follows because each remaining bin has at most ᵐ/ₙ objects. Grouping the n copies of the ᵐ/ₙ term here tells us that

m < ᵐ/ₙ + ᵐ/ₙ + ᵐ/ₙ + … + ᵐ/ₙ

= m.

But this means m < m, which is impossible. We’ve reached a contradiction, so our assumption was wrong, so if m objects are distributed into n bins and no bin has more than ᵐ/ₙ objects, no bin has fewer than ᵐ/ₙ objects either. ■

Page 184: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Lemma: If m objects are distributed into n bins and there are no binscontaining more than ᵐ/ₙ objects, then there are no bins containingfewer than ᵐ/ₙ objects.

Proof: Assume for the sake of contradiction that m objects are distributedinto n bins such that no bin contains more than ᵐ/ₙ objects, yet somebin has fewer than ᵐ/ₙ objects.

For simplicity, denote by xᵢ the number of objects in bin i. Without loss of generality, assume that bin 1 has fewer than ᵐ/ₙ objects, meaning that x₁ < ᵐ/ₙ. Adding up the number of objects in each bin tells us that

m = x₁ + x₂ + x₃ + … + xₙ

< ᵐ/ₙ + x₂ + x₃ + … + xₙ

≤ ᵐ/ₙ + ᵐ/ₙ + ᵐ/ₙ + … + ᵐ/ₙ.

This third step follows because each remaining bin has at most ᵐ/ₙ objects. Grouping the n copies of the ᵐ/ₙ term here tells us that

m < ᵐ/ₙ + ᵐ/ₙ + ᵐ/ₙ + … + ᵐ/ₙ

= m.

But this means m < m, which is impossible. We’ve reached a contradiction, so our assumption was wrong, so if m objects are distributed into n bins and no bin has more than ᵐ/ₙ objects, no bin has fewer than ᵐ/ₙ objects either. ■

Page 185: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Lemma: If m objects are distributed into n bins and there are no binscontaining more than ᵐ/ₙ objects, then there are no bins containingfewer than ᵐ/ₙ objects.

Proof: Assume for the sake of contradiction that m objects are distributedinto n bins such that no bin contains more than ᵐ/ₙ objects, yet somebin has fewer than ᵐ/ₙ objects.

For simplicity, denote by xᵢ the number of objects in bin i. Without loss of generality, assume that bin 1 has fewer than ᵐ/ₙ objects, meaning that x₁ < ᵐ/ₙ. Adding up the number of objects in each bin tells us that

m = x₁ + x₂ + x₃ + … + xₙ

< ᵐ/ₙ + x₂ + x₃ + … + xₙ

≤ ᵐ/ₙ + ᵐ/ₙ + ᵐ/ₙ + … + ᵐ/ₙ.

This third step follows because each remaining bin has at most ᵐ/ₙ objects. Grouping the n copies of the ᵐ/ₙ term here tells us that

m < ᵐ/ₙ + ᵐ/ₙ + ᵐ/ₙ + … + ᵐ/ₙ

= m.

But this means m < m, which is impossible. We’ve reached a contradiction, so our assumption was wrong, so if m objects are distributed into n bins and no bin has more than ᵐ/ₙ objects, no bin has fewer than ᵐ/ₙ objects either. ■

Page 186: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Lemma: If m objects are distributed into n bins and there are no binscontaining more than ᵐ/ₙ objects, then there are no bins containingfewer than ᵐ/ₙ objects.

Proof: Assume for the sake of contradiction that m objects are distributedinto n bins such that no bin contains more than ᵐ/ₙ objects, yet somebin has fewer than ᵐ/ₙ objects.

For simplicity, denote by xᵢ the number of objects in bin i. Without loss of generality, assume that bin 1 has fewer than ᵐ/ₙ objects, meaning that x₁ < ᵐ/ₙ. Adding up the number of objects in each bin tells us that

m = x₁ + x₂ + x₃ + … + xₙ

< ᵐ/ₙ + x₂ + x₃ + … + xₙ

≤ ᵐ/ₙ + ᵐ/ₙ + ᵐ/ₙ + … + ᵐ/ₙ.

This third step follows because each remaining bin has at most ᵐ/ₙ objects. Grouping the n copies of the ᵐ/ₙ term here tells us that

m < ᵐ/ₙ + ᵐ/ₙ + ᵐ/ₙ + … + ᵐ/ₙ

= m.

But this means m < m, which is impossible. We’ve reached a contradiction, so our assumption was wrong, so if m objects are distributed into n bins and no bin has more than ᵐ/ₙ objects, no bin has fewer than ᵐ/ₙ objects either. ■

Page 187: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Lemma: If m objects are distributed into n bins and there are no binscontaining more than ᵐ/ₙ objects, then there are no bins containingfewer than ᵐ/ₙ objects.

Proof: Assume for the sake of contradiction that m objects are distributedinto n bins such that no bin contains more than ᵐ/ₙ objects, yet somebin has fewer than ᵐ/ₙ objects.

For simplicity, denote by xᵢ the number of objects in bin i. Without loss of generality, assume that bin 1 has fewer than ᵐ/ₙ objects, meaning that x₁ < ᵐ/ₙ. Adding up the number of objects in each bin tells us that

m = x₁ + x₂ + x₃ + … + xₙ

< ᵐ/ₙ + x₂ + x₃ + … + xₙ

≤ ᵐ/ₙ + ᵐ/ₙ + ᵐ/ₙ + … + ᵐ/ₙ.

This third step follows because each remaining bin has at most ᵐ/ₙ objects. Grouping the n copies of the ᵐ/ₙ term here tells us that

m < ᵐ/ₙ + ᵐ/ₙ + ᵐ/ₙ + … + ᵐ/ₙ

= m.

But this means m < m, which is impossible. We’ve reached a contradiction, so our assumption was wrong, so if m objects are distributed into n bins and no bin has more than ᵐ/ₙ objects, no bin has fewer than ᵐ/ₙ objects either. ■

1 2 3 4 5 614

This magic phrase means “we get to pick how we’re labeling things anyway,

so if it doesn’t work out, just relabel things.”

This magic phrase means “we get to pick how we’re labeling things anyway,

so if it doesn’t work out, just relabel things.”

Page 188: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Lemma: If m objects are distributed into n bins and there are no binscontaining more than ᵐ/ₙ objects, then there are no bins containingfewer than ᵐ/ₙ objects.

Proof: Assume for the sake of contradiction that m objects are distributedinto n bins such that no bin contains more than ᵐ/ₙ objects, yet somebin has fewer than ᵐ/ₙ objects.

For simplicity, denote by xᵢ the number of objects in bin i. Without loss of generality, assume that bin 1 has fewer than ᵐ/ₙ objects, meaning that x₁ < ᵐ/ₙ. Adding up the number of objects in each bin tells us that

m = x₁ + x₂ + x₃ + … + xₙ

< ᵐ/ₙ + x₂ + x₃ + … + xₙ

≤ ᵐ/ₙ + ᵐ/ₙ + ᵐ/ₙ + … + ᵐ/ₙ.

This third step follows because each remaining bin has at most ᵐ/ₙ objects. Grouping the n copies of the ᵐ/ₙ term here tells us that

m < ᵐ/ₙ + ᵐ/ₙ + ᵐ/ₙ + … + ᵐ/ₙ

= m.

But this means m < m, which is impossible. We’ve reached a contradiction, so our assumption was wrong, so if m objects are distributed into n bins and no bin has more than ᵐ/ₙ objects, no bin has fewer than ᵐ/ₙ objects either. ■

Page 189: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Lemma: If m objects are distributed into n bins and there are no binscontaining more than ᵐ/ₙ objects, then there are no bins containingfewer than ᵐ/ₙ objects.

Proof: Assume for the sake of contradiction that m objects are distributedinto n bins such that no bin contains more than ᵐ/ₙ objects, yet somebin has fewer than ᵐ/ₙ objects.

For simplicity, denote by xᵢ the number of objects in bin i. Without loss of generality, assume that bin 1 has fewer than ᵐ/ₙ objects, meaning that x₁ < ᵐ/ₙ. Adding up the number of objects in each bin tells us that

m = x₁ + x₂ + x₃ + … + xₙ

< ᵐ/ₙ + x₂ + x₃ + … + xₙ

≤ ᵐ/ₙ + ᵐ/ₙ + ᵐ/ₙ + … + ᵐ/ₙ.

This third step follows because each remaining bin has at most ᵐ/ₙ objects. Grouping the n copies of the ᵐ/ₙ term here tells us that

m < ᵐ/ₙ + ᵐ/ₙ + ᵐ/ₙ + … + ᵐ/ₙ

= m.

But this means m < m, which is impossible. We’ve reached a contradiction, so our assumption was wrong, so if m objects are distributed into n bins and no bin has more than ᵐ/ₙ objects, no bin has fewer than ᵐ/ₙ objects either. ■

Page 190: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Lemma: If m objects are distributed into n bins and there are no binscontaining more than ᵐ/ₙ objects, then there are no bins containingfewer than ᵐ/ₙ objects.

Proof: Assume for the sake of contradiction that m objects are distributedinto n bins such that no bin contains more than ᵐ/ₙ objects, yet somebin has fewer than ᵐ/ₙ objects.

For simplicity, denote by xᵢ the number of objects in bin i. Without loss of generality, assume that bin 1 has fewer than ᵐ/ₙ objects, meaning that x₁ < ᵐ/ₙ. Adding up the number of objects in each bin tells us that

m = x₁ + x₂ + x₃ + … + xₙ

< ᵐ/ₙ + x₂ + x₃ + … + xₙ

≤ ᵐ/ₙ + ᵐ/ₙ + ᵐ/ₙ + … + ᵐ/ₙ.

This third step follows because each remaining bin has at most ᵐ/ₙ objects. Grouping the n copies of the ᵐ/ₙ term here tells us that

m < ᵐ/ₙ + ᵐ/ₙ + ᵐ/ₙ + … + ᵐ/ₙ

= m.

But this means m < m, which is impossible. We’ve reached a contradiction, so our assumption was wrong, so if m objects are distributed into n bins and no bin has more than ᵐ/ₙ objects, no bin has fewer than ᵐ/ₙ objects either. ■

Page 191: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Lemma: If m objects are distributed into n bins and there are no binscontaining more than ᵐ/ₙ objects, then there are no bins containingfewer than ᵐ/ₙ objects.

Proof: Assume for the sake of contradiction that m objects are distributedinto n bins such that no bin contains more than ᵐ/ₙ objects, yet somebin has fewer than ᵐ/ₙ objects.

For simplicity, denote by xᵢ the number of objects in bin i. Without loss of generality, assume that bin 1 has fewer than ᵐ/ₙ objects, meaning that x₁ < ᵐ/ₙ. Adding up the number of objects in each bin tells us that

m = x₁ + x₂ + x₃ + … + xₙ

< ᵐ/ₙ + x₂ + x₃ + … + xₙ

≤ ᵐ/ₙ + ᵐ/ₙ + ᵐ/ₙ + … + ᵐ/ₙ.

This third step follows because each remaining bin has at most ᵐ/ₙ objects. Grouping the n copies of the ᵐ/ₙ term here tells us that

m < ᵐ/ₙ + ᵐ/ₙ + ᵐ/ₙ + … + ᵐ/ₙ

= m.

But this means m < m, which is impossible. We’ve reached a contradiction, so our assumption was wrong, so if m objects are distributed into n bins and no bin has more than ᵐ/ₙ objects, no bin has fewer than ᵐ/ₙ objects either. ■

Page 192: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Lemma: If m objects are distributed into n bins and there are no binscontaining more than ᵐ/ₙ objects, then there are no bins containingfewer than ᵐ/ₙ objects.

Proof: Assume for the sake of contradiction that m objects are distributedinto n bins such that no bin contains more than ᵐ/ₙ objects, yet somebin has fewer than ᵐ/ₙ objects.

For simplicity, denote by xᵢ the number of objects in bin i. Without loss of generality, assume that bin 1 has fewer than ᵐ/ₙ objects, meaning that x₁ < ᵐ/ₙ. Adding up the number of objects in each bin tells us that

m = x₁ + x₂ + x₃ + … + xₙ

< ᵐ/ₙ + x₂ + x₃ + … + xₙ

≤ ᵐ/ₙ + ᵐ/ₙ + ᵐ/ₙ + … + ᵐ/ₙ.

This third step follows because each remaining bin has at most ᵐ/ₙ objects. Grouping the n copies of the ᵐ/ₙ term here tells us that

m < ᵐ/ₙ + ᵐ/ₙ + ᵐ/ₙ + … + ᵐ/ₙ

= m.

But this means m < m, which is impossible. We’ve reached a contradiction, so our assumption was wrong, so if m objects are distributed into n bins and no bin has more than ᵐ/ₙ objects, no bin has fewer than ᵐ/ₙ objects either. ■

Page 193: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Lemma: If m objects are distributed into n bins and there are no binscontaining more than ᵐ/ₙ objects, then there are no bins containingfewer than ᵐ/ₙ objects.

Proof: Assume for the sake of contradiction that m objects are distributedinto n bins such that no bin contains more than ᵐ/ₙ objects, yet somebin has fewer than ᵐ/ₙ objects.

For simplicity, denote by xᵢ the number of objects in bin i. Without loss of generality, assume that bin 1 has fewer than ᵐ/ₙ objects, meaning that x₁ < ᵐ/ₙ. Adding up the number of objects in each bin tells us that

m = x₁ + x₂ + x₃ + … + xₙ

< ᵐ/ₙ + x₂ + x₃ + … + xₙ

≤ ᵐ/ₙ + ᵐ/ₙ + ᵐ/ₙ + … + ᵐ/ₙ.

This third step follows because each remaining bin has at most ᵐ/ₙ objects. Grouping the n copies of the ᵐ/ₙ term here tells us that

m < ᵐ/ₙ + ᵐ/ₙ + ᵐ/ₙ + … + ᵐ/ₙ

= m.

But this means m < m, which is impossible. We’ve reached a contradiction, so our assumption was wrong, so if m objects are distributed into n bins and no bin has more than ᵐ/ₙ objects, no bin has fewer than ᵐ/ₙ objects either. ■

Page 194: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Lemma: If m objects are distributed into n bins and there are no binscontaining more than ᵐ/ₙ objects, then there are no bins containingfewer than ᵐ/ₙ objects.

Proof: Assume for the sake of contradiction that m objects are distributedinto n bins such that no bin contains more than ᵐ/ₙ objects, yet somebin has fewer than ᵐ/ₙ objects.

For simplicity, denote by xᵢ the number of objects in bin i. Without loss of generality, assume that bin 1 has fewer than ᵐ/ₙ objects, meaning that x₁ < ᵐ/ₙ. Adding up the number of objects in each bin tells us that

m = x₁ + x₂ + x₃ + … + xₙ

< ᵐ/ₙ + x₂ + x₃ + … + xₙ

≤ ᵐ/ₙ + ᵐ/ₙ + ᵐ/ₙ + … + ᵐ/ₙ.

This third step follows because each remaining bin has at most ᵐ/ₙ objects. Grouping the n copies of the ᵐ/ₙ term here tells us that

m < ᵐ/ₙ + ᵐ/ₙ + ᵐ/ₙ + … + ᵐ/ₙ

= m.

But this means m < m, which is impossible. We’ve reached a contradiction, so our assumption was wrong, so if m objects are distributed into n bins and no bin has more than ᵐ/ₙ objects, no bin has fewer than ᵐ/ₙ objects either. ■

Page 195: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Lemma: If m objects are distributed into n bins and there are no binscontaining more than ᵐ/ₙ objects, then there are no bins containingfewer than ᵐ/ₙ objects.

Proof: Assume for the sake of contradiction that m objects are distributedinto n bins such that no bin contains more than ᵐ/ₙ objects, yet somebin has fewer than ᵐ/ₙ objects.

For simplicity, denote by xᵢ the number of objects in bin i. Without loss of generality, assume that bin 1 has fewer than ᵐ/ₙ objects, meaning that x₁ < ᵐ/ₙ. Adding up the number of objects in each bin tells us that

m = x₁ + x₂ + x₃ + … + xₙ

< ᵐ/ₙ + x₂ + x₃ + … + xₙ

≤ ᵐ/ₙ + ᵐ/ₙ + ᵐ/ₙ + … + ᵐ/ₙ.

This third step follows because each remaining bin has at most ᵐ/ₙ objects. Grouping the n copies of the ᵐ/ₙ term here tells us that

m < ᵐ/ₙ + ᵐ/ₙ + ᵐ/ₙ + … + ᵐ/ₙ

= m.

But this means m < m, which is impossible. We’ve reached a contradiction, so our assumption was wrong, so if m objects are distributed into n bins and no bin has more than ᵐ/ₙ objects, no bin has fewer than ᵐ/ₙ objects either. ■

Page 196: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Lemma: If m objects are distributed into n bins and there are no binscontaining more than ᵐ/ₙ objects, then there are no bins containingfewer than ᵐ/ₙ objects.

Proof: Assume for the sake of contradiction that m objects are distributedinto n bins such that no bin contains more than ᵐ/ₙ objects, yet somebin has fewer than ᵐ/ₙ objects.

For simplicity, denote by xᵢ the number of objects in bin i. Without loss of generality, assume that bin 1 has fewer than ᵐ/ₙ objects, meaning that x₁ < ᵐ/ₙ. Adding up the number of objects in each bin tells us that

m = x₁ + x₂ + x₃ + … + xₙ

< ᵐ/ₙ + x₂ + x₃ + … + xₙ

≤ ᵐ/ₙ + ᵐ/ₙ + ᵐ/ₙ + … + ᵐ/ₙ.

This third step follows because each remaining bin has at most ᵐ/ₙ objects. Grouping the n copies of the ᵐ/ₙ term here tells us that

m < ᵐ/ₙ + ᵐ/ₙ + ᵐ/ₙ + … + ᵐ/ₙ

= m.

But this means m < m, which is impossible. We’ve reached a contradiction, so our assumption was wrong, so if m objects are distributed into n bins and no bin has more than ᵐ/ₙ objects, no bin has fewer than ᵐ/ₙ objects either. ■

Page 197: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

“In a group of n > 0 people …

· 90% of those people enjoyed Get Out, · 80% of those people enjoyed Lady Bird, · 70% of those people enjoyed Arrival, and · 60% of those people enjoyed Zootopia.

No one enjoyed all four movies. How many people enjoyed at least one of Get Out and Arrival?”

“In a group of n > 0 people …

· 90% of those people enjoyed Get Out, · 80% of those people enjoyed Lady Bird, · 70% of those people enjoyed Arrival, and · 60% of those people enjoyed Zootopia.

No one enjoyed all four movies. How many people enjoyed at least one of Get Out and Arrival?”

Georgia Michaun Anna Eva

GL

Z

A Z AG G

ZL

Insight 1: Model movie preferences as balls (movies) in bins

(people).

Insight 1: Model movie preferences as balls (movies) in bins

(people).

Insight 2: There are n total bins, one for each

person.

Insight 2: There are n total bins, one for each

person.

Page 198: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

“In a group of n > 0 people …

· 90% of those people enjoyed Get Out, · 80% of those people enjoyed Lady Bird, · 70% of those people enjoyed Arrival, and · 60% of those people enjoyed Zootopia.

No one enjoyed all four movies. How many people enjoyed at least one of Get Out and Arrival?”

“In a group of n > 0 people …

· 90% of those people enjoyed Get Out, · 80% of those people enjoyed Lady Bird, · 70% of those people enjoyed Arrival, and · 60% of those people enjoyed Zootopia.

No one enjoyed all four movies. How many people enjoyed at least one of Get Out and Arrival?”

.9n + .8n + .7n + .6n= 3n

Insight 3: There are 3n balls being

distributed into n bins.

Insight 3: There are 3n balls being

distributed into n bins.

Insight 4: The average number of balls in

each bin is 3.

Insight 4: The average number of balls in

each bin is 3.

Page 199: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

“In a group of n > 0 people …

· 90% of those people enjoyed Get Out, · 80% of those people enjoyed Lady Bird, · 70% of those people enjoyed Arrival, and · 60% of those people enjoyed Zootopia.

No one enjoyed all four movies. How many people enjoyed at least one of Get Out and Arrival?”

“In a group of n > 0 people …

· 90% of those people enjoyed Get Out, · 80% of those people enjoyed Lady Bird, · 70% of those people enjoyed Arrival, and · 60% of those people enjoyed Zootopia.

No one enjoyed all four movies. How many people enjoyed at least one of Get Out and Arrival?”

Insight 5: No one enjoyed more than

three movies…

Insight 5: No one enjoyed more than

three movies…

Insight 6: … so no one enjoyed fewer than

three movies …

Insight 6: … so no one enjoyed fewer than

three movies …

Insight 7: … so everyone enjoyed

exactly three movies.

Insight 7: … so everyone enjoyed

exactly three movies.

Page 200: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

“In a group of n > 0 people …

· 90% of those people enjoyed Get Out, · 80% of those people enjoyed Lady Bird, · 70% of those people enjoyed Arrival, and · 60% of those people enjoyed Zootopia.

No one enjoyed all four movies. How many people enjoyed at least one of Get Out and Arrival?”

“In a group of n > 0 people …

· 90% of those people enjoyed Get Out, · 80% of those people enjoyed Lady Bird, · 70% of those people enjoyed Arrival, and · 60% of those people enjoyed Zootopia.

No one enjoyed all four movies. How many people enjoyed at least one of Get Out and Arrival?”

Insight 8: You have to enjoy at least one of these movies to enjoy three of the four

movies.

Insight 8: You have to enjoy at least one of these movies to enjoy three of the four

movies.

Conclusion: Everyone liked at least one of these two movies!

Conclusion: Everyone liked at least one of these two movies!

Page 201: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Theorem: In the scenario described here, all n people enjoyed at leastone of Get Out and Arrival.

Proof: Suppose there is a group of n people meeting these criteria. We can model this problem by representing each person as a bin andeach time a person enjoys a movie as a ball. The number of balls is

.9n + .8n + .7n + .6n = 3n,

and since there are n people, there are n bins. Since no person liked all four movies, no bin contains more than 3 = ³ⁿ/ₙ balls, so by our earlier theorem we see that no bin contains fewer than three balls. Therefore, each bin contains exactly three balls.

Now suppose for the sake of contradiction that someone didn’t enjoy Get Out and didn’t enjoy Arrival. This means they could enjoy at most two of the four movies, contradicting that each person enjoys exactly three.

We’ve reached acontradiction, so ourassumption waswrong and eachperson enjoyed atleast one of Get Outand Arrival. ■

“In a group of n > 0 people …

· 90% of those people enjoyed Get Out, · 80% of those people enjoyed Lady Bird, · 70% of those people enjoyed Arrival, and · 60% of those people enjoyed Zootopia.

No one enjoyed all four movies. How many people enjoyed at least one of Get Out and Arrival?”

“In a group of n > 0 people …

· 90% of those people enjoyed Get Out, · 80% of those people enjoyed Lady Bird, · 70% of those people enjoyed Arrival, and · 60% of those people enjoyed Zootopia.

No one enjoyed all four movies. How many people enjoyed at least one of Get Out and Arrival?”

Page 202: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Theorem: In the scenario described here, all n people enjoyed at leastone of Get Out and Arrival.

Proof: Suppose there is a group of n people meeting these criteria. We can model this problem by representing each person as a bin andeach time a person enjoys a movie as a ball. The number of balls is

.9n + .8n + .7n + .6n = 3n,

and since there are n people, there are n bins. Since no person liked all four movies, no bin contains more than 3 = ³ⁿ/ₙ balls, so by our earlier theorem we see that no bin contains fewer than three balls. Therefore, each bin contains exactly three balls.

Now suppose for the sake of contradiction that someone didn’t enjoy Get Out and didn’t enjoy Arrival. This means they could enjoy at most two of the four movies, contradicting that each person enjoys exactly three.

We’ve reached acontradiction, so ourassumption waswrong and eachperson enjoyed atleast one of Get Outand Arrival. ■

“In a group of n > 0 people …

· 90% of those people enjoyed Get Out, · 80% of those people enjoyed Lady Bird, · 70% of those people enjoyed Arrival, and · 60% of those people enjoyed Zootopia.

No one enjoyed all four movies. How many people enjoyed at least one of Get Out and Arrival?”

“In a group of n > 0 people …

· 90% of those people enjoyed Get Out, · 80% of those people enjoyed Lady Bird, · 70% of those people enjoyed Arrival, and · 60% of those people enjoyed Zootopia.

No one enjoyed all four movies. How many people enjoyed at least one of Get Out and Arrival?”

Page 203: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Theorem: In the scenario described here, all n people enjoyed at leastone of Get Out and Arrival.

Proof: Suppose there is a group of n people meeting these criteria. We can model this problem by representing each person as a bin andeach time a person enjoys a movie as a ball. The number of balls is

.9n + .8n + .7n + .6n = 3n,

and since there are n people, there are n bins. Since no person liked all four movies, no bin contains more than 3 = ³ⁿ/ₙ balls, so by our earlier theorem we see that no bin contains fewer than three balls. Therefore, each bin contains exactly three balls.

Now suppose for the sake of contradiction that someone didn’t enjoy Get Out and didn’t enjoy Arrival. This means they could enjoy at most two of the four movies, contradicting that each person enjoys exactly three.

We’ve reached acontradiction, so ourassumption waswrong and eachperson enjoyed atleast one of Get Outand Arrival. ■

“In a group of n > 0 people …

· 90% of those people enjoyed Get Out, · 80% of those people enjoyed Lady Bird, · 70% of those people enjoyed Arrival, and · 60% of those people enjoyed Zootopia.

No one enjoyed all four movies. How many people enjoyed at least one of Get Out and Arrival?”

“In a group of n > 0 people …

· 90% of those people enjoyed Get Out, · 80% of those people enjoyed Lady Bird, · 70% of those people enjoyed Arrival, and · 60% of those people enjoyed Zootopia.

No one enjoyed all four movies. How many people enjoyed at least one of Get Out and Arrival?”

Page 204: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Theorem: In the scenario described here, all n people enjoyed at leastone of Get Out and Arrival.

Proof: Suppose there is a group of n people meeting these criteria. We can model this problem by representing each person as a bin andeach time a person enjoys a movie as a ball. The number of balls is

.9n + .8n + .7n + .6n = 3n,

and since there are n people, there are n bins. Since no person liked all four movies, no bin contains more than 3 = ³ⁿ/ₙ balls, so by our earlier theorem we see that no bin contains fewer than three balls. Therefore, each bin contains exactly three balls.

Now suppose for the sake of contradiction that someone didn’t enjoy Get Out and didn’t enjoy Arrival. This means they could enjoy at most two of the four movies, contradicting that each person enjoys exactly three.

We’ve reached acontradiction, so ourassumption waswrong and eachperson enjoyed atleast one of Get Outand Arrival. ■

“In a group of n > 0 people …

· 90% of those people enjoyed Get Out, · 80% of those people enjoyed Lady Bird, · 70% of those people enjoyed Arrival, and · 60% of those people enjoyed Zootopia.

No one enjoyed all four movies. How many people enjoyed at least one of Get Out and Arrival?”

“In a group of n > 0 people …

· 90% of those people enjoyed Get Out, · 80% of those people enjoyed Lady Bird, · 70% of those people enjoyed Arrival, and · 60% of those people enjoyed Zootopia.

No one enjoyed all four movies. How many people enjoyed at least one of Get Out and Arrival?”

Page 205: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Theorem: In the scenario described here, all n people enjoyed at leastone of Get Out and Arrival.

Proof: Suppose there is a group of n people meeting these criteria. We can model this problem by representing each person as a bin andeach time a person enjoys a movie as a ball. The number of balls is

.9n + .8n + .7n + .6n = 3n,

and since there are n people, there are n bins. Since no person liked all four movies, no bin contains more than 3 = ³ⁿ/ₙ balls, so by our earlier theorem we see that no bin contains fewer than three balls. Therefore, each bin contains exactly three balls.

Now suppose for the sake of contradiction that someone didn’t enjoy Get Out and didn’t enjoy Arrival. This means they could enjoy at most two of the four movies, contradicting that each person enjoys exactly three.

We’ve reached acontradiction, so ourassumption waswrong and eachperson enjoyed atleast one of Get Outand Arrival. ■

“In a group of n > 0 people …

· 90% of those people enjoyed Get Out, · 80% of those people enjoyed Lady Bird, · 70% of those people enjoyed Arrival, and · 60% of those people enjoyed Zootopia.

No one enjoyed all four movies. How many people enjoyed at least one of Get Out and Arrival?”

“In a group of n > 0 people …

· 90% of those people enjoyed Get Out, · 80% of those people enjoyed Lady Bird, · 70% of those people enjoyed Arrival, and · 60% of those people enjoyed Zootopia.

No one enjoyed all four movies. How many people enjoyed at least one of Get Out and Arrival?”

Page 206: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Theorem: In the scenario described here, all n people enjoyed at leastone of Get Out and Arrival.

Proof: Suppose there is a group of n people meeting these criteria. We can model this problem by representing each person as a bin andeach time a person enjoys a movie as a ball. The number of balls is

.9n + .8n + .7n + .6n = 3n,

and since there are n people, there are n bins. Since no person liked all four movies, no bin contains more than 3 = ³ⁿ/ₙ balls, so by our earlier theorem we see that no bin contains fewer than three balls. Therefore, each bin contains exactly three balls.

Now suppose for the sake of contradiction that someone didn’t enjoy Get Out and didn’t enjoy Arrival. This means they could enjoy at most two of the four movies, contradicting that each person enjoys exactly three.

We’ve reached acontradiction, so ourassumption waswrong and eachperson enjoyed atleast one of Get Outand Arrival. ■

“In a group of n > 0 people …

· 90% of those people enjoyed Get Out, · 80% of those people enjoyed Lady Bird, · 70% of those people enjoyed Arrival, and · 60% of those people enjoyed Zootopia.

No one enjoyed all four movies. How many people enjoyed at least one of Get Out and Arrival?”

“In a group of n > 0 people …

· 90% of those people enjoyed Get Out, · 80% of those people enjoyed Lady Bird, · 70% of those people enjoyed Arrival, and · 60% of those people enjoyed Zootopia.

No one enjoyed all four movies. How many people enjoyed at least one of Get Out and Arrival?”

Page 207: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Theorem: In the scenario described here, all n people enjoyed at leastone of Get Out and Arrival.

Proof: Suppose there is a group of n people meeting these criteria. We can model this problem by representing each person as a bin andeach time a person enjoys a movie as a ball. The number of balls is

.9n + .8n + .7n + .6n = 3n,

and since there are n people, there are n bins. Since no person liked all four movies, no bin contains more than 3 = ³ⁿ/ₙ balls, so by our earlier theorem we see that no bin contains fewer than three balls. Therefore, each bin contains exactly three balls.

Now suppose for the sake of contradiction that someone didn’t enjoy Get Out and didn’t enjoy Arrival. This means they could enjoy at most two of the four movies, contradicting that each person enjoys exactly three.

We’ve reached acontradiction, so ourassumption waswrong and eachperson enjoyed atleast one of Get Outand Arrival. ■

“In a group of n > 0 people …

· 90% of those people enjoyed Get Out, · 80% of those people enjoyed Lady Bird, · 70% of those people enjoyed Arrival, and · 60% of those people enjoyed Zootopia.

No one enjoyed all four movies. How many people enjoyed at least one of Get Out and Arrival?”

“In a group of n > 0 people …

· 90% of those people enjoyed Get Out, · 80% of those people enjoyed Lady Bird, · 70% of those people enjoyed Arrival, and · 60% of those people enjoyed Zootopia.

No one enjoyed all four movies. How many people enjoyed at least one of Get Out and Arrival?”

Page 208: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Theorem: In the scenario described here, all n people enjoyed at leastone of Get Out and Arrival.

Proof: Suppose there is a group of n people meeting these criteria. We can model this problem by representing each person as a bin andeach time a person enjoys a movie as a ball. The number of balls is

.9n + .8n + .7n + .6n = 3n,

and since there are n people, there are n bins. Since no person liked all four movies, no bin contains more than 3 = ³ⁿ/ₙ balls, so by our earlier theorem we see that no bin contains fewer than three balls. Therefore, each bin contains exactly three balls.

Now suppose for the sake of contradiction that someone didn’t enjoy Get Out and didn’t enjoy Arrival. This means they could enjoy at most two of the four movies, contradicting that each person enjoys exactly three.

We’ve reached acontradiction, so ourassumption waswrong and eachperson enjoyed atleast one of Get Outand Arrival. ■

“In a group of n > 0 people …

· 90% of those people enjoyed Get Out, · 80% of those people enjoyed Lady Bird, · 70% of those people enjoyed Arrival, and · 60% of those people enjoyed Zootopia.

No one enjoyed all four movies. How many people enjoyed at least one of Get Out and Arrival?”

“In a group of n > 0 people …

· 90% of those people enjoyed Get Out, · 80% of those people enjoyed Lady Bird, · 70% of those people enjoyed Arrival, and · 60% of those people enjoyed Zootopia.

No one enjoyed all four movies. How many people enjoyed at least one of Get Out and Arrival?”

Page 209: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Theorem: In the scenario described here, all n people enjoyed at leastone of Get Out and Arrival.

Proof: Suppose there is a group of n people meeting these criteria. We can model this problem by representing each person as a bin andeach time a person enjoys a movie as a ball. The number of balls is

.9n + .8n + .7n + .6n = 3n,

and since there are n people, there are n bins. Since no person liked all four movies, no bin contains more than 3 = ³ⁿ/ₙ balls, so by our earlier theorem we see that no bin contains fewer than three balls. Therefore, each bin contains exactly three balls.

Now suppose for the sake of contradiction that someone didn’t enjoy Get Out and didn’t enjoy Arrival. This means they could enjoy at most two of the four movies, contradicting that each person enjoys exactly three.

We’ve reached acontradiction, so ourassumption waswrong and eachperson enjoyed atleast one of Get Outand Arrival. ■

“In a group of n > 0 people …

· 90% of those people enjoyed Get Out, · 80% of those people enjoyed Lady Bird, · 70% of those people enjoyed Arrival, and · 60% of those people enjoyed Zootopia.

No one enjoyed all four movies. How many people enjoyed at least one of Get Out and Arrival?”

“In a group of n > 0 people …

· 90% of those people enjoyed Get Out, · 80% of those people enjoyed Lady Bird, · 70% of those people enjoyed Arrival, and · 60% of those people enjoyed Zootopia.

No one enjoyed all four movies. How many people enjoyed at least one of Get Out and Arrival?”

Page 210: Graph Theory - Stanford Universityweb.stanford.edu/class/archive/cs/cs103/cs103.1198...SD Nog Port SLC LA But Mon LV Bar Flag Phoe SF Sac Sea F r o m To A path in a graph G = (V, E)

Going Further

● The pigeonhole principle can be used to prove a ton of amazing theorems. Here’s a sampler:● There is always a way to fairly split rent among multiple people,

even if diferent people want diferent rooms. (Sperner’s lemma)● You and a friend can climb any mountain from two diferent

starting points so that the two of you maintain the same altitude at each point in time. (Mountain-climbing theorem)

● If you model cofee in a cup as a collection of infnitely many points and then stir the cofee, some point is always where it initially started. (Brower’s fxed-point theorem)

● A complex process that doesn’t parallelize well must contain a large serial subprocess. (Mirksy’s theorem)

● Any positive integer n has a nonzero multiple that can be written purely using the digits 1 and 0. (Doesn’t have a name, but still cool!)