discrete mathematics - graphs

302
Discrete Mathematics Graphs H. Turgut Uyar Ay¸ seg¨ ul Gen¸ cata Yayımlı Emre Harmancı 2001-2013

Upload: turgut-uyar

Post on 28-Nov-2014

16.853 views

Category:

Education


4 download

DESCRIPTION

Graphs, digraphs, isomorphism, connectivity, traversable graphs, planar graphs. Trees, rooted trees, binary trees, decision trees. Weighted graphs, shortest path, miminum spanning tree.

TRANSCRIPT

Page 1: Discrete Mathematics - Graphs

Discrete MathematicsGraphs

H. Turgut Uyar Aysegul Gencata Yayımlı Emre Harmancı

2001-2013

Page 2: Discrete Mathematics - Graphs

License

c©2001-2013 T. Uyar, A. Yayımlı, E. Harmancı

You are free:

to Share – to copy, distribute and transmit the work

to Remix – to adapt the work

Under the following conditions:

Attribution – You must attribute the work in the manner specified by the author or licensor (but not in anyway that suggests that they endorse you or your use of the work).

Noncommercial – You may not use this work for commercial purposes.

Share Alike – If you alter, transform, or build upon this work, you may distribute the resulting work onlyunder the same or similar license to this one.

Legal code (the full license):http://creativecommons.org/licenses/by-nc-sa/3.0/

Page 3: Discrete Mathematics - Graphs

Topics

1 GraphsIntroductionConnectivityPlanar GraphsSearching Graphs

2 TreesIntroductionRooted TreesBinary TreesDecision Trees

3 Weighted GraphsIntroductionShortest PathMinimum Spanning Tree

Page 4: Discrete Mathematics - Graphs

Topics

1 GraphsIntroductionConnectivityPlanar GraphsSearching Graphs

2 TreesIntroductionRooted TreesBinary TreesDecision Trees

3 Weighted GraphsIntroductionShortest PathMinimum Spanning Tree

Page 5: Discrete Mathematics - Graphs

Graphs

Definition

graph: G = (V ,E )

V : node (or vertex) set

E ⊆ V × V : edge set

if e = (v1, v2) ∈ E :

v1 and v2 are endnodes of ee is incident to v1 and v2

v1 and v2 are adjacent

node with no incident edge: isolated node

Page 6: Discrete Mathematics - Graphs

Graphs

Definition

graph: G = (V ,E )

V : node (or vertex) set

E ⊆ V × V : edge set

if e = (v1, v2) ∈ E :

v1 and v2 are endnodes of ee is incident to v1 and v2

v1 and v2 are adjacent

node with no incident edge: isolated node

Page 7: Discrete Mathematics - Graphs

Graph Example

Example

V = {a, b, c, d , e, f }E = {(a, b), (a, c),

(a, d), (a, e),(a, f ), (b, c),(d , e), (e, f )}

Page 8: Discrete Mathematics - Graphs

Directed Graphs

Definition

directed graph (or digraph): D = (V ,A)

A ⊆ V × V : arc set

origin and terminating nodes

Page 9: Discrete Mathematics - Graphs

Directed Graph Example

Example

Page 10: Discrete Mathematics - Graphs

Multigraphs

Definition

parallel edges: edges between the same pair of nodes

loop: an edge starting and ending in the same node

plain graph: a graph without any loops or parallel edges

multigraph: a graph which is not plain

Page 11: Discrete Mathematics - Graphs

Multigraphs

Definition

parallel edges: edges between the same pair of nodes

loop: an edge starting and ending in the same node

plain graph: a graph without any loops or parallel edges

multigraph: a graph which is not plain

Page 12: Discrete Mathematics - Graphs

Multigraph Example

Example

parallel edges:(a, b)

loop:(e, e)

Page 13: Discrete Mathematics - Graphs

Subgraph

Definition

G ′ = (V ′,E ′) is a subgraph of G = (V ,E ):

V ′ ⊆ V

E ′ ⊆ E

∀(v1, v2) ∈ E ′ v1, v2 ∈ V ′

Page 14: Discrete Mathematics - Graphs

Representation

incidence matrix:

rows represent nodes, columns represent edgescell: 1 if the edge is incident to the node, 0 otherwise

adjacency matrix:

rows and columns represent nodescells represent the number of edges between the nodes

Page 15: Discrete Mathematics - Graphs

Representation

incidence matrix:

rows represent nodes, columns represent edgescell: 1 if the edge is incident to the node, 0 otherwise

adjacency matrix:

rows and columns represent nodescells represent the number of edges between the nodes

Page 16: Discrete Mathematics - Graphs

Incidence Matrix Example

Example

e1 e2 e3 e4 e5 e6 e7 e8

v1 1 1 1 0 1 0 0 0v2 1 0 0 1 0 0 0 0v3 0 0 1 1 0 0 1 1v4 0 0 0 0 1 1 0 1v5 0 1 0 0 0 1 1 0

Page 17: Discrete Mathematics - Graphs

Adjacency Matrix Example

Example

v1 v2 v3 v4 v5

v1 0 1 1 1 1v2 1 0 1 0 0v3 1 1 0 1 1v4 1 0 1 0 1v5 1 0 1 1 0

Page 18: Discrete Mathematics - Graphs

Adjacency Matrix Example

Example

a b c d

a 0 0 0 1b 2 1 1 0c 0 0 0 0d 0 1 1 0

Page 19: Discrete Mathematics - Graphs

Degree

Definition

degree: number of edges incident to the node

Theorem

let di be the degree of node vi

|E | =∑

i di

2

Page 20: Discrete Mathematics - Graphs

Degree

Definition

degree: number of edges incident to the node

Theorem

let di be the degree of node vi

|E | =∑

i di

2

Page 21: Discrete Mathematics - Graphs

Degree Example

Example (plain graph)

da = 5db = 2dc = 2dd = 2de = 3df = 2

Total = 16

|E | = 8

Page 22: Discrete Mathematics - Graphs

Degree Example

Example (multigraph)

da = 6db = 3dc = 2dd = 2de = 5df = 2

Total = 20

|E | = 10

Page 23: Discrete Mathematics - Graphs

Degree in Directed Graphs

two types of degree

in-degree: dvi

out-degree: dvo

node with in-degree 0: source

node with out-degree 0: sink∑v∈V dv

i =∑

v∈V dvo = |A|

Page 24: Discrete Mathematics - Graphs

Degree in Directed Graphs

two types of degree

in-degree: dvi

out-degree: dvo

node with in-degree 0: source

node with out-degree 0: sink∑v∈V dv

i =∑

v∈V dvo = |A|

Page 25: Discrete Mathematics - Graphs

Degree in Directed Graphs

two types of degree

in-degree: dvi

out-degree: dvo

node with in-degree 0: source

node with out-degree 0: sink∑v∈V dv

i =∑

v∈V dvo = |A|

Page 26: Discrete Mathematics - Graphs

Degree

Theorem

In an undirected graph, there is an even number of nodeswhich have an odd degree.

Proof.

ti : number of nodes of degree i2|E | =

∑i di = 1t1 + 2t2 + 3t3 + 4t4 + 5t5 + . . .

2|E | − 2t2 − 4t4 − · · · = t1 + t3 + · · ·+ 2t3 + 4t5 + . . .2|E | − 2t2 − 4t4 − · · · − 2t3 − 4t5 − · · · = t1 + t3 + t5 + . . .

since the left-hand side is even, the right-hand side is also even

Page 27: Discrete Mathematics - Graphs

Degree

Theorem

In an undirected graph, there is an even number of nodeswhich have an odd degree.

Proof.

ti : number of nodes of degree i2|E | =

∑i di = 1t1 + 2t2 + 3t3 + 4t4 + 5t5 + . . .

2|E | − 2t2 − 4t4 − · · · = t1 + t3 + · · ·+ 2t3 + 4t5 + . . .2|E | − 2t2 − 4t4 − · · · − 2t3 − 4t5 − · · · = t1 + t3 + t5 + . . .

since the left-hand side is even, the right-hand side is also even

Page 28: Discrete Mathematics - Graphs

Degree

Theorem

In an undirected graph, there is an even number of nodeswhich have an odd degree.

Proof.

ti : number of nodes of degree i2|E | =

∑i di = 1t1 + 2t2 + 3t3 + 4t4 + 5t5 + . . .

2|E | − 2t2 − 4t4 − · · · = t1 + t3 + · · ·+ 2t3 + 4t5 + . . .2|E | − 2t2 − 4t4 − · · · − 2t3 − 4t5 − · · · = t1 + t3 + t5 + . . .

since the left-hand side is even, the right-hand side is also even

Page 29: Discrete Mathematics - Graphs

Degree

Theorem

In an undirected graph, there is an even number of nodeswhich have an odd degree.

Proof.

ti : number of nodes of degree i2|E | =

∑i di = 1t1 + 2t2 + 3t3 + 4t4 + 5t5 + . . .

2|E | − 2t2 − 4t4 − · · · = t1 + t3 + · · ·+ 2t3 + 4t5 + . . .2|E | − 2t2 − 4t4 − · · · − 2t3 − 4t5 − · · · = t1 + t3 + t5 + . . .

since the left-hand side is even, the right-hand side is also even

Page 30: Discrete Mathematics - Graphs

Degree

Theorem

In an undirected graph, there is an even number of nodeswhich have an odd degree.

Proof.

ti : number of nodes of degree i2|E | =

∑i di = 1t1 + 2t2 + 3t3 + 4t4 + 5t5 + . . .

2|E | − 2t2 − 4t4 − · · · = t1 + t3 + · · ·+ 2t3 + 4t5 + . . .2|E | − 2t2 − 4t4 − · · · − 2t3 − 4t5 − · · · = t1 + t3 + t5 + . . .

since the left-hand side is even, the right-hand side is also even

Page 31: Discrete Mathematics - Graphs

Degree

Theorem

In an undirected graph, there is an even number of nodeswhich have an odd degree.

Proof.

ti : number of nodes of degree i2|E | =

∑i di = 1t1 + 2t2 + 3t3 + 4t4 + 5t5 + . . .

2|E | − 2t2 − 4t4 − · · · = t1 + t3 + · · ·+ 2t3 + 4t5 + . . .2|E | − 2t2 − 4t4 − · · · − 2t3 − 4t5 − · · · = t1 + t3 + t5 + . . .

since the left-hand side is even, the right-hand side is also even

Page 32: Discrete Mathematics - Graphs

Regular Graphs

Definition

regular graph: all nodes have the same degree

n-regular: all nodes have degree n

Page 33: Discrete Mathematics - Graphs

Regular Graph Examples

Example

Page 34: Discrete Mathematics - Graphs

Completely Connected Graphs

Definition

G = (V ,E ) is completely connected:

∀v1, v2 ∈ V (v1, v2) ∈ E

there is an edge between every pair of nodes

Kn: the completely connected graph with n nodes

Page 35: Discrete Mathematics - Graphs

Completely Connected Graphs

Definition

G = (V ,E ) is completely connected:

∀v1, v2 ∈ V (v1, v2) ∈ E

there is an edge between every pair of nodes

Kn: the completely connected graph with n nodes

Page 36: Discrete Mathematics - Graphs

Completely Connected Graph Examples

Example (K4)Example (K5)

Page 37: Discrete Mathematics - Graphs

Bipartite Graphs

Definition

G = (V ,E ) is bipartite:

∀(v1, v2) ∈ E v1 ∈ V1 ∧ v2 ∈ V2

V1 ∪ V2 = V , V1 ∩ V2 = ∅

complete bipartite: ∀v1 ∈ V1 ∀v2 ∈ V2 (v1, v2) ∈ E

Km,n: |V1| = m, |V2| = n

Page 38: Discrete Mathematics - Graphs

Bipartite Graphs

Definition

G = (V ,E ) is bipartite:

∀(v1, v2) ∈ E v1 ∈ V1 ∧ v2 ∈ V2

V1 ∪ V2 = V , V1 ∩ V2 = ∅

complete bipartite: ∀v1 ∈ V1 ∀v2 ∈ V2 (v1, v2) ∈ E

Km,n: |V1| = m, |V2| = n

Page 39: Discrete Mathematics - Graphs

Complete Bipartite Graph Examples

Example (K2,3) Example (K3,3)

Page 40: Discrete Mathematics - Graphs

Isomorphism

Definition

G = (V ,E ) and G ? = (V ?,E ?) are isomorphic:

∃f : V → V ? (u, v) ∈ E ⇒ (f (u), f (v)) ∈ E ?

f is bijective

G and G ? can be drawn the same way

Page 41: Discrete Mathematics - Graphs

Isomorphism

Definition

G = (V ,E ) and G ? = (V ?,E ?) are isomorphic:

∃f : V → V ? (u, v) ∈ E ⇒ (f (u), f (v)) ∈ E ?

f is bijective

G and G ? can be drawn the same way

Page 42: Discrete Mathematics - Graphs

Isomorphism Example

Example

f = {(a, d), (b, e), (c, b), (d , c), (e, a)}

Page 43: Discrete Mathematics - Graphs

Isomorphism Example

Example

f = {(a, d), (b, e), (c, b), (d , c), (e, a)}

Page 44: Discrete Mathematics - Graphs

Isomorphism Example

Example (Petersen graph)

f = {(a, q), (b, v), (c, u), (d , y), (e, r),(f ,w), (g , x), (h, t), (i , z), (j , s)}

Page 45: Discrete Mathematics - Graphs

Homeomorphism

Definition

G = (V ,E ) and G ? = (V ?,E ?) are homeomorphic:

G and G ? are isomorphic except thatsome edges in E ? are divided with additional nodes

Page 46: Discrete Mathematics - Graphs

Homeomorphism Example

Example

Page 47: Discrete Mathematics - Graphs

Topics

1 GraphsIntroductionConnectivityPlanar GraphsSearching Graphs

2 TreesIntroductionRooted TreesBinary TreesDecision Trees

3 Weighted GraphsIntroductionShortest PathMinimum Spanning Tree

Page 48: Discrete Mathematics - Graphs

Walk

Definition

walk: a sequence of nodes and edgesfrom a starting node (v0) to an ending node (vn)

v0, e1, v1, e2, v2, e3, v3, . . . , en−1, vn−1, en, vn

where ei = (vi−1, vi )

no need to write the edges

length: number of edges in the walk

if v0 6= vn open, if v0 = vn closed

Page 49: Discrete Mathematics - Graphs

Walk

Definition

walk: a sequence of nodes and edgesfrom a starting node (v0) to an ending node (vn)

v0, e1, v1, e2, v2, e3, v3, . . . , en−1, vn−1, en, vn

where ei = (vi−1, vi )

no need to write the edges

length: number of edges in the walk

if v0 6= vn open, if v0 = vn closed

Page 50: Discrete Mathematics - Graphs

Walk

Definition

walk: a sequence of nodes and edgesfrom a starting node (v0) to an ending node (vn)

v0, e1, v1, e2, v2, e3, v3, . . . , en−1, vn−1, en, vn

where ei = (vi−1, vi )

no need to write the edges

length: number of edges in the walk

if v0 6= vn open, if v0 = vn closed

Page 51: Discrete Mathematics - Graphs

Walk Example

Example

(c, b), (b, a), (a, d), (d , e),(e, f ), (f , a), (a, b)

c, b, a, d , e, f , a, b

length: 7

Page 52: Discrete Mathematics - Graphs

Trail

Definition

trail: a walk where edges are not repeated

circuit: closed trail

spanning trail: a trail that covers all the edges in the graph

Page 53: Discrete Mathematics - Graphs

Trail

Definition

trail: a walk where edges are not repeated

circuit: closed trail

spanning trail: a trail that covers all the edges in the graph

Page 54: Discrete Mathematics - Graphs

Trail Example

Example

(c, b), (b, a), (a, e), (e, d),(d , a), (a, f )

c, b, a, e, d , a, f

Page 55: Discrete Mathematics - Graphs

Path

Definition

path: a walk where nodes are not repeated

cycle: closed path

spanning path: a path that visits all the nodes in the graph

Page 56: Discrete Mathematics - Graphs

Path

Definition

path: a walk where nodes are not repeated

cycle: closed path

spanning path: a path that visits all the nodes in the graph

Page 57: Discrete Mathematics - Graphs

Path Example

Example

(c, b), (b, a), (a, d), (d , e),(e, f )

c, b, a, d , e, f

Page 58: Discrete Mathematics - Graphs

Connectivity

Definition

connected graph: there is a path between every pair of nodes

a disconnected graph can be dividedinto connected components

Page 59: Discrete Mathematics - Graphs

Connectivity

Definition

connected graph: there is a path between every pair of nodes

a disconnected graph can be dividedinto connected components

Page 60: Discrete Mathematics - Graphs

Connected Components Example

Example

graph is disconnected:no path between a and c

connected components:a, d , eb, cf

Page 61: Discrete Mathematics - Graphs

Distance

Definition

the distance between nodes vi and vj :

the length of the shortest path between vi and vj

Definition

diameter: the largest distance in the graph

Page 62: Discrete Mathematics - Graphs

Distance

Definition

the distance between nodes vi and vj :

the length of the shortest path between vi and vj

Definition

diameter: the largest distance in the graph

Page 63: Discrete Mathematics - Graphs

Distance Example

Example

distance between a and e: 2

diameter: 3

Page 64: Discrete Mathematics - Graphs

Distance Example

Example

distance between a and e: 2

diameter: 3

Page 65: Discrete Mathematics - Graphs

Cut-Point

Definition

G − v :

the graph obtained by deleting the node vand all its incident edges from the graph G

Definition

v is a cut-point for G :

G is connected but G − v is disconnected

Page 66: Discrete Mathematics - Graphs

Cut-Point

Definition

G − v :

the graph obtained by deleting the node vand all its incident edges from the graph G

Definition

v is a cut-point for G :

G is connected but G − v is disconnected

Page 67: Discrete Mathematics - Graphs

Cut-Point Example

G G − d

Page 68: Discrete Mathematics - Graphs

Directed Walks

same as in undirected graphs

ignoring the directions on the arcs:semi-walk, semi-trail, semi-path

Page 69: Discrete Mathematics - Graphs

Weakly Connected Graph

Definition

weakly connected:there is a semi-pathbetween every pair of nodes

Example

Page 70: Discrete Mathematics - Graphs

Unilaterally Connected Graph

Definition

unilaterally connected:for every pair of nodes, there isa path from one to the other

Example

Page 71: Discrete Mathematics - Graphs

Strongly Connected Graph

Definition

strongly connected:there is a path in both directionsbetween every pair of nodes

Example

Page 72: Discrete Mathematics - Graphs

Bridges of Konigsberg

cross each bridge exactly onceand return to the starting point

Page 73: Discrete Mathematics - Graphs

Traversable Graphs

Definition

G is traversable: G contains a spanning trail

Page 74: Discrete Mathematics - Graphs

Traversable Graphs

a node with an odd degree must be either the starting nodeor the ending node of the trail

all nodes except the starting node and the ending nodemust have even degrees

Page 75: Discrete Mathematics - Graphs

Traversable Graph Example

Example

degrees of a, b and c are even

degrees of d and e are odd

a spanning trail can be formedstarting from node d andending at node e (or vice versa):d , b, a, c, e, d , c, b, e

Page 76: Discrete Mathematics - Graphs

Traversable Graph Example

Example

degrees of a, b and c are even

degrees of d and e are odd

a spanning trail can be formedstarting from node d andending at node e (or vice versa):d , b, a, c, e, d , c, b, e

Page 77: Discrete Mathematics - Graphs

Bridges of Konigsberg

all node have odd degrees: not traversable

Page 78: Discrete Mathematics - Graphs

Euler Graphs

Definition

Euler graph: a graph that contains a closed spanning trail

G is an Euler graph ⇔ the degrees of all nodes in G are even

Page 79: Discrete Mathematics - Graphs

Euler Graph Examples

Example (Euler graph) Example (not an Euler graph)

Page 80: Discrete Mathematics - Graphs

Hamilton Graphs

Definition

Hamilton graph: a graph that contains a closed spanning path

Page 81: Discrete Mathematics - Graphs

Hamilton Graph Examples

Example (Hamilton graph) Example (not a Hamilton graph)

Page 82: Discrete Mathematics - Graphs

Connectivity Matrix

if the adjacency matrix of the graph is A,the (i , j) element of Ak shows the number of walks of length kbetween the nodes i and j

in an undirected graph with n nodes,the distance between two nodes is at most n − 1

connectivity matrix:C = A1 + A2 + A3 + · · ·+ An−1

if all elements are non-zero, then the graph is connected

Page 83: Discrete Mathematics - Graphs

Connectivity Matrix

if the adjacency matrix of the graph is A,the (i , j) element of Ak shows the number of walks of length kbetween the nodes i and j

in an undirected graph with n nodes,the distance between two nodes is at most n − 1

connectivity matrix:C = A1 + A2 + A3 + · · ·+ An−1

if all elements are non-zero, then the graph is connected

Page 84: Discrete Mathematics - Graphs

Connectivity Matrix

if the adjacency matrix of the graph is A,the (i , j) element of Ak shows the number of walks of length kbetween the nodes i and j

in an undirected graph with n nodes,the distance between two nodes is at most n − 1

connectivity matrix:C = A1 + A2 + A3 + · · ·+ An−1

if all elements are non-zero, then the graph is connected

Page 85: Discrete Mathematics - Graphs

Warshall’s Algorithm

it is easier to find whether there is a walk between two nodesinstead of finding the number of walks

for each node:

from all nodes which can reach the chosen node(the rows that contain 1 in the chosen column)to the nodes which can be reached from the chosen node(the columns that contain 1 in the chosen row)

Page 86: Discrete Mathematics - Graphs

Warshall’s Algorithm

it is easier to find whether there is a walk between two nodesinstead of finding the number of walks

for each node:

from all nodes which can reach the chosen node(the rows that contain 1 in the chosen column)to the nodes which can be reached from the chosen node(the columns that contain 1 in the chosen row)

Page 87: Discrete Mathematics - Graphs

Warshall’s Algorithm Example

Example

a b c d

a 0 1 0 0b 0 1 0 0c 0 0 0 1d 1 0 1 0

Page 88: Discrete Mathematics - Graphs

Warshall’s Algorithm Example

Example

a b c d

a 0 1 0 0b 0 1 0 0c 0 0 0 1d 1 1 1 0

Page 89: Discrete Mathematics - Graphs

Warshall’s Algorithm Example

Example

a b c d

a 0 1 0 0b 0 1 0 0c 0 0 0 1d 1 1 1 0

Page 90: Discrete Mathematics - Graphs

Warshall’s Algorithm Example

Example

a b c d

a 0 1 0 0b 0 1 0 0c 0 0 0 1d 1 1 1 1

Page 91: Discrete Mathematics - Graphs

Warshall’s Algorithm Example

Example

a b c d

a 0 1 0 0b 0 1 0 0c 1 1 1 1d 1 1 1 1

Page 92: Discrete Mathematics - Graphs

Topics

1 GraphsIntroductionConnectivityPlanar GraphsSearching Graphs

2 TreesIntroductionRooted TreesBinary TreesDecision Trees

3 Weighted GraphsIntroductionShortest PathMinimum Spanning Tree

Page 93: Discrete Mathematics - Graphs

Planar Graphs

Definition

A graph is planar if it can be drawn on a planewithout intersecting its edges.

a map of G : a planar drawing of G

Page 94: Discrete Mathematics - Graphs

Planar Graph Example

Example (K4)

Page 95: Discrete Mathematics - Graphs

Regions

a map divides the plane into regions

the degree of a region:the length of the closed trail that surrounds the region

Theorem

let dri be the degree of region ri

|E | =∑

i dri

2

Page 96: Discrete Mathematics - Graphs

Regions

a map divides the plane into regions

the degree of a region:the length of the closed trail that surrounds the region

Theorem

let dri be the degree of region ri

|E | =∑

i dri

2

Page 97: Discrete Mathematics - Graphs

Region Example

Example

dr1 = 3 (abda)dr2 = 3 (bcdb)dr3 = 5 (cdefec)dr4 = 4 (abcea)dr5 = 3 (adea)∑

r dr = 18|E | = 9

Page 98: Discrete Mathematics - Graphs

Euler’s Formula

Theorem (Euler’s Formula)

Let G = (V ,E ) be a planar, connected graphand let R be the set of regions in a map of G:

|V | − |E |+ |R| = 2

Page 99: Discrete Mathematics - Graphs

Euler’s Formula Example

Example

|V | = 6, |E | = 9, |R| = 5

Page 100: Discrete Mathematics - Graphs

Planar Graph Theorems

Theorem

Let G = (V ,E ) be a connected, planar graph where |V | ≥ 3:|E | ≤ 3|V | − 6

Proof.

the sum of region degrees: 2|E |degree of a region is at least 3⇒ 2|E | ≥ 3|R| ⇒ |R| ≤ 2

3 |E ||V | − |E |+ |R| = 2⇒ |V | − |E |+ 2

3 |E | ≥ 2 ⇒ |V | − 13 |E | ≥ 2

⇒ 3|V | − |E | ≥ 6 ⇒ |E | ≤ 3|V | − 6

Page 101: Discrete Mathematics - Graphs

Planar Graph Theorems

Theorem

Let G = (V ,E ) be a connected, planar graph where |V | ≥ 3:|E | ≤ 3|V | − 6

Proof.

the sum of region degrees: 2|E |degree of a region is at least 3⇒ 2|E | ≥ 3|R| ⇒ |R| ≤ 2

3 |E ||V | − |E |+ |R| = 2⇒ |V | − |E |+ 2

3 |E | ≥ 2 ⇒ |V | − 13 |E | ≥ 2

⇒ 3|V | − |E | ≥ 6 ⇒ |E | ≤ 3|V | − 6

Page 102: Discrete Mathematics - Graphs

Planar Graph Theorems

Theorem

Let G = (V ,E ) be a connected, planar graph where |V | ≥ 3:|E | ≤ 3|V | − 6

Proof.

the sum of region degrees: 2|E |degree of a region is at least 3⇒ 2|E | ≥ 3|R| ⇒ |R| ≤ 2

3 |E ||V | − |E |+ |R| = 2⇒ |V | − |E |+ 2

3 |E | ≥ 2 ⇒ |V | − 13 |E | ≥ 2

⇒ 3|V | − |E | ≥ 6 ⇒ |E | ≤ 3|V | − 6

Page 103: Discrete Mathematics - Graphs

Planar Graph Theorems

Theorem

Let G = (V ,E ) be a connected, planar graph where |V | ≥ 3:|E | ≤ 3|V | − 6

Proof.

the sum of region degrees: 2|E |degree of a region is at least 3⇒ 2|E | ≥ 3|R| ⇒ |R| ≤ 2

3 |E ||V | − |E |+ |R| = 2⇒ |V | − |E |+ 2

3 |E | ≥ 2 ⇒ |V | − 13 |E | ≥ 2

⇒ 3|V | − |E | ≥ 6 ⇒ |E | ≤ 3|V | − 6

Page 104: Discrete Mathematics - Graphs

Planar Graph Theorems

Theorem

Let G = (V ,E ) be a connected, planar graph where |V | ≥ 3:|E | ≤ 3|V | − 6

Proof.

the sum of region degrees: 2|E |degree of a region is at least 3⇒ 2|E | ≥ 3|R| ⇒ |R| ≤ 2

3 |E ||V | − |E |+ |R| = 2⇒ |V | − |E |+ 2

3 |E | ≥ 2 ⇒ |V | − 13 |E | ≥ 2

⇒ 3|V | − |E | ≥ 6 ⇒ |E | ≤ 3|V | − 6

Page 105: Discrete Mathematics - Graphs

Planar Graph Theorems

Theorem

Let G = (V ,E ) be a connected, planar graph where |V | ≥ 3:|E | ≤ 3|V | − 6

Proof.

the sum of region degrees: 2|E |degree of a region is at least 3⇒ 2|E | ≥ 3|R| ⇒ |R| ≤ 2

3 |E ||V | − |E |+ |R| = 2⇒ |V | − |E |+ 2

3 |E | ≥ 2 ⇒ |V | − 13 |E | ≥ 2

⇒ 3|V | − |E | ≥ 6 ⇒ |E | ≤ 3|V | − 6

Page 106: Discrete Mathematics - Graphs

Planar Graph Theorems

Theorem

Let G = (V ,E ) be a connected, planar graph where |V | ≥ 3:|E | ≤ 3|V | − 6

Proof.

the sum of region degrees: 2|E |degree of a region is at least 3⇒ 2|E | ≥ 3|R| ⇒ |R| ≤ 2

3 |E ||V | − |E |+ |R| = 2⇒ |V | − |E |+ 2

3 |E | ≥ 2 ⇒ |V | − 13 |E | ≥ 2

⇒ 3|V | − |E | ≥ 6 ⇒ |E | ≤ 3|V | − 6

Page 107: Discrete Mathematics - Graphs

Planar Graph Theorems

Theorem

Let G = (V ,E ) be a connected, planar graph where |V | ≥ 3:|E | ≤ 3|V | − 6

Proof.

the sum of region degrees: 2|E |degree of a region is at least 3⇒ 2|E | ≥ 3|R| ⇒ |R| ≤ 2

3 |E ||V | − |E |+ |R| = 2⇒ |V | − |E |+ 2

3 |E | ≥ 2 ⇒ |V | − 13 |E | ≥ 2

⇒ 3|V | − |E | ≥ 6 ⇒ |E | ≤ 3|V | − 6

Page 108: Discrete Mathematics - Graphs

Planar Graph Theorems

Theorem

Let G = (V ,E ) be a connected, planar graph where |V | ≥ 3:|E | ≤ 3|V | − 6

Proof.

the sum of region degrees: 2|E |degree of a region is at least 3⇒ 2|E | ≥ 3|R| ⇒ |R| ≤ 2

3 |E ||V | − |E |+ |R| = 2⇒ |V | − |E |+ 2

3 |E | ≥ 2 ⇒ |V | − 13 |E | ≥ 2

⇒ 3|V | − |E | ≥ 6 ⇒ |E | ≤ 3|V | − 6

Page 109: Discrete Mathematics - Graphs

Planar Graph Theorems

Theorem

Let G = (V ,E ) be a connected, planar graph where |V | ≥ 3:|E | ≤ 3|V | − 6

Proof.

the sum of region degrees: 2|E |degree of a region is at least 3⇒ 2|E | ≥ 3|R| ⇒ |R| ≤ 2

3 |E ||V | − |E |+ |R| = 2⇒ |V | − |E |+ 2

3 |E | ≥ 2 ⇒ |V | − 13 |E | ≥ 2

⇒ 3|V | − |E | ≥ 6 ⇒ |E | ≤ 3|V | − 6

Page 110: Discrete Mathematics - Graphs

Planar Graph Theorems

Theorem

Let G = (V ,E ) be a connected, planar graph where |V | ≥ 3:∃v ∈ V dv ≤ 5

Proof.

let ∀v ∈ V dv ≥ 6⇒ 2|E | ≥ 6|V |⇒ |E | ≥ 3|V |⇒ |E | > 3|V | − 6

Page 111: Discrete Mathematics - Graphs

Planar Graph Theorems

Theorem

Let G = (V ,E ) be a connected, planar graph where |V | ≥ 3:∃v ∈ V dv ≤ 5

Proof.

let ∀v ∈ V dv ≥ 6⇒ 2|E | ≥ 6|V |⇒ |E | ≥ 3|V |⇒ |E | > 3|V | − 6

Page 112: Discrete Mathematics - Graphs

Planar Graph Theorems

Theorem

Let G = (V ,E ) be a connected, planar graph where |V | ≥ 3:∃v ∈ V dv ≤ 5

Proof.

let ∀v ∈ V dv ≥ 6⇒ 2|E | ≥ 6|V |⇒ |E | ≥ 3|V |⇒ |E | > 3|V | − 6

Page 113: Discrete Mathematics - Graphs

Planar Graph Theorems

Theorem

Let G = (V ,E ) be a connected, planar graph where |V | ≥ 3:∃v ∈ V dv ≤ 5

Proof.

let ∀v ∈ V dv ≥ 6⇒ 2|E | ≥ 6|V |⇒ |E | ≥ 3|V |⇒ |E | > 3|V | − 6

Page 114: Discrete Mathematics - Graphs

Planar Graph Theorems

Theorem

Let G = (V ,E ) be a connected, planar graph where |V | ≥ 3:∃v ∈ V dv ≤ 5

Proof.

let ∀v ∈ V dv ≥ 6⇒ 2|E | ≥ 6|V |⇒ |E | ≥ 3|V |⇒ |E | > 3|V | − 6

Page 115: Discrete Mathematics - Graphs

Nonplanar Graphs

Theorem

K5 is not planar.

Proof.

|V | = 5

3|V | − 6 = 3 · 5− 6 = 9

|E | ≤ 9 should hold

but |E | = 10

Page 116: Discrete Mathematics - Graphs

Nonplanar Graphs

Theorem

K5 is not planar.

Proof.

|V | = 5

3|V | − 6 = 3 · 5− 6 = 9

|E | ≤ 9 should hold

but |E | = 10

Page 117: Discrete Mathematics - Graphs

Nonplanar Graphs

Theorem

K5 is not planar.

Proof.

|V | = 5

3|V | − 6 = 3 · 5− 6 = 9

|E | ≤ 9 should hold

but |E | = 10

Page 118: Discrete Mathematics - Graphs

Nonplanar Graphs

Theorem

K5 is not planar.

Proof.

|V | = 5

3|V | − 6 = 3 · 5− 6 = 9

|E | ≤ 9 should hold

but |E | = 10

Page 119: Discrete Mathematics - Graphs

Nonplanar Graphs

Theorem

K5 is not planar.

Proof.

|V | = 5

3|V | − 6 = 3 · 5− 6 = 9

|E | ≤ 9 should hold

but |E | = 10

Page 120: Discrete Mathematics - Graphs

Nonplanar Graphs

Theorem

K3,3 is not planar. Proof.

|V | = 6, |E | = 9

if planar then |R| = 5

degree of a region is at least 4⇒

∑r∈R dr ≥ 20

|E | ≥ 10 should hold

but |E | = 9

Page 121: Discrete Mathematics - Graphs

Nonplanar Graphs

Theorem

K3,3 is not planar. Proof.

|V | = 6, |E | = 9

if planar then |R| = 5

degree of a region is at least 4⇒

∑r∈R dr ≥ 20

|E | ≥ 10 should hold

but |E | = 9

Page 122: Discrete Mathematics - Graphs

Nonplanar Graphs

Theorem

K3,3 is not planar. Proof.

|V | = 6, |E | = 9

if planar then |R| = 5

degree of a region is at least 4⇒

∑r∈R dr ≥ 20

|E | ≥ 10 should hold

but |E | = 9

Page 123: Discrete Mathematics - Graphs

Nonplanar Graphs

Theorem

K3,3 is not planar. Proof.

|V | = 6, |E | = 9

if planar then |R| = 5

degree of a region is at least 4⇒

∑r∈R dr ≥ 20

|E | ≥ 10 should hold

but |E | = 9

Page 124: Discrete Mathematics - Graphs

Nonplanar Graphs

Theorem

K3,3 is not planar. Proof.

|V | = 6, |E | = 9

if planar then |R| = 5

degree of a region is at least 4⇒

∑r∈R dr ≥ 20

|E | ≥ 10 should hold

but |E | = 9

Page 125: Discrete Mathematics - Graphs

Nonplanar Graphs

Theorem

K3,3 is not planar. Proof.

|V | = 6, |E | = 9

if planar then |R| = 5

degree of a region is at least 4⇒

∑r∈R dr ≥ 20

|E | ≥ 10 should hold

but |E | = 9

Page 126: Discrete Mathematics - Graphs

Kuratowski’s Theorem

Theorem

G contains a subgraph homeomorphic to K5 or K3,3.⇔

G is not planar.

Page 127: Discrete Mathematics - Graphs

Platonic Solids

regular polyhedron: a 3-dimensional solidwhere the faces are identical regular polygons

the projection of a regular polyhedron onto the planeis a planar graph

every corner is a nodeevery side is an edgeevery face is a region

Page 128: Discrete Mathematics - Graphs

Platonic Solids

regular polyhedron: a 3-dimensional solidwhere the faces are identical regular polygons

the projection of a regular polyhedron onto the planeis a planar graph

every corner is a nodeevery side is an edgeevery face is a region

Page 129: Discrete Mathematics - Graphs

Platonic Solids

Example (cube)

Page 130: Discrete Mathematics - Graphs

Platonic Solids

v : number of corners (nodes)

e: number of sides (edges)

r : number of faces (regions)

n: number of faces meeting at a corner (node degree)

m: number of sides of a face (region degree)

m, n ≥ 3

2e = n · v2e = m · r

Page 131: Discrete Mathematics - Graphs

Platonic Solids

v : number of corners (nodes)

e: number of sides (edges)

r : number of faces (regions)

n: number of faces meeting at a corner (node degree)

m: number of sides of a face (region degree)

m, n ≥ 3

2e = n · v2e = m · r

Page 132: Discrete Mathematics - Graphs

Platonic Solids

from Euler’s formula:

2 = v − e + r =2e

n− e +

2e

m= e

(2m −mn + 2n

mn

)> 0

e,m, n > 0:

2m −mn + 2n > 0⇒ mn − 2m − 2n < 0

⇒ mn − 2m − 2n + 4 < 4⇒ (m − 2)(n − 2) < 4

the values that satisfy this inequation:

1 m = 3, n = 32 m = 4, n = 33 m = 3, n = 44 m = 5, n = 35 m = 3, n = 5

Page 133: Discrete Mathematics - Graphs

Platonic Solids

from Euler’s formula:

2 = v − e + r =2e

n− e +

2e

m= e

(2m −mn + 2n

mn

)> 0

e,m, n > 0:

2m −mn + 2n > 0⇒ mn − 2m − 2n < 0

⇒ mn − 2m − 2n + 4 < 4⇒ (m − 2)(n − 2) < 4

the values that satisfy this inequation:

1 m = 3, n = 32 m = 4, n = 33 m = 3, n = 44 m = 5, n = 35 m = 3, n = 5

Page 134: Discrete Mathematics - Graphs

Platonic Solids

from Euler’s formula:

2 = v − e + r =2e

n− e +

2e

m= e

(2m −mn + 2n

mn

)> 0

e,m, n > 0:

2m −mn + 2n > 0⇒ mn − 2m − 2n < 0

⇒ mn − 2m − 2n + 4 < 4⇒ (m − 2)(n − 2) < 4

the values that satisfy this inequation:

1 m = 3, n = 32 m = 4, n = 33 m = 3, n = 44 m = 5, n = 35 m = 3, n = 5

Page 135: Discrete Mathematics - Graphs

Platonic Solids

from Euler’s formula:

2 = v − e + r =2e

n− e +

2e

m= e

(2m −mn + 2n

mn

)> 0

e,m, n > 0:

2m −mn + 2n > 0⇒ mn − 2m − 2n < 0

⇒ mn − 2m − 2n + 4 < 4⇒ (m − 2)(n − 2) < 4

the values that satisfy this inequation:

1 m = 3, n = 32 m = 4, n = 33 m = 3, n = 44 m = 5, n = 35 m = 3, n = 5

Page 136: Discrete Mathematics - Graphs

Platonic Solids

from Euler’s formula:

2 = v − e + r =2e

n− e +

2e

m= e

(2m −mn + 2n

mn

)> 0

e,m, n > 0:

2m −mn + 2n > 0⇒ mn − 2m − 2n < 0

⇒ mn − 2m − 2n + 4 < 4⇒ (m − 2)(n − 2) < 4

the values that satisfy this inequation:

1 m = 3, n = 32 m = 4, n = 33 m = 3, n = 44 m = 5, n = 35 m = 3, n = 5

Page 137: Discrete Mathematics - Graphs

Tetrahedron

m = 3, n = 3

Page 138: Discrete Mathematics - Graphs

Hexahedron

m = 4, n = 3

Page 139: Discrete Mathematics - Graphs

Octahedron

m = 3, n = 4

Page 140: Discrete Mathematics - Graphs

Dodecahedron

m = 5, n = 3

Page 141: Discrete Mathematics - Graphs

Icosahedron

m = 3, n = 5

Page 142: Discrete Mathematics - Graphs

Graph Coloring

Definition

proper coloring of G = (V ,E ): f : V → Cwhere C is a set of colors

∀(vi , vj) ∈ E f (vi ) 6= f (vj)

minimizing |C |

Page 143: Discrete Mathematics - Graphs

Graph Coloring Example

Example

a company produces chemical compounds

some compounds cannot be stored together

such compounds must be placed in separate storage areas

store the compounds using the least number of storage areas

Page 144: Discrete Mathematics - Graphs

Graph Coloring Example

Example

a company produces chemical compounds

some compounds cannot be stored together

such compounds must be placed in separate storage areas

store the compounds using the least number of storage areas

Page 145: Discrete Mathematics - Graphs

Graph Coloring

Example

every compound is a node

two compounds that cannot be stored together are adjacent

Page 146: Discrete Mathematics - Graphs

Graph Coloring Example

Example

Page 147: Discrete Mathematics - Graphs

Graph Coloring Example

Example

Page 148: Discrete Mathematics - Graphs

Graph Coloring Example

Example

Page 149: Discrete Mathematics - Graphs

Graph Coloring Example

Example

Page 150: Discrete Mathematics - Graphs

Chromatic Number

Definition

chromatic number of G : χ(G )

the minimum number of colors needed to color the graph G

calculating χ(G ) is a very difficult problem

χ(Kn) = n

Page 151: Discrete Mathematics - Graphs

Chromatic Number

Definition

chromatic number of G : χ(G )

the minimum number of colors needed to color the graph G

calculating χ(G ) is a very difficult problem

χ(Kn) = n

Page 152: Discrete Mathematics - Graphs

Chromatic Number Example

Example (Herschel graph)

chromatic number: 2

Page 153: Discrete Mathematics - Graphs

Graph Coloring Example

Example (Sudoku)

every cell is a node

cells of the same roware adjacent

cells of the same columnare adjacent

cells of the same 3× 3 blockare adjacent

every number is a color

problem: properly color a graphthat is partially colored

Page 154: Discrete Mathematics - Graphs

Graph Coloring Example

Example (Sudoku)

every cell is a node

cells of the same roware adjacent

cells of the same columnare adjacent

cells of the same 3× 3 blockare adjacent

every number is a color

problem: properly color a graphthat is partially colored

Page 155: Discrete Mathematics - Graphs

Region Coloring

coloring a map by assigning different colors to adjacent regions

Theorem (Four Color Theorem)

The regions in a map can be colored using four colors.

Page 156: Discrete Mathematics - Graphs

Topics

1 GraphsIntroductionConnectivityPlanar GraphsSearching Graphs

2 TreesIntroductionRooted TreesBinary TreesDecision Trees

3 Weighted GraphsIntroductionShortest PathMinimum Spanning Tree

Page 157: Discrete Mathematics - Graphs

Searching Graphs

searching nodes of graph G = (V ,E ) starting from node v1

depth-first

breadth-first

Page 158: Discrete Mathematics - Graphs

Depth-First Search

1 v ← v1,T = ∅, D = {v1}2 find smallest i in 2 ≤ i ≤ |V | such that (v , vi ) ∈ E and vi /∈ D

if no such i exists: go to step 3if found: T = T ∪ {(v , vi )}, D = D ∪ {vi}, v ← vi ,go to step 2

3 if v = v1 then the result is T

4 if v 6= v1 then v ← parent(v), go to step 2

Page 159: Discrete Mathematics - Graphs

Depth-First Search

1 v ← v1,T = ∅, D = {v1}2 find smallest i in 2 ≤ i ≤ |V | such that (v , vi ) ∈ E and vi /∈ D

if no such i exists: go to step 3if found: T = T ∪ {(v , vi )}, D = D ∪ {vi}, v ← vi ,go to step 2

3 if v = v1 then the result is T

4 if v 6= v1 then v ← parent(v), go to step 2

Page 160: Discrete Mathematics - Graphs

Depth-First Search

1 v ← v1,T = ∅, D = {v1}2 find smallest i in 2 ≤ i ≤ |V | such that (v , vi ) ∈ E and vi /∈ D

if no such i exists: go to step 3if found: T = T ∪ {(v , vi )}, D = D ∪ {vi}, v ← vi ,go to step 2

3 if v = v1 then the result is T

4 if v 6= v1 then v ← parent(v), go to step 2

Page 161: Discrete Mathematics - Graphs

Depth-First Search

1 v ← v1,T = ∅, D = {v1}2 find smallest i in 2 ≤ i ≤ |V | such that (v , vi ) ∈ E and vi /∈ D

if no such i exists: go to step 3if found: T = T ∪ {(v , vi )}, D = D ∪ {vi}, v ← vi ,go to step 2

3 if v = v1 then the result is T

4 if v 6= v1 then v ← parent(v), go to step 2

Page 162: Discrete Mathematics - Graphs

Breadth-First Search

1 T = ∅, D = {v1}, Q = (v1)

2 if Q is empty: the result is T

3 if Q not empty: v ← front(Q), Q ← Q − vfor 2 ≤ i ≤ |V | check the edges (v , vi ) ∈ E :

if vi /∈ D : Q = Q + vi , T = T ∪ {(v , vi )}, D = D ∪ {vi}go to step 3

Page 163: Discrete Mathematics - Graphs

Breadth-First Search

1 T = ∅, D = {v1}, Q = (v1)

2 if Q is empty: the result is T

3 if Q not empty: v ← front(Q), Q ← Q − vfor 2 ≤ i ≤ |V | check the edges (v , vi ) ∈ E :

if vi /∈ D : Q = Q + vi , T = T ∪ {(v , vi )}, D = D ∪ {vi}go to step 3

Page 164: Discrete Mathematics - Graphs

References

Required Reading: Grimaldi

Chapter 11: An Introduction to Graph Theory

Chapter 7: Relations: The Second Time Around

7.2. Computer Recognition: Zero-One Matricesand Directed Graphs

Page 165: Discrete Mathematics - Graphs

Topics

1 GraphsIntroductionConnectivityPlanar GraphsSearching Graphs

2 TreesIntroductionRooted TreesBinary TreesDecision Trees

3 Weighted GraphsIntroductionShortest PathMinimum Spanning Tree

Page 166: Discrete Mathematics - Graphs

Tree

Definition

tree: a connected graph that contains no cycle

forest: a graph where the connected components are trees

Page 167: Discrete Mathematics - Graphs

Tree

Definition

tree: a connected graph that contains no cycle

forest: a graph where the connected components are trees

Page 168: Discrete Mathematics - Graphs

Tree Examples

Example

Page 169: Discrete Mathematics - Graphs

Tree Theorems

Theorem

In a tree, there is one and only one pathbetween any two distinct nodes.

there is at least one path because the tree is connected

if there were more than one path, they would form a cycle

Page 170: Discrete Mathematics - Graphs

Tree Theorems

Theorem

Let T = (V ,E ) be a tree:

|E | = |V | − 1

proof method: induction on the number of edges

Page 171: Discrete Mathematics - Graphs

Tree Theorems

Proof: base step

|E | = 0⇒ |V | = 1

|E | = 1⇒ |V | = 2

|E | = 2⇒ |V | = 3

assume that |E | = |V | − 1 for |E | ≤ k

Page 172: Discrete Mathematics - Graphs

Tree Theorems

Proof: base step

|E | = 0⇒ |V | = 1

|E | = 1⇒ |V | = 2

|E | = 2⇒ |V | = 3

assume that |E | = |V | − 1 for |E | ≤ k

Page 173: Discrete Mathematics - Graphs

Tree Theorems

Proof: induction step.

|E | = k + 1

let’s remove the edge (y , z):T1 = (V1,E1), T2 = (V2,E2)

|V | = |V1|+ |V2|= |E1|+ 1 + |E2|+ 1

= (|E1|+ |E2|+ 1) + 1

= |E |+ 1

Page 174: Discrete Mathematics - Graphs

Tree Theorems

Proof: induction step.

|E | = k + 1

let’s remove the edge (y , z):T1 = (V1,E1), T2 = (V2,E2)

|V | = |V1|+ |V2|= |E1|+ 1 + |E2|+ 1

= (|E1|+ |E2|+ 1) + 1

= |E |+ 1

Page 175: Discrete Mathematics - Graphs

Tree Theorems

Proof: induction step.

|E | = k + 1

let’s remove the edge (y , z):T1 = (V1,E1), T2 = (V2,E2)

|V | = |V1|+ |V2|= |E1|+ 1 + |E2|+ 1

= (|E1|+ |E2|+ 1) + 1

= |E |+ 1

Page 176: Discrete Mathematics - Graphs

Tree Theorems

Proof: induction step.

|E | = k + 1

let’s remove the edge (y , z):T1 = (V1,E1), T2 = (V2,E2)

|V | = |V1|+ |V2|= |E1|+ 1 + |E2|+ 1

= (|E1|+ |E2|+ 1) + 1

= |E |+ 1

Page 177: Discrete Mathematics - Graphs

Tree Theorems

Proof: induction step.

|E | = k + 1

let’s remove the edge (y , z):T1 = (V1,E1), T2 = (V2,E2)

|V | = |V1|+ |V2|= |E1|+ 1 + |E2|+ 1

= (|E1|+ |E2|+ 1) + 1

= |E |+ 1

Page 178: Discrete Mathematics - Graphs

Tree Theorems

Proof: induction step.

|E | = k + 1

let’s remove the edge (y , z):T1 = (V1,E1), T2 = (V2,E2)

|V | = |V1|+ |V2|= |E1|+ 1 + |E2|+ 1

= (|E1|+ |E2|+ 1) + 1

= |E |+ 1

Page 179: Discrete Mathematics - Graphs

Tree Theorems

Theorem

In a tree, there are at least two nodes with degree 1.

Proof.

2|E | =∑

v∈V dv

assume that there is only 1 node with degree 1:⇒ 2|E | ≥ 2(|V | − 1) + 1⇒ 2|E | ≥ 2|V | − 1⇒ |E | ≥ |V | − 1

2 > |V | − 1

Page 180: Discrete Mathematics - Graphs

Tree Theorems

Theorem

In a tree, there are at least two nodes with degree 1.

Proof.

2|E | =∑

v∈V dv

assume that there is only 1 node with degree 1:⇒ 2|E | ≥ 2(|V | − 1) + 1⇒ 2|E | ≥ 2|V | − 1⇒ |E | ≥ |V | − 1

2 > |V | − 1

Page 181: Discrete Mathematics - Graphs

Tree Theorems

Theorem

In a tree, there are at least two nodes with degree 1.

Proof.

2|E | =∑

v∈V dv

assume that there is only 1 node with degree 1:⇒ 2|E | ≥ 2(|V | − 1) + 1⇒ 2|E | ≥ 2|V | − 1⇒ |E | ≥ |V | − 1

2 > |V | − 1

Page 182: Discrete Mathematics - Graphs

Tree Theorems

Theorem

In a tree, there are at least two nodes with degree 1.

Proof.

2|E | =∑

v∈V dv

assume that there is only 1 node with degree 1:⇒ 2|E | ≥ 2(|V | − 1) + 1⇒ 2|E | ≥ 2|V | − 1⇒ |E | ≥ |V | − 1

2 > |V | − 1

Page 183: Discrete Mathematics - Graphs

Tree Theorems

Theorem

In a tree, there are at least two nodes with degree 1.

Proof.

2|E | =∑

v∈V dv

assume that there is only 1 node with degree 1:⇒ 2|E | ≥ 2(|V | − 1) + 1⇒ 2|E | ≥ 2|V | − 1⇒ |E | ≥ |V | − 1

2 > |V | − 1

Page 184: Discrete Mathematics - Graphs

Tree Theorems

Theorem

In a tree, there are at least two nodes with degree 1.

Proof.

2|E | =∑

v∈V dv

assume that there is only 1 node with degree 1:⇒ 2|E | ≥ 2(|V | − 1) + 1⇒ 2|E | ≥ 2|V | − 1⇒ |E | ≥ |V | − 1

2 > |V | − 1

Page 185: Discrete Mathematics - Graphs

Tree Theorems

Theorem

In a tree, there are at least two nodes with degree 1.

Proof.

2|E | =∑

v∈V dv

assume that there is only 1 node with degree 1:⇒ 2|E | ≥ 2(|V | − 1) + 1⇒ 2|E | ≥ 2|V | − 1⇒ |E | ≥ |V | − 1

2 > |V | − 1

Page 186: Discrete Mathematics - Graphs

Tree Theorems

Theorem

T is a tree (T is connected and contains no cycle).⇔

There is one and only one pathbetween any two distinct nodes in T .

⇔T is connected, but if any edge is removed

it will no longer be connected.⇔

T contains no cycle, but if an edge is addedbetween any pair of nodes one and only one cycle will be formed.

Page 187: Discrete Mathematics - Graphs

Tree Theorems

Theorem

T is a tree (T is connected and contains no cycle).⇔

T is connected and |E | = |V | − 1.⇔

T contains no cycle and |E | = |V | − 1.

Page 188: Discrete Mathematics - Graphs

Topics

1 GraphsIntroductionConnectivityPlanar GraphsSearching Graphs

2 TreesIntroductionRooted TreesBinary TreesDecision Trees

3 Weighted GraphsIntroductionShortest PathMinimum Spanning Tree

Page 189: Discrete Mathematics - Graphs

Rooted Tree

a hierarchy is defined between nodes

hierarchy creates a natural direction on edges⇒ in and out degrees

node with in-degree 0 (top of the hierarchy): root

nodes with out-degree 0: leaf

nodes that are not leaves: internal node

Page 190: Discrete Mathematics - Graphs

Rooted Tree

a hierarchy is defined between nodes

hierarchy creates a natural direction on edges⇒ in and out degrees

node with in-degree 0 (top of the hierarchy): root

nodes with out-degree 0: leaf

nodes that are not leaves: internal node

Page 191: Discrete Mathematics - Graphs

Node Level

Definition

level of a node: the distance of the node from the root

parent: adjacent node in the next upper level

children: adjacent nodes in the next lower level

sibling: nodes which have the same parent

Page 192: Discrete Mathematics - Graphs

Rooted Tree Example

Example

root: r

leaves: x y z u v

internal nodes: r p n t s q w

parent of y : wchildren of w : y and z

y and z are siblings

Page 193: Discrete Mathematics - Graphs

Rooted Tree Example

ExampleBook

C1

S1.1S1.2

C2

C3

S3.1S3.2

S3.2.1S3.2.2

S3.3

Page 194: Discrete Mathematics - Graphs

Ordered Rooted Tree

sibling nodes are ordered from left to right

universal address system

assign the address 0 to the rootassign the positive integers 1, 2, 3, . . . to the nodes at level 1,from left to rightlet v be an internal node with address a,assign the addresses a.1, a.2, a.3, . . . to the children of vfrom left to right

Page 195: Discrete Mathematics - Graphs

Lexicographic Order

Definition

Let b and c be two addresses.b comes before c if one of the following holds:

1 b = a1a2 . . . amx1 . . .c = a1a2 . . . amx2 . . .x1 comes before x2

2 b = a1a2 . . . am

c = a1a2 . . . amam+1 . . .

Page 196: Discrete Mathematics - Graphs

Lexicographic Order

Definition

Let b and c be two addresses.b comes before c if one of the following holds:

1 b = a1a2 . . . amx1 . . .c = a1a2 . . . amx2 . . .x1 comes before x2

2 b = a1a2 . . . am

c = a1a2 . . . amam+1 . . .

Page 197: Discrete Mathematics - Graphs

Lexicographic Order Example

Example

0 - 1 - 1.1 - 1.2- 1.2.1 - 1.2.2 - 1.2.3- 1.2.3.1 - 1.2.3.2- 1.3 - 1.4 - 2- 2.1 - 2.2 - 2.2.1- 3 - 3.1 - 3.2

Page 198: Discrete Mathematics - Graphs

Topics

1 GraphsIntroductionConnectivityPlanar GraphsSearching Graphs

2 TreesIntroductionRooted TreesBinary TreesDecision Trees

3 Weighted GraphsIntroductionShortest PathMinimum Spanning Tree

Page 199: Discrete Mathematics - Graphs

Binary Trees

Definition

T = (V ,E ) is a binary tree: ∀v ∈ V dvo ∈ {0, 1, 2}

T = (V ,E ) is a complete binary tree: ∀v ∈ V dvo ∈ {0, 2}

Page 200: Discrete Mathematics - Graphs

Expression Tree

a binary operation can be represented as a binary tree

operator as the root, operands as the children

every mathematical expression can be represented as a tree

operators at internal nodes, variables and values at the leaves

Page 201: Discrete Mathematics - Graphs

Expression Tree Examples

Example (7− a) Example (a + b)

Page 202: Discrete Mathematics - Graphs

Expression Tree Examples

Example ((7− a)/5) Example ((a + b) ↑ 3)

Page 203: Discrete Mathematics - Graphs

Expression Tree Examples

Example (((7− a)/5) ∗ ((a + b) ↑ 3))

Page 204: Discrete Mathematics - Graphs

Expression Tree Examples

Example (t + (u ∗ v)/(w + x − y ↑ z))

Page 205: Discrete Mathematics - Graphs

Expression Tree Traversals

1 inorder traversal: traverse the left subtree, visit the root,traverse the right subtree

2 preorder traversal: visit the root, traverse the left subtree,traverse the right subtree

3 postorder traversal: traverse the left subtree,traverse the right subtree, visit the root

reverse Polish notation

Page 206: Discrete Mathematics - Graphs

Inorder Traversal Example

Example

t + u ∗ v / w + x − y ↑ z

Page 207: Discrete Mathematics - Graphs

Preorder Traversal Example

Example

+ t / ∗ u v + w − x ↑ y z

Page 208: Discrete Mathematics - Graphs

Postorder Traversal Example

Example

t u v ∗ w x y z ↑ − + / +

Page 209: Discrete Mathematics - Graphs

Expression Tree Evaluation

inorder traversal requires parantheses for precedence

preorder and postorder traversals do not require parantheses

Page 210: Discrete Mathematics - Graphs

Postorder Evaluation Example

Example (t u v ∗ w x y z ↑ − + / +)

4 2 3 ∗ 1 9 2 3 ↑ − + / +

4 2 3 ∗4 6 1 9 2 3 ↑4 6 1 9 8 −4 6 1 1 +4 6 2 /4 3 +7

Page 211: Discrete Mathematics - Graphs

Postorder Evaluation Example

Example (t u v ∗ w x y z ↑ − + / +)

4 2 3 ∗ 1 9 2 3 ↑ − + / +

4 2 3 ∗4 6 1 9 2 3 ↑4 6 1 9 8 −4 6 1 1 +4 6 2 /4 3 +7

Page 212: Discrete Mathematics - Graphs

Postorder Evaluation Example

Example (t u v ∗ w x y z ↑ − + / +)

4 2 3 ∗ 1 9 2 3 ↑ − + / +

4 2 3 ∗4 6 1 9 2 3 ↑4 6 1 9 8 −4 6 1 1 +4 6 2 /4 3 +7

Page 213: Discrete Mathematics - Graphs

Postorder Evaluation Example

Example (t u v ∗ w x y z ↑ − + / +)

4 2 3 ∗ 1 9 2 3 ↑ − + / +

4 2 3 ∗4 6 1 9 2 3 ↑4 6 1 9 8 −4 6 1 1 +4 6 2 /4 3 +7

Page 214: Discrete Mathematics - Graphs

Postorder Evaluation Example

Example (t u v ∗ w x y z ↑ − + / +)

4 2 3 ∗ 1 9 2 3 ↑ − + / +

4 2 3 ∗4 6 1 9 2 3 ↑4 6 1 9 8 −4 6 1 1 +4 6 2 /4 3 +7

Page 215: Discrete Mathematics - Graphs

Postorder Evaluation Example

Example (t u v ∗ w x y z ↑ − + / +)

4 2 3 ∗ 1 9 2 3 ↑ − + / +

4 2 3 ∗4 6 1 9 2 3 ↑4 6 1 9 8 −4 6 1 1 +4 6 2 /4 3 +7

Page 216: Discrete Mathematics - Graphs

Postorder Evaluation Example

Example (t u v ∗ w x y z ↑ − + / +)

4 2 3 ∗ 1 9 2 3 ↑ − + / +

4 2 3 ∗4 6 1 9 2 3 ↑4 6 1 9 8 −4 6 1 1 +4 6 2 /4 3 +7

Page 217: Discrete Mathematics - Graphs

Postorder Evaluation Example

Example (t u v ∗ w x y z ↑ − + / +)

4 2 3 ∗ 1 9 2 3 ↑ − + / +

4 2 3 ∗4 6 1 9 2 3 ↑4 6 1 9 8 −4 6 1 1 +4 6 2 /4 3 +7

Page 218: Discrete Mathematics - Graphs

Postorder Evaluation Example

Example (t u v ∗ w x y z ↑ − + / +)

4 2 3 ∗ 1 9 2 3 ↑ − + / +

4 2 3 ∗4 6 1 9 2 3 ↑4 6 1 9 8 −4 6 1 1 +4 6 2 /4 3 +7

Page 219: Discrete Mathematics - Graphs

Postorder Evaluation Example

Example (t u v ∗ w x y z ↑ − + / +)

4 2 3 ∗ 1 9 2 3 ↑ − + / +

4 2 3 ∗4 6 1 9 2 3 ↑4 6 1 9 8 −4 6 1 1 +4 6 2 /4 3 +7

Page 220: Discrete Mathematics - Graphs

Postorder Evaluation Example

Example (t u v ∗ w x y z ↑ − + / +)

4 2 3 ∗ 1 9 2 3 ↑ − + / +

4 2 3 ∗4 6 1 9 2 3 ↑4 6 1 9 8 −4 6 1 1 +4 6 2 /4 3 +7

Page 221: Discrete Mathematics - Graphs

Postorder Evaluation Example

Example (t u v ∗ w x y z ↑ − + / +)

4 2 3 ∗ 1 9 2 3 ↑ − + / +

4 2 3 ∗4 6 1 9 2 3 ↑4 6 1 9 8 −4 6 1 1 +4 6 2 /4 3 +7

Page 222: Discrete Mathematics - Graphs

Postorder Evaluation Example

Example (t u v ∗ w x y z ↑ − + / +)

4 2 3 ∗ 1 9 2 3 ↑ − + / +

4 2 3 ∗4 6 1 9 2 3 ↑4 6 1 9 8 −4 6 1 1 +4 6 2 /4 3 +7

Page 223: Discrete Mathematics - Graphs

Postorder Evaluation Example

Example (t u v ∗ w x y z ↑ − + / +)

4 2 3 ∗ 1 9 2 3 ↑ − + / +

4 2 3 ∗4 6 1 9 2 3 ↑4 6 1 9 8 −4 6 1 1 +4 6 2 /4 3 +7

Page 224: Discrete Mathematics - Graphs

Regular Tree

Definition

T = (V ,E ) is an m-ary tree: ∀v ∈ V dvo ≤ m

T = (V ,E ) is a complete m-ary tree: ∀v ∈ V dvo ∈ {0,m}

Page 225: Discrete Mathematics - Graphs

Regular Tree Theorem

Theorem

Let T = (V ,E ) be a complete m-ary tree.

n: number of nodes

l : number of leaves

i : number of internal nodes

Then:

n = m · i + 1

l = n − i = m · i + 1− i = (m − 1) · i + 1

i =l − 1

m − 1

Page 226: Discrete Mathematics - Graphs

Regular Tree Theorem

Theorem

Let T = (V ,E ) be a complete m-ary tree.

n: number of nodes

l : number of leaves

i : number of internal nodes

Then:

n = m · i + 1

l = n − i = m · i + 1− i = (m − 1) · i + 1

i =l − 1

m − 1

Page 227: Discrete Mathematics - Graphs

Regular Tree Theorem

Theorem

Let T = (V ,E ) be a complete m-ary tree.

n: number of nodes

l : number of leaves

i : number of internal nodes

Then:

n = m · i + 1

l = n − i = m · i + 1− i = (m − 1) · i + 1

i =l − 1

m − 1

Page 228: Discrete Mathematics - Graphs

Regular Tree Theorem

Theorem

Let T = (V ,E ) be a complete m-ary tree.

n: number of nodes

l : number of leaves

i : number of internal nodes

Then:

n = m · i + 1

l = n − i = m · i + 1− i = (m − 1) · i + 1

i =l − 1

m − 1

Page 229: Discrete Mathematics - Graphs

Regular Tree Theorem

Theorem

Let T = (V ,E ) be a complete m-ary tree.

n: number of nodes

l : number of leaves

i : number of internal nodes

Then:

n = m · i + 1

l = n − i = m · i + 1− i = (m − 1) · i + 1

i =l − 1

m − 1

Page 230: Discrete Mathematics - Graphs

Regular Tree Theorem

Theorem

Let T = (V ,E ) be a complete m-ary tree.

n: number of nodes

l : number of leaves

i : number of internal nodes

Then:

n = m · i + 1

l = n − i = m · i + 1− i = (m − 1) · i + 1

i =l − 1

m − 1

Page 231: Discrete Mathematics - Graphs

Regular Tree Examples

Example

how many matches are played in a tennis tournamentwith 27 players?

every player is a leaf: l = 27

every match is an internal node: m = 2

number of matches: i = l−1m−1 = 27−1

2−1 = 26

Page 232: Discrete Mathematics - Graphs

Regular Tree Examples

Example

how many matches are played in a tennis tournamentwith 27 players?

every player is a leaf: l = 27

every match is an internal node: m = 2

number of matches: i = l−1m−1 = 27−1

2−1 = 26

Page 233: Discrete Mathematics - Graphs

Regular Tree Examples

Example

how many extension cords with 4 outlets are requiredto connect 25 computers to a wall socket?

every computer is a leaf: l = 25

every extension cord is an internal node: m = 4

number of cords: i = l−1m−1 = 25−1

4−1 = 8

Page 234: Discrete Mathematics - Graphs

Regular Tree Examples

Example

how many extension cords with 4 outlets are requiredto connect 25 computers to a wall socket?

every computer is a leaf: l = 25

every extension cord is an internal node: m = 4

number of cords: i = l−1m−1 = 25−1

4−1 = 8

Page 235: Discrete Mathematics - Graphs

Topics

1 GraphsIntroductionConnectivityPlanar GraphsSearching Graphs

2 TreesIntroductionRooted TreesBinary TreesDecision Trees

3 Weighted GraphsIntroductionShortest PathMinimum Spanning Tree

Page 236: Discrete Mathematics - Graphs

Decision Trees

Example

one of 8 coins is counterfeit (it’s heavier)

find the counterfeit coin using a beam balance

Page 237: Discrete Mathematics - Graphs

Decision Trees

Example (in 3 weighings)

Page 238: Discrete Mathematics - Graphs

Decision Trees

Example (in 2 weighings)

Page 239: Discrete Mathematics - Graphs

References

Required Reading: Grimaldi

Chapter 12: Trees

12.1. Definitions and Examples12.2. Rooted Trees

Page 240: Discrete Mathematics - Graphs

Topics

1 GraphsIntroductionConnectivityPlanar GraphsSearching Graphs

2 TreesIntroductionRooted TreesBinary TreesDecision Trees

3 Weighted GraphsIntroductionShortest PathMinimum Spanning Tree

Page 241: Discrete Mathematics - Graphs

Weighted Graphs

assign labels to edges:weight, length, cost, delay, probability, . . .

Page 242: Discrete Mathematics - Graphs

Topics

1 GraphsIntroductionConnectivityPlanar GraphsSearching Graphs

2 TreesIntroductionRooted TreesBinary TreesDecision Trees

3 Weighted GraphsIntroductionShortest PathMinimum Spanning Tree

Page 243: Discrete Mathematics - Graphs

Shortest Path

find the shortest paths from a node to all other nodes:Dijkstra’s algorithm

Page 244: Discrete Mathematics - Graphs

Dijkstra’s Algorithm Example

Example (initialization)

starting node: c

a (∞,−)

b (∞,−)

c (0,−)

f (∞,−)

g (∞,−)

h (∞,−)

Page 245: Discrete Mathematics - Graphs

Dijkstra’s Algorithm Example

Example (from node c - base distance=0)

c → f : 6, 6 <∞c → h : 11, 11 <∞

a (∞,−)

b (∞,−)

c (0,−)√

f (6, cf )

g (∞,−)

h (11, ch)

closest node: f

Page 246: Discrete Mathematics - Graphs

Dijkstra’s Algorithm Example

Example (from node c - base distance=0)

c → f : 6, 6 <∞c → h : 11, 11 <∞

a (∞,−)

b (∞,−)

c (0,−)√

f (6, cf )

g (∞,−)

h (11, ch)

closest node: f

Page 247: Discrete Mathematics - Graphs

Dijkstra’s Algorithm Example

Example (from node c - base distance=0)

c → f : 6, 6 <∞c → h : 11, 11 <∞

a (∞,−)

b (∞,−)

c (0,−)√

f (6, cf )

g (∞,−)

h (11, ch)

closest node: f

Page 248: Discrete Mathematics - Graphs

Dijkstra’s Algorithm Example

Example (from node f - base distance=6)

f → a : 6 + 11, 17 <∞f → g : 6 + 9, 15 <∞f → h : 6 + 4, 10 < 11

a (17, cfa)

b (∞,−)

c (0,−)√

f (6, cf )√

g (15, cfg)

h (10, cfh)

closest node: h

Page 249: Discrete Mathematics - Graphs

Dijkstra’s Algorithm Example

Example (from node f - base distance=6)

f → a : 6 + 11, 17 <∞f → g : 6 + 9, 15 <∞f → h : 6 + 4, 10 < 11

a (17, cfa)

b (∞,−)

c (0,−)√

f (6, cf )√

g (15, cfg)

h (10, cfh)

closest node: h

Page 250: Discrete Mathematics - Graphs

Dijkstra’s Algorithm Example

Example (from node f - base distance=6)

f → a : 6 + 11, 17 <∞f → g : 6 + 9, 15 <∞f → h : 6 + 4, 10 < 11

a (17, cfa)

b (∞,−)

c (0,−)√

f (6, cf )√

g (15, cfg)

h (10, cfh)

closest node: h

Page 251: Discrete Mathematics - Graphs

Dijkstra’s Algorithm Example

Example (from node h - base distance=10)

h→ a : 10 + 11, 21 ≮ 17

h→ g : 10 + 4, 14 < 15

a (17, cfa)

b (∞,−)

c (0,−)√

f (6, cf )√

g (14, cfhg)

h (10, cfh)√

closest node: g

Page 252: Discrete Mathematics - Graphs

Dijkstra’s Algorithm Example

Example (from node h - base distance=10)

h→ a : 10 + 11, 21 ≮ 17

h→ g : 10 + 4, 14 < 15

a (17, cfa)

b (∞,−)

c (0,−)√

f (6, cf )√

g (14, cfhg)

h (10, cfh)√

closest node: g

Page 253: Discrete Mathematics - Graphs

Dijkstra’s Algorithm Example

Example (from node h - base distance=10)

h→ a : 10 + 11, 21 ≮ 17

h→ g : 10 + 4, 14 < 15

a (17, cfa)

b (∞,−)

c (0,−)√

f (6, cf )√

g (14, cfhg)

h (10, cfh)√

closest node: g

Page 254: Discrete Mathematics - Graphs

Dijkstra’s Algorithm Example

Example (from node g - base distance=14)

g → a : 14 + 17, 31 ≮ 17

a (17, cfa)

b (∞,−)

c (0,−)√

f (6, cf )√

g (14, cfhg)√

h (10, cfh)√

closest node: a

Page 255: Discrete Mathematics - Graphs

Dijkstra’s Algorithm Example

Example (from node g - base distance=14)

g → a : 14 + 17, 31 ≮ 17

a (17, cfa)

b (∞,−)

c (0,−)√

f (6, cf )√

g (14, cfhg)√

h (10, cfh)√

closest node: a

Page 256: Discrete Mathematics - Graphs

Dijkstra’s Algorithm Example

Example (from node g - base distance=14)

g → a : 14 + 17, 31 ≮ 17

a (17, cfa)

b (∞,−)

c (0,−)√

f (6, cf )√

g (14, cfhg)√

h (10, cfh)√

closest node: a

Page 257: Discrete Mathematics - Graphs

Dijkstra’s Algorithm Example

Example (from node a - base distance=17)

a→ b : 17 + 5, 22 <∞

a (17, cfa)√

b (22, cfab)

c (0,−)√

f (6, cf )√

g (14, cfhg)√

h (10, cfh)√

last node: b

Page 258: Discrete Mathematics - Graphs

Dijkstra’s Algorithm Example

Example (from node a - base distance=17)

a→ b : 17 + 5, 22 <∞

a (17, cfa)√

b (22, cfab)

c (0,−)√

f (6, cf )√

g (14, cfhg)√

h (10, cfh)√

last node: b

Page 259: Discrete Mathematics - Graphs

Dijkstra’s Algorithm Example

Example (from node a - base distance=17)

a→ b : 17 + 5, 22 <∞

a (17, cfa)√

b (22, cfab)

c (0,−)√

f (6, cf )√

g (14, cfhg)√

h (10, cfh)√

last node: b

Page 260: Discrete Mathematics - Graphs

Topics

1 GraphsIntroductionConnectivityPlanar GraphsSearching Graphs

2 TreesIntroductionRooted TreesBinary TreesDecision Trees

3 Weighted GraphsIntroductionShortest PathMinimum Spanning Tree

Page 261: Discrete Mathematics - Graphs

Spanning Tree

Definition

spanning tree:a subgraph which is a tree and contains all the nodes of the graph

Definition

minimum spanning tree:a spanning tree for which the total weight of edges is minimal

Page 262: Discrete Mathematics - Graphs

Spanning Tree

Definition

spanning tree:a subgraph which is a tree and contains all the nodes of the graph

Definition

minimum spanning tree:a spanning tree for which the total weight of edges is minimal

Page 263: Discrete Mathematics - Graphs

Kruskal’s Algorithm

Kruskal’s algorithm

1 i ← 1, e1 ∈ E , wt(e1) is minimal

2 for 1 ≤ i ≤ n − 2:the selected edges are e1, e2, . . . , ei

select a new edge ei+1 from the remaining edges such that:

wt(ei+1) is minimale1, e2, . . . , ei , ei+1 contains no cycle

3 i ← i + 1

i = n − 1 ⇒ the subgraph G containing the edgese1, e2, . . . , en−1 is a minimum spanning treei < n − 1 ⇒ go to step 2

Page 264: Discrete Mathematics - Graphs

Kruskal’s Algorithm

Kruskal’s algorithm

1 i ← 1, e1 ∈ E , wt(e1) is minimal

2 for 1 ≤ i ≤ n − 2:the selected edges are e1, e2, . . . , ei

select a new edge ei+1 from the remaining edges such that:

wt(ei+1) is minimale1, e2, . . . , ei , ei+1 contains no cycle

3 i ← i + 1

i = n − 1 ⇒ the subgraph G containing the edgese1, e2, . . . , en−1 is a minimum spanning treei < n − 1 ⇒ go to step 2

Page 265: Discrete Mathematics - Graphs

Kruskal’s Algorithm

Kruskal’s algorithm

1 i ← 1, e1 ∈ E , wt(e1) is minimal

2 for 1 ≤ i ≤ n − 2:the selected edges are e1, e2, . . . , ei

select a new edge ei+1 from the remaining edges such that:

wt(ei+1) is minimale1, e2, . . . , ei , ei+1 contains no cycle

3 i ← i + 1

i = n − 1 ⇒ the subgraph G containing the edgese1, e2, . . . , en−1 is a minimum spanning treei < n − 1 ⇒ go to step 2

Page 266: Discrete Mathematics - Graphs

Kruskal’s Algorithm Example

Example (initialization)

i ← 1

minimum weight: 1(e, g)

T = {(e, g)}

Page 267: Discrete Mathematics - Graphs

Kruskal’s Algorithm Example

Example (initialization)

i ← 1

minimum weight: 1(e, g)

T = {(e, g)}

Page 268: Discrete Mathematics - Graphs

Kruskal’s Algorithm Example

Example (initialization)

i ← 1

minimum weight: 1(e, g)

T = {(e, g)}

Page 269: Discrete Mathematics - Graphs

Kruskal’s Algorithm Example

Example (1 < 6)

minimum weight: 2(d , e), (d , f ), (f , g)

T = {(e, g), (d , f )}i ← 2

Page 270: Discrete Mathematics - Graphs

Kruskal’s Algorithm Example

Example (1 < 6)

minimum weight: 2(d , e), (d , f ), (f , g)

T = {(e, g), (d , f )}i ← 2

Page 271: Discrete Mathematics - Graphs

Kruskal’s Algorithm Example

Example (1 < 6)

minimum weight: 2(d , e), (d , f ), (f , g)

T = {(e, g), (d , f )}i ← 2

Page 272: Discrete Mathematics - Graphs

Kruskal’s Algorithm Example

Example (2 < 6)

minimum weight: 2(d , e), (f , g)

T = {(e, g), (d , f ), (d , e)}i ← 3

Page 273: Discrete Mathematics - Graphs

Kruskal’s Algorithm Example

Example (2 < 6)

minimum weight: 2(d , e), (f , g)

T = {(e, g), (d , f ), (d , e)}i ← 3

Page 274: Discrete Mathematics - Graphs

Kruskal’s Algorithm Example

Example (2 < 6)

minimum weight: 2(d , e), (f , g)

T = {(e, g), (d , f ), (d , e)}i ← 3

Page 275: Discrete Mathematics - Graphs

Kruskal’s Algorithm Example

Example (3 < 6)

minimum weight: 2(f , g) forms a cycle

minimum weight: 3(c, e), (c, g), (d , g)(d , g) forms a cycle

T = {(e, g), (d , f ), (d , e), (c, e)}i ← 4

Page 276: Discrete Mathematics - Graphs

Kruskal’s Algorithm Example

Example (3 < 6)

minimum weight: 2(f , g) forms a cycle

minimum weight: 3(c, e), (c, g), (d , g)(d , g) forms a cycle

T = {(e, g), (d , f ), (d , e), (c, e)}i ← 4

Page 277: Discrete Mathematics - Graphs

Kruskal’s Algorithm Example

Example (3 < 6)

minimum weight: 2(f , g) forms a cycle

minimum weight: 3(c, e), (c, g), (d , g)(d , g) forms a cycle

T = {(e, g), (d , f ), (d , e), (c, e)}i ← 4

Page 278: Discrete Mathematics - Graphs

Kruskal’s Algorithm Example

Example (3 < 6)

minimum weight: 2(f , g) forms a cycle

minimum weight: 3(c, e), (c, g), (d , g)(d , g) forms a cycle

T = {(e, g), (d , f ), (d , e), (c, e)}i ← 4

Page 279: Discrete Mathematics - Graphs

Kruskal’s Algorithm Example

Example (4 < 6)

T = {(e, g), (d , f ), (d , e),(c, e), (b, e)}i ← 5

Page 280: Discrete Mathematics - Graphs

Kruskal’s Algorithm Example

Example (4 < 6)

T = {(e, g), (d , f ), (d , e),(c, e), (b, e)}i ← 5

Page 281: Discrete Mathematics - Graphs

Kruskal’s Algorithm Example

Example (5 < 6)

T = {(e, g), (d , f ), (d , e),(c, e), (b, e), (a, b)}i ← 6

Page 282: Discrete Mathematics - Graphs

Kruskal’s Algorithm Example

Example (5 < 6)

T = {(e, g), (d , f ), (d , e),(c, e), (b, e), (a, b)}i ← 6

Page 283: Discrete Mathematics - Graphs

Kruskal’s Algorithm Example

Example (6 ≮ 6)

total weight: 17

Page 284: Discrete Mathematics - Graphs

Prim’s Algorithm

Prim’s algorithm

1 i ← 1, v1 ∈ V , P = {v1}, N = V − {v1}, T = ∅2 for 1 ≤ i ≤ n − 1:

P = {v1, v2, . . . , vi}, T = {e1, e2, . . . , ei−1}, N = V − Pselect a node vi+1 ∈ N such that for a node x ∈ Pe = (x , vi+1) /∈ T , wt(e) is minimalP ← P + {vi+1}, N ← N − {vi+1}, T ← T + {e}

3 i ← i + 1

i = n ⇒: the subgraph G containing the edgese1, e2, . . . , en−1 is a minimum spanning treei < n ⇒ go to step 2

Page 285: Discrete Mathematics - Graphs

Prim’s Algorithm

Prim’s algorithm

1 i ← 1, v1 ∈ V , P = {v1}, N = V − {v1}, T = ∅2 for 1 ≤ i ≤ n − 1:

P = {v1, v2, . . . , vi}, T = {e1, e2, . . . , ei−1}, N = V − Pselect a node vi+1 ∈ N such that for a node x ∈ Pe = (x , vi+1) /∈ T , wt(e) is minimalP ← P + {vi+1}, N ← N − {vi+1}, T ← T + {e}

3 i ← i + 1

i = n ⇒: the subgraph G containing the edgese1, e2, . . . , en−1 is a minimum spanning treei < n ⇒ go to step 2

Page 286: Discrete Mathematics - Graphs

Prim’s Algorithm

Prim’s algorithm

1 i ← 1, v1 ∈ V , P = {v1}, N = V − {v1}, T = ∅2 for 1 ≤ i ≤ n − 1:

P = {v1, v2, . . . , vi}, T = {e1, e2, . . . , ei−1}, N = V − Pselect a node vi+1 ∈ N such that for a node x ∈ Pe = (x , vi+1) /∈ T , wt(e) is minimalP ← P + {vi+1}, N ← N − {vi+1}, T ← T + {e}

3 i ← i + 1

i = n ⇒: the subgraph G containing the edgese1, e2, . . . , en−1 is a minimum spanning treei < n ⇒ go to step 2

Page 287: Discrete Mathematics - Graphs

Prim’s Algorithm Example

Example (initialization)

i ← 1

P = {a}N = {b, c, d , e, f , g}T = ∅

Page 288: Discrete Mathematics - Graphs

Prim’s Algorithm Example

Example (initialization)

i ← 1

P = {a}N = {b, c, d , e, f , g}T = ∅

Page 289: Discrete Mathematics - Graphs

Prim’s Algorithm Example

Example (1 < 7)

T = {(a, b)}P = {a, b}N = {c, d , e, f , g}i ← 2

Page 290: Discrete Mathematics - Graphs

Prim’s Algorithm Example

Example (1 < 7)

T = {(a, b)}P = {a, b}N = {c, d , e, f , g}i ← 2

Page 291: Discrete Mathematics - Graphs

Prim’s Algorithm Example

Example (2 < 7)

T = {(a, b), (b, e)}P = {a, b, e}N = {c, d , f , g}i ← 3

Page 292: Discrete Mathematics - Graphs

Prim’s Algorithm Example

Example (2 < 7)

T = {(a, b), (b, e)}P = {a, b, e}N = {c, d , f , g}i ← 3

Page 293: Discrete Mathematics - Graphs

Prim’s Algorithm Example

Example (3 < 7)

T = {(a, b), (b, e), (e, g)}P = {a, b, e, g}N = {c, d , f }i ← 4

Page 294: Discrete Mathematics - Graphs

Prim’s Algorithm Example

Example (3 < 7)

T = {(a, b), (b, e), (e, g)}P = {a, b, e, g}N = {c, d , f }i ← 4

Page 295: Discrete Mathematics - Graphs

Prim’s Algorithm Example

Example (4 < 7)

T = {(a, b), (b, e), (e, g), (d , e)}P = {a, b, e, g , d}N = {c, f }i ← 5

Page 296: Discrete Mathematics - Graphs

Prim’s Algorithm Example

Example (4 < 7)

T = {(a, b), (b, e), (e, g), (d , e)}P = {a, b, e, g , d}N = {c, f }i ← 5

Page 297: Discrete Mathematics - Graphs

Prim’s Algorithm Example

Example (5 < 7)

T = {(a, b), (b, e), (e, g),(d , e), (f , g)}P = {a, b, e, g , d , f }N = {c}i ← 6

Page 298: Discrete Mathematics - Graphs

Prim’s Algorithm Example

Example (5 < 7)

T = {(a, b), (b, e), (e, g),(d , e), (f , g)}P = {a, b, e, g , d , f }N = {c}i ← 6

Page 299: Discrete Mathematics - Graphs

Prim’s Algorithm Example

Example (6 < 7)

T = {(a, b), (b, e), (e, g),(d , e), (f , g), (c, g)}P = {a, b, e, g , d , f , c}N = ∅i ← 7

Page 300: Discrete Mathematics - Graphs

Prim’s Algorithm Example

Example (6 < 7)

T = {(a, b), (b, e), (e, g),(d , e), (f , g), (c, g)}P = {a, b, e, g , d , f , c}N = ∅i ← 7

Page 301: Discrete Mathematics - Graphs

Prim’s Algorithm Example

Example (7 ≮ 7)

total weight: 17

Page 302: Discrete Mathematics - Graphs

References

Required Reading: Grimaldi

Chapter 13: Optimization and Matching

13.1. Dijkstra’s Shortest Path Algorithm13.2. Minimal Spanning Trees:The Algorithms of Kruskal and Prim