dm22s Graphs
dm22s Graphs
Ver.
1
Chapter Summary
Graphs and Graph Models
Graph Terminology and Special Types of Graphs
Representing Graphs and Graph Isomorphism
Connectivity
Euler and Hamiltonian Graphs
Shortest-Path Problems
Planar Graphs
Graph Coloring
2
Section
3
§10.1: Graphs and Graph Models
Introduction to Graphs
Graph Taxonomy
Graph Models
4
What are Graphs?
Discrete structure consisting of vertices and edges
vertex
edge
5
Simple Graphs
each edge connects two different vertices
No two edges connect the same pair of vertices
No loop (edge that connects a vertex to itself)
6
Example of a Simple Graph
Let V be the set of states in the far-southeastern U.S.:
V={FL, GA, AL, MS, LA, SC, TN, NC}
Let E={{u,v}|u adjoins v}
TN NC
GA
LA FL
7
Multigraphs
There may be multiple edges connecting the same two
vertices.
When m different edges connect the vertices u and v, we
say that {u, v} is an edge of
an edge of
multiplicity m. multiplicity 2
8
Pseudographs
Like a multigraph, but may include loops.
Loop: an edge that connects a vertex to itself
e.g., nodes are campsites in a loop
national park, edges are hiking
trails through the woods.
9
Directed Graphs
A directed graph (or digraph) G=(V,E) consists of a
nonempty set V of vertices (or nodes) and a set E of edges
(or arcs).
Each edge is associated with an ordered pair of vertices.
The edge associated with (u, v) is v
u
said to start at u and end at v.
an ordered pair
10
Simple Directed Graph
A directed graph that has no loops and no multiple edges.
v
u
a b
c
not a simple
directed graph
11
Directed Multigraphs
Like directed graphs, but there may be more than one arc
from a vertex to another.
When there are m directed
edges from vertices u to v,
we say that is an
edge of multiplicity m.
12
Graph Models: Computer Networks
build a graph model: use an appropriate type of graph to
capture the important features of the application.
We illustrate this process using graph models of different
types of computer networks.
In all these graph models
vertices represent data centers
edges represent communication links
13
Computer Networks: Simple Graph
If we are only concerned whether two data centers are connected by a
communications link (and not how many links there may be), we
use a simple graph.
all communications links work in both directions.
14
Computer Networks: Multigraph
If we care about the number of links between data centers,
we use a multigraph.
15
Computer Networks: Pseudograph
To model a computer network with diagnostic links at data
centers, we use a pseudograph, as loops are needed.
16
Computer Networks: Directed Multigraph
To model a network with multiple one-way links, we use a directed
multigraph.
allows both
18
Other Applications of Graphs
graph theory can be used in models of:
Social networks
Communications networks
Information networks
Software design
Transportation networks
Biological networks
It’s a challenge to find a subject to which graph theory has not yet been
applied.
19
Graph Models: Social Networks
In a social network
vertices represent individuals or organizations
edges represent (different kinds of) relationships between them.
Useful graph models of social networks:
friendship graphs
collaboration graphs
influence graphs
20
Friendship Graph
undirected graphs where two people are connected if they
are friends (in the real world, on Facebook, or in a particular
virtual world, and so on.)
21
Collaboration Graphs
undirected graphs where two people are connected if they
collaborate in a specific way
Jason Statham
The Rock
Vin Diesel
22
Influence Graphs
directed graphs where there is an edge from one person to
another if the first person can influence the second person
Your Dad
You
23
Examples of Collaboration Graphs
The Hollywood graph models the collaboration of actors in
films.
represent actors by vertices
connect two vertices if the actors they represent have appeared in
the same movie.
We will study the Hollywood Graph in Sec. 10.4 when we
discuss Kevin Bacon numbers.
24
Academic Collaboration Graph
models the collaboration of researchers who have jointly
written a paper in a particular subject.
represent researchers in a particular academic discipline using
vertices.
connect two vertices if the researchers they represent have
coauthored a paper.
In Sec. 10.4, We will study the academic collaboration graph
for mathematicians when we discuss Erd s numbers
25
Applications to Information Networks
Graphs can be used to model different types of networks that link
different types of information.
In a web graph, web pages vertices, and links directed edges.
A web graph models the WWW at a particular time.
In a citation network:
Research papers in a particular discipline are represented by vertices.
When a paper cites a second paper as a reference, there is an edge from the
vertex representing this paper to the vertex representing the second paper.
26
Transportation Graphs
Graph models are extensively used in the study of transportation
networks.
Airline networks (directed multigraphs)
airports vertices
each flight a directed edge
Road networks
vertices represent intersections and edges represent roads.
undirected edges represent two-way roads and directed edges represent one-
way roads.
27
Software Design Applications
A top-down approach divides a system into modules, each
performing a specific task.
a module dependency graph represents the dependency between
these modules.
vertices represent software modules
there is an edge from one module to another if the second module depends
on the first
These dependencies need to be understood before coding can be
done.
28
Module Dependency Graph: An Example
31
Biological Applications: Protein Interaction Network
vertices represent proteins and vertices are connected by an edge if
the proteins they represent interact.
Protein interaction graphs can be huge (more than vertices
and more than edges)
often split into smaller graphs,
called modules, which represent
the interactions between proteins
involved in a particular function.
a module of the protein interaction graph of
proteins that degrade RNA in a human cell.
32
Section
33
§10.2: Graph Terminology and Special Types of
Graphs
Basic Terminology
Some Special Types of Graphs
Bipartite Graphs
Bipartite Graphs and Matchings
Some Applications of Special Types of Graphs
New Graphs from Old
34
Terminology: Adjacency
Let G be an undirected graph. Let e = {u,v} be an edge of G.
Then we say:
e v
u, v are adjacent (neighbors; connected). u
Edge e is incident with vertices u and v.
Edge e connects u and v.
Vertices u and v are endpoints of edge e.
35
Terminology: Neighborhood
Let G=(V, E) be an undirected graph, vV a vertex, A is a
subset of V.
The neighborhood of v, denoted by N(v), is the set of all
neighbors of v
N(A) is the set of all vertices in G that are adjacent to at least
one vertex in A.
36
Degree of a Vertex
Let G=(V, E) be an undirected graph, vV a vertex.
The degree of v, deg(v), is its number of incident edges.
(Except that any self-loops are counted twice.)
A vertex with degree is isolated.
A vertex of degree is pendant.
37
Degrees and Neighborhoods: Example 1
What are the degrees and neighborhoods
of the vertices in the graph G?
Solution:
deg(a) = 2, deg(b) = deg(c) = deg(f) = 4,
deg(d) = 1, deg(e) = 3, deg(g) = 0.
N(a) = {b, f }, N(b) = {a, c, e, f }, N(c) = {b, d, e, f }, N(d) = {c}, N(e) = {b, c ,
f}, N(f) = {a, b, c, e}, N(g) = .
38
Degrees and Neighborhoods: Example 2
What are the degrees and neighborhoods
of the vertices in the graph H?
39
Handshaking Theorem
Let G=(V, E) be an undirected (simple, multi-, or pseudo-)
graph with m edges. Then
deg(v) 2m
vV
Each edge contributes
1 degree at each end
degree+ degree+
40
Handshaking Theorem: Example 1
How many edges are there in a graph with 10 vertices of
degree six?
Solution:
Because the sum of the degrees of the vertices is 6 10 = 60,
the handshaking theorem tells us that 2m = 60.
So the number of edges m = 30.
41
Handshaking Theorem: Example 2
If a graph has 5 vertices, can each vertex have degree 3?
Solution:
This is not possible by the handshaking theorem, because
the sum of the degrees of the vertices 3 5 = 15 is odd.
42
Theorem 2
Theorem 2: An undirected graph G = (V, E) with m edges has an even
number of vertices of odd degree.
Proof: Let V1 be the vertices of even degree and V2 be the vertices of odd
degree in G. Then
must be even
even
must be even
Because all vertices in V2 are of
odd degrees, there must be an
even number of such vertices.
43
Directed Adjacency
Let G be a directed (possibly multi-) graph, and let e = (u, v) be an
edge of G.
Then we say: e v
u is adjacent to v, v is adjacent from u u
e comes from u, e goes to v.
e connects u to v, e goes from u to v
the initial vertex of e is u
the terminal vertex of e is v
44
Directed Degree
Let G be a directed graph, v a vertex of G.
The in-degree of v, deg(v), is the number of edges going to v.
The out-degree of v, deg(v), is the number of edges coming from v.
The degree of v, deg(v)deg(v)+deg(v), is the sum of v’s in-
degree and out-degree.
in-degree = 2
out-degree = 3
45
In-Degree/Out-Degree Example
deg−(a) = 2, deg−(b) = 2,
deg−(c) = 3, deg−(d) = 2,
deg−(e) = 3, deg−(f) = 0.
deg+(a) = 4, deg+(b) = 1,
deg+(c) = 2, deg+(d) = 2,
deg+ (e) = 3, deg+(f) = 0.
46
Directed Handshaking Theorem
Let G=(V, E) be a directed (possibly multi-) graph. Then:
vV vV
47
Special Graph Structures
Special cases of undirected graph structures:
Complete graphs Kn
Cycles Cn
Wheels Wn
n-Cubes Qn
Bipartite graphs
Complete bipartite graphs Km,n
48
Complete Graphs
For any nN, a complete graph on n vertices, Kn, is a simple graph
with n vertices that contains exactly one edge between each pair of
distinct vertices.
K1 K2 K3 K4 K5 K6
49
Cycles
A cycle Cn for n ≥ consists of n vertices v , v , , vn, and
edges {v , v }, {v , v } , , {vn- , vn}, {vn, v }.
C3 C4 C5 C6 C7 C8
W3 W4 W5 W6 W7 W8
Q4
Number of edges: Exercise to try!
52
Bipartite Graphs
A simple graph G=(V, E) is bipartite if we can find a way to partition
V into two disjoint subsets V1 and V2 such that every edge connects a
vertex in V1 and a vertex in V2.
V1 V2
In other words, there are • •
no edges which connect • •
• •
two vertices in V1 or in V2. • •
•
53
It’s Not Always Easy to Identify a Bipartite
Graph
This is a bipartite
graph
54
Bipartite Graph and Coloring
an equivalent definition of a bipartite graph: we can find a way to assign
either red or blue to each vertex so that no two adjacent vertices are
assigned the same color.
G is bipartite
55
Bipartite Graph Example 1
Example: Show that C6 is bipartite.
Solution: We can partition the vertex set into V1 = {v1, v3, v5} and V2
= {v2, v4, v6} so that every edge of C6 connects a vertex in V1 and
another vertex in V2.
v1
v6 v2
v5 v3
v4
C6
56
Bipartite Graph Example 2
Example: Show that C3 is not bipartite.
Proof: If we divide the vertex set of C3 into two
nonempty sets, one of the two must contain two
vertices.
C3
But in C3 every vertex is connected to every other vertex.
Therefore, the two vertices in the same partition are
connected.
Hence, C3 is not bipartite.
57
Complete Bipartite Graphs
A complete bipartite graph Km,n is a graph that has its vertex set
partitioned into two subsets V1 of size m and V2 of size n such that
there is an edge from every vertex in V1 to every vertex in V2.
K2,3 K3,3
K3,5 K2,6
58
Server Pod Used by Facebook
A spine/leaf topology
K4,48
59
Special Graphs in Computer Network
Architecture
Some local area networks use a star topology, which is
a complete bipartite graph K1,n .
All devices are connected to a central control device.
Other local networks are based on a ring topology,
where each device is connected to exactly two others
using Cn.
Messages may be sent around the ring.
Others use a Wn–based topology, combining the
features of a star topology and a ring topology.
60
Special Graph in Parallel Processing System
in a parallel processing system, processors need to be
interconnected as one processor may need the output
generated by another.
The n-dimensional hypercube, or n-cube, Qn,
is a common way to connect processors in
parallel, e.g., Intel Hypercube.
Another common method is the mesh
network, illustrated here for processors.
61
Subgraphs
A subgraph of a graph G=(V,E) is a graph H=(W,F) where W
V and F E.
G H
A subgraph H of G is a proper subgraph of G if H ≠ G
62
Induced Subgraph
Let G = (V, E) be a simple graph.
The subgraph induced by a subset of vertices W V is a graph (W, F)
such that {u, v} F if and only if {u, v} E and {u, v} W.
Here we show K5 and the
subgraph induced by
W = {a, b, c, e}.
63
Subgraph vs. Induced Subgraph
For all u, vW, if {u, v} E then {u, v} must be in the induced
subgraph (not necessarily in a subgraph)
a a
b b
and
but
64
Bipartite Graphs and Matchings
Bipartite graphs are used to model applications that involve
matching the elements of one set to elements in another.
Job assignments - vertices represent the jobs and the employees,
edges link employees with those jobs they have been trained to do.
A common goal is to
match jobs to employees
so that the most jobs are
done. ( matching)
65
Matching Problem is Not Easy
Allen Bob Christ David
67
Graph Unions
The union of two simple graphs and
is the simple graph .
b c a b c a b c
a
d e d f d e f
68
Section
69
§10.3: Representing Graphs and Graph
Isomorphism
Adjacency Lists
Adjacency Matrices Graph Representation
Incidence Matrices
Isomorphism of Graphs
70
Adjacency Lists
A table with row per vertex, listing its adjacent vertices.
b Adjacent
a
Vertex Vertices
a b, c
c d b a, c, e, f
e
c a, b, f
f d
e b
For graphs with no f c, b
multiple edges
71
Directed Adjacency Lists
row per node, listing the terminal nodes of each edge
incident from that node.
Adjacent
a b Vertex Vertices
a
d b a, e
c e c a, b, f
f d
e
For graphs with no f b
multiple edges
72
Adjacency Matrices
Matrix A=[aij], where aij is if {vi, vj} is an edge of G,
otherwise. a b c d
a b a 0 1 1 1
b 1 0 1 0
c c 1 1 0 0
d
d 1 0 0 0
can represent simple graph (here) and directed graph (later)
73
Adjacency Matrix Example
The ordering of
vertices is a, b, c, d.
74
Adjacency List vs. Adjacency Matrix
A graph can be sparse (has few edges relatively to the total
number of possible edges) or dense (on the other hand).
When a graph is sparse, it is much more efficient to
represent the graph using an adjacency list than an
adjacency matrix.
For a dense graph, an adjacency matrix is preferable.
75
For Loops and Multiple Edges
A loop at the vertex vi is represented by a at the (i, i)th position of
the matrix.
When multiple edges are allowed, the (i, j)th entry equals the
number of edges connecting vi and vj.
the (i, i)th entry > if multiple loops are present
a pseudograph
76
Directed Adjacency Matrices
For a directed graph G = (V, E), the matrix has a in its (i, j)th
position if there is an edge from vi to vj.
When there is an edge from vi to vj, there may not be an edge from vj
to vi.
Thus the adjacency matrix for a directed graph does not have to be
symmetric.
To represent directed multigraphs, the value of aij is the number of
edges connecting vi to vj.
77
Incidence Matrices
An n m matrix M=[mij], where n = |V| and m = |E|
mij = 1 if edge ej is incident with vi
e1 e1 e2 e3 e4 edges
a b
a 1 1 1 0
e2 1
e4 e3 b
0 0 1
c
d c 0 1 0 1
d
0 0 1 0
vertices
78
Incidence Matrix for Simple Graph
e1 e2 … e6
v1
v2
:
v5
+)
79
Incidence Matrix for Pseudograph
e1 e2 … e8
v1
v2
:
v5
+)
80
Isomorphism of Graphs
Graphs with the same structure
a v1
b v2
have the same
and
structure?
c v4
d v3
a d
c
b
81
Graph Isomorphism: Formal Definition
Simple graphs G =(V , E ) and G =(V , E ) are isomorphic iff
a bijection f:V V such that a, bV , a and b are
adjacent in G iff f(a) and f(b) are adjacent in G .
f is called an isomorphism.
Two simple graphs that are not isomorphic are called
nonisomorphic.
82
Graph Isomorphism: Example
u1
Show that the graphs G =(V, E) u2
and H = (W, F) are isomorphic.
The function f with f(u1) = v1,
u3 u4
f(u2) = v4, f(u3) = v3, and f(u4) = v2
is a one-to-one correspondence G
between V and W.
v1
Adjacent vertices in G are u1 and u2, v2
v1 v4
u1 and u3, u2 and u4, and u3 and u4.
v3
v1 v3 v4 v2 v3 v2 H v4
83
Determining Graph Isomorphism
It is difficult to determine whether two simple graphs are isomorphic
using brute force (n! possible one-to-one correspondences).
graph invariant is a property that should be preserved by
isomorphism
We try to find a graph invariant that only one of the two graphs has.
many different useful graph invariants can be used to distinguish
nonisomorphic graphs (number of vertices, number of edges, and
degree sequence)
84
Some graph Invariants under Isomorphism
Necessary but not sufficient conditions for G =(V , E ) to be
isomorphic to G =(V , E ):
|V |=|V |, |E |=|E |.
The number of vertices with degree n is the same in both
graphs for each n.
For every proper subgraph g of one graph, there is a
proper subgraph of the other graph that is isomorphic to g.
85
Isomorphism Example
If isomorphic, label the nd graph to show the isomorphism.
Otherwise, identify the difference.
d * Same # of vertices
b
b a
a * Same # of edges
d c
e
f * Same # of vertices of
c
e every degree
f
86
Are These Isomorphic?
If isomorphic, label the nd graph to show the isomorphism.
Otherwise, identify the difference.
a * Same # of vertices
b
* Same # of edges
d
* Different # of vertices of
c e degree 2! (1 vs. 3)
87
Determining Graph Isomorphism: Example 1
deg =
Both graphs have
vertices and edges.
They also both have
vertices of degree and
deg =
of degree .
deg(a) = in G, a must correspond to t, u, x, or y in H
each of these vertices is adjacent to another vertex of degree two in H,
which is not true for a in G.
Nonisomorphic!
88
Determining Graph Isomorphism: Example 2
Both graphs have
vertices and edges.
They also both have
vertices of degree and
of degree .
The subgraphs of G and H consisting of all the vertices of degree two
and the edges connecting them are isomorphic.
So, it is reasonable to try to find an isomorphism f.
89
The function f with f(u1) = v6, f(u2) = v3, f(u3) = v4, and f(u4) = v5 ,
f(u5) = v1, and f(u6) = v2 is a one-to-one correspondence
between G and H.
Can use the adjacency matrices of G and H to verify that f is an
isomorphism.
90
Algorithms for Graph Isomorphism
The best known algorithms have exponential worst-case time
complexity (in the number of vertices).
Some algorithms have linear average-case time complexity.
a public domain program, NAUTY, determines in < sec. whether
two graphs with vertices are isomoprhic.
Graph isomorphism is a problem of special interest because it is one
of a few NP problems not known to be either tractable or NP-
complete.
91
Applications of Graph Isomorphism
chemists use molecular graphs
to model chemical compounds.
Vertices represent atoms and
edges represent chemical bonds.
When a new compound is synthesized, a database of molecular
graphs is checked to determine whether the graph representing the
new compound is isomorphic to the graph of a compound that this
already known.
92
Electronic Circuits
Electronic circuits are modeled as graphs in which
the vertices represent components
the edges represent connections between components
Graph isomorphism is the basis for
verifying whether a particular circuit layout corresponds to the
design’s original schematics.
determining whether a chip from one vendor includes the
intellectual property of another vendor.
93
Section
94
§10.4: Connectivity
Paths
Connectedness in Undirected Graphs
Vertex Connectivity and Edge Connectivity
Connectedness in Directed Graphs
Paths and Isomorphism
Counting Paths between Vertices
95
Path
In an undirected graph, a path of length n from u to v is a
sequence of n adjacent edges going from vertex u to vertex v.
A path is a circuit if u = v.
A path is simple if it contains no edge more than once.
96
Path Definition
A path of length n from u to v
e1 e2 en
x0 = u x1 x2 xn-1 xn = v
When the graph is simple, we denote this path by its vertex sequence
x0, x1, … , xn
The path or circuit is said to pass through the vertices x1, x2, …, xn-1
and traverse the edges e1, …, en. excluding u and v
97
Circuits and Simple Paths
This graph is simple
a b b, f, c, a, b is a circuit
b, c, a, b, e is a simple path
c d
e b, c, a, b, c, f is not a
f simple path
98
More Examples on Paths
a, d, c, f, e is a simple path of
length .
d, e, c, a is not a path because
e is not connected to c.
b, c, f, e, b is a circuit of
length .
a, b, e, d, a, b is a path of length , but it is not a simple
path.
99
Paths in Directed Graphs
Same as in undirected graphs, but the path must go in the
direction of the arrows.
a b
c, f, b, e is a simple path
c d f, b, c, a is not a path
e
f
100
Degrees of Separation
In an acquaintanceship graph, two
people are neighbors if they know
one another.
There is a path between two
people if there is a chain of people Some have speculated that
almost every pair of people in
linking these people the world are linked by a small
Here is a chain of six people chain of no more than six (Six
Degrees of Separation).
linking Kamini and Ching.
101
Erdős numbers
Paul Erdős
103
Bacon Numbers Kevin Bacon
104
Connectedness in Undirected Graphs
An undirected graph is connected iff there is
a path between every pair of distinct
vertices in the graph.
105
Connectedness: Examples
not connected
connected
106
Connected Components
A connected component: a connected subgraph that is not a proper
subgraph of another connected subgraph. (a maximal connected
subgraph)
A graph G that is not connected has two or more connected
components
connected components
are disjoint
G is the union of these
connected components.
107
How Connected is a Graph?
Sometimes a graph is connected, but a
removal of one vertex or an edge from
this graph will make it not connected.
We want to know how robust a graph is
in terms of connectedness.
108
Cut Vertex and Cut Edge
If removing a vertex (and all incident edges) from a
connected graph produces a subgraph that is not connected,
this vertex is called a cut vertex.
109
Cut Vertex/Edge Example
Cut vertices:
a d f g
b, c, and e
Cut edges:
b c e h
(a, b) and (c, e)
110
Vertex Connectivity
No all graphs have cut vertices K5 K4
Removing any vertex from Kn Kn-1
Nonseparable graphs
May need to remove more vertices/edges
Using the min. number of needed vertices/ edges as a
measure of graph connectivity
111
Set of vertices
112
Vertex Connectivity Examples
a d f g
G1 κ(G1) =
b c e h
b c d
113
κ(G) for Complete Graphs
A complete graph should also have a vertex cut
However, removing any subset from it still a complete graph
Redefine κ(G): the minimum number of vertices that must be
removed from G to
either disconnect G
or produce a graph with a single vertex
Therefore, κ(Kn) = n −
if G has n vertices, ≤ κ(G) ≤ n − (in general)
114
k-Connected Graph
a graph G is k-connected (or k-vertex-connected), if κ(G) ≥ k
That means we have to remove at least k vertices to disconnect G (or
reduce it to a graph with vertex)
if G is a k-connected graph, then G is a j-connected graph for all j
with ≤ j ≤ k.
b c d
-connected
a also -connected
g f e
115
Set of edges
116
Edge Connectivity Examples
a d f g
G1 (G1) =
b c e h
b c d
117
Inequalities of Vertex/Edge Connectivity
Removing all the neighbors of a vertex will disconnect this vertex
from all other vertices
So κ(G) minvV deg(v)
Removing all the edges incident with a vertex will disconnect this
vertex from all other vertices
So (G) minvV deg(v) a d
Removing one vertex may
remove more than one edge c
b e
κ(G) (G)
118
Directed Connectedness
A directed graph is strongly connected iff there is a directed
path from a to b for any two vertices a and b.
It is weakly connected iff the underlying undirected graph
(i.e., with edge directions removed) is connected.
Note strongly implies weakly but not vice-versa.
119
Strongly Connectedness Examples
b
a b Strongly connected?
No! There is no path
c e from e to any others
f
Weakly connected?
Yes! The underlying
undirected graph is
connected
120
Directed Connectedness: Examples
121
Strongly Connected Component
the maximal strongly connected subgraphs are called the
strongly connected components or strong components.
these subgraphs are
strongly connected but
not contained in larger
strongly connected
subgraphs
the meaning of ‘maximal’
122
Paths & Isomorphism
Note that connectedness and the existence of a circuit
or simple circuit of length k are also graph invariants with
respect to isomorphism.
* Same number of vertices
u1 v1
* Same number of edges
u6 u2 v6 v2
* Same number of vertices
of degrees 2 and 3.
u5 u3 v5 v3 * H has simple circuit of length 3,
G u4 H v4 but G has not
123
Counting Paths with Adjacency Matrices
Let A be the adjacency matrix of graph G.
The number of paths of length k from vi to vj is equal to (Ak)i,j. (The
notation (M)i,j denotes mi,j where [mi,j] = M.)
a a 0 1 1 0 8 0 0 8
b 1 1
d 0
0 0 8 8 0
A A4
c 1 0 0 1 0 8 8 0
b
d 0 1 1 0
c 8 0 0 8
The number of paths of length 4 from d to a
124
Understanding Why
a 01 1 0 0 1 1 0 2 0 0 2
b 1 0 0 1 1 0 0 1 0 2 2 0
A A = A
2
c 1 0 0 1 1 0 0 1 0 2 2 0
d 0 1 1 0 0 1 1 0 2 0 0 2
(da) 0 (aa) 0 = (da) 0 a
(db) 1 (ba) 1 = (da) 1 d
(dc) 1 (ca) 1 = (da) 1
+ (dd) 0 (da) 0 = (da) 0
b
(d) (a) 2 c
125
Understanding Why (cont)
2 0 0 2 0 1 1 0 0 4 4 0
0 2 2 0 1 0 0 1 4 0 0 4
A2 A = A
3
0 2 2 0 1 0 0 1 4 0 0 4
2 0 0 2 0 1 1 0 0 4 4 0
(d a) 2 (aa) 0 = (da) 0
a
(d b) 0 (ba) 1 = (da) 0 d
(d c) 0 (ca) 1 = (da) 0
+ (d d) 2 (da) 0 = (da) 0 b
(d) (a) 0 c
of length 2 126
Counting Paths between Vertices: Example
How many paths of length four are there from a to d in the graph G?
a
d
G A=
b
c adjacency matrix of G
a, b, a, b, d a, b, a, c, d
A4 = a, b, d, b, d a, b, d, c, d
a, c, a, b, d a, c, a, c, d
a, c, d, b, d a, c, d, c, d
127
Section
128
§10.5: Euler and Hamiltonian Graphs
Euler Paths and Circuits
Hamilton Paths and Circuits
Applications of Hamilton Circuits
129
Euler Paths and Circuits
The town of K nigsberg, Prussia (now Kalingrad, Russia) was
divided into four sections by the branches of the Pregel river.
In the th century seven bridges
connected these regions.
People wondered whether
it was possible to follow a
path that crosses each bridge
exactly once and returns to
the starting point. The 7 Bridges of Kӧnigsberg
130
And the answer is … Leonard Euler
(1707-1783)
Multigraph
Model of the
A A D
D Bridges of
Kӧnigsberg
B B
131
Euler Circuit in a Graph
A path is an Euler circuit in a graph G if
It is a simple path (containing no edge more than once)
It contains every edge of G.
It is a circuit (beginning with and ending at the same vertex.)
a d
Is a, b, d, c, a an Euler circuit? Why?
Is a, b, d, c, a, d an Euler circuit?
Is there an Euler circuit? b
c
132
A circuit is also a path.
Euler Path in a Graph An Euler circuit is not an Euler path.
134
Necessary Conditions for Euler Circuit / Euler
Path
Every vertex in G
G has an Euler circuit
is of even degree
135
Necessary Condition for Euler Circuit
Suppose that an Euler circuit begins with a vertex a
a b c x a
deg(a)+ deg(b)+ deg(x)+
deg(b)+ deg(c)+ deg(x)+ deg(a)+
deg(c)+
deg(a) must Each time the circuit passes through a vertex it
be even contributes two (in & out) to the vertex’s degree
a b c x y
deg(a)+ deg(y)+
Each time the path passes through a vertex
it contributes two to the vertex’s degree
deg(a) must deg(y) must
be odd be odd
a graph with an Euler path has exactly two vertices of odd degree.
137
Sufficient Conditions for Euler Circuit / Euler Path
Every vertex in G is
G has an Euler circuit
of even degree
We prove it by showing
how to construct one.
138
Sufficient Condition for Euler Circuit (1/5)
Suppose that G is a connected multigraph with ≥ vertices, all of even
degree.
Let x0 = a be a vertex of even degree.
Choose an edge {x0 x1 a
{x0 x1 {x1 x2 {xn-1 xn a b
c d
We reach a vertex for which all f
incident edges are included
e
139
Sufficient Condition for Euler Circuit (2/5)
a (i.e., a circuit)
a
140
Sufficient Condition for Euler Circuit (3/5)
If not all of the edges have been used, construct subgraph H from G by
deleting the edges already used and vertices not incident with any
remaining edges
a b
c d
G H
c d
f
e
e
141
Sufficient Condition for Euler Circuit (4/5)
Every vertex in H must have even degree because
all the vertices in G have even degree and
for each vertex in H, either or pairs of edges incident with this vertex have
been deleted. c d
Beginning with the shared vertex
construct a path (circuit) ending in
the same vertex (as was done before).
e
Then splice this new circuit into
the original circuit.
In the example, we end up with the circuit a, f, c, d, e, c, b, a.
142
Sufficient Condition for Euler Circuit (5/5)
Continue this process until all edges have been used.
This produces an Euler circuit since every edge is included
and no edge is included more than once.
Similar reasoning can be used to show that a graph with
exactly two vertices of odd degree must have an Euler path
connecting these two vertices of odd degree
143
Algorithm for Constructing an Euler Circuit
In our proof we developed an algorithm
procedure Euler(G: connected multigraph with all vertices of even degree)
circuit := a circuit in G beginning at an arbitrarily chosen vertex with edges successively added to
form a path that returns to this vertex.
H := G with the edges of this circuit removed
while H has edges
subciruit := a circuit in H beginning at a vertex in H that also is an endpoint of an edge in circuit.
H := H with edges of subciruit and all isolated vertices removed
circuit := circuit with subcircuit inserted at the appropriate vertex.
return circuit{circuit is an Euler circuit}
144
Theorem for Euler Circuit
A connected multigraph has an Euler circuit iff each vertex
has even degree.
C
Is there an Euler circuit?
A D
145
Theorem of Euler Path
A connected multigraph has an Euler path (but not an Euler circuit)
iff it has exactly vertices of odd degree.
C C
A D A D
B B
Is there an How about this? And this?
Euler path?
146
How to Find an Euler Path?
We have exactly two vertices of odd degree
One of them must be the starting vertex
The other must be the ending vertex
147
Euler Circuits and Paths: Examples
a
a b a g f e b
f
c c d g c
d b
e
an Euler path: an Euler path: b, a, g, d
d, a, b, c, d, b. f, e, d, c, g, b, c, f, d No Euler path
148
Applications of Euler Paths and Circuits
Finding a path or circuit that traverses each
street in a neighborhood,
road in a transportation network,
connection in a utility grid,
link in a communications network.
Other applications are found in the
layout of circuits,
network multicasting,
molecular biology, where Euler paths are used in the sequencing of DNA.
149
Hamilton Circuit in a Graph
A path is a Hamilton circuit in a graph G if
It is a circuit (beginning with and ending at the same vertex.)
It traverses each vertex in G exactly once.
a
a, b, d, c is not a Hamilton circuit. Why?
d
b
c
150
Hamilton Path in a Graph
A path is a Hamilton path in a graph G if
It is not a circuit (beginning with and ending at different
vertices.)
It traverses each vertex in G exactly once.
Is a, b, d, c a Hamilton path? a d
b
c
151
Hamilton Circuit: An Example
need not traverse
every edge
William Rowan Hamilton
(1805- 1865)
152
Hamilton Paths and Circuits: Examples
a b a b a b g
e c d c
d d c e f
a, b, c, d, e, a
a, b, c, d
153
Necessary Conditions for Hamilton Circuits
Do we have the necessary and sufficient conditions for the
existence of a Hamilton circuit?
No
There are some useful sufficient conditions.
Dirac’s Theorem
Ore’s Theorem
154
Dirac’s Theorem
Gabriel Andrew Dirac
If (but not only if ) G = (V, E) is (1925-1984)
connected, yes a
d
simple, yes
has n vertices, and yes b
vV: deg(v) n/ , yes c
then G has a Hamilton circuit. 2
How about this?
2
155
Ore’s Theorem
Øysten Ore
(1899-1968)
If (but not only if ) G = (V, E) is
3 4
connected, yes
simple, yes 3
2
156
Applications of Hamilton Paths and Circuits
Applications that ask for a path or a circuit that visits
each intersection of a city,
each place pipelines intersect in a utility grid, or
each node in a communications network exactly once
traveling salesperson problem (TSP) asks for the shortest route a
traveling salesperson should take to visit a set of cities.
finding a Hamilton circuit such that the total sum of the weights
of its edges is as small as possible.
157
Section
158
§10.6: Shortest-Path Problems
Introduction
A Shortest-Path Algorithm
The Traveling Salesperson Problem
159
Weighted Graph
a number (weight) is assigned to each edge
160
Shortest-Path Problem
Let the length of a path be the sum of the weights of the edges of this
path
What is a shortest path (a path of least length) between two given
vertices?
161
Let’s try an example
Find the length of the shortest path between a and z.
b 3 c starting b 3 c
4 2 from a 4 2
a z a z
3 3
2 1 a visited 2 1
3 e L(a) = 0 3 e
d d
L(v): the length of the L(b)= choose d
b visited shortest path from a to v L(d)=
L(b) = 4
b 3 c b 3 c
4 2 4 2
a z L(b)= , L(e)= z
3 a 3
2 choose b
1 d visited 2 1
d 3 e L(d) = 2 d 3 e
162
The example continues …
b 3 c L(c)= , La,b,e(e)
4 2
a z = , La,d,e(e)= b 3 c
3 4 2
2 choose a,d,e a z
1 3
d 3 e e visited 2 1
a, b, d visited, L(d) = 2, L(b) = 4 L(e) = 5 d 3 e
L(c)= choose z
L(z)=
b 3 c
4 2
a z
3
z visited 2 1
L(z) = 6 d 3 e
163
Dijkstra’s Algorithm: Notation
distinguished set: set of vertices that have been visited
Sk: the distinguished set after k iterations
S0 = . Sk = Sk-1 {v}, where v Sk-1 s.t. Lk(v) is min.
Lk(v) is the length of a shortest path from a to v containing only vertices in
S k.
Lk(v) = min {Lk− 1(v),
Sk-1 v not in Lk− 1(u) + w(u, v) ),
u Sk-1 Lk− 1(w) + w(w, v)}
x
w Lk(x) = min {Lk− 1(x),
Lk− 1(u) + w(u, x) ),
Lk− 1(w) + w(w, x)}
Sk = Sk-1 {v} if Lk(v) < Lk(x)
164
Dijkstra’s Algorithm: from a to z
1. L(a) :=
2. L(x) := w(a, x) for all x a // will be if x is not adjacent to a
3. S :=
4. while z S // destination not reached
5. u := a vertex not in S with L(u) minimal
6. S := S ∪ {u}
7. for all vertices v not in S
8. if L(u) + w(u, v) < L(v) then L(v) := L(u) + w(u, v)
9. return L(z)
165
The Traveling Salesperson Problem
A traveling salesperson wants to visit each of n cities exactly once
and return to his starting point.
In which order should
he visit these cities to
travel the minimum
total distance?
Find a Hamilton
circuit with minimal
total weight.
166
All Possible Hamilton Circuits
The best
167
Section
168
§10.7: Planner Graph
Introduction
Euler’s Formula
Kuratowski’s Theorem
169
The Problem
Is it possible to join these houses and utilities so that none
of the connections cross?
It’s a complete bipartite
graph K , .
Can K , be drawn on a
plane so that no two of
its edges cross?
170
Planner Graph
A graph is called planar if it can be drawn on a plane without any
edges crossing
Such a drawing is called a planar representation of the graph
K4 drawn with
K4
no crossings.
Q3 A planar
representation of Q3.
171
Is K3,3 Planner? (1/2) The curve splits the plane
into two regions: R1 and R2
Consider
𝑣 ,𝑣 ,𝑣 ,𝑣 Connecting v1 and v2 to v4
first and v5 forms a closed curve
172
Is K3,3 Planner? (2/2)
v6 could be in
Add 𝑣 R1, R21 or R22
173
Euler’s Formula
A planar representation of a graph splits the plane into
regions
r=
e=
v=
Euler’s Formula
If G is a connected planar simple graph with e edges and v vertices.
And r is the number of regions in a planar representation of G .
Then r = e − v + .
174
Degree of a Region
Degree of a region is the number of edges on the
boundary of R, denoted by deg( )
c
Edge {f, g} appears twice on the
boundary of and thus contributes
b
d to
3
a Edge {b, c} appears twice on the
g 6
e boundary of and thus contributes
7
to
f
175
Corollary 1 of Euler’s Formula
Corollary
If is a connected planar simple graph with edges and vertices,
where , then
Proof
The degree of each region in G is
First, we have at least
r=e−v+
176
Example of Corollary 1
Show that is not planner
is a connected simple graph. By Corollary ,
if is planner, then .
K5
However, has vertices and edges
( , ) so
Therefore, is not planner
177
Corollary 2 of Euler’s Formula
Corollary
If is a connected planar simple graph, then has a vertex of
degree not exceeding five.
Proof
It’s true if has one or two vertices. (easy to check)
If has at least vertices, by Corollary and thus
179
Example of Corollary 3
Show that is not planner
has no circuits of length three K3,3
is also a connected simple graph with
By Corollary , if is planner, then .
However, has vertices and edges
( , ) so
Therefore, is not planner
180
Kuratowski’s Theorem
If a graph contains either or as a subgraph, is not planner
Kuratowski’s Theorem
If a graph is not planner, it must contain a subgraph that can be obtained
from or , using certain permitted operations
181
Homeomorphic Graphs
Elementary subdivision operation
remove an existing edge and add a new vertex together
with edges and .
If a graph is planner, any graph obtained by one or more
elementary subdivisions is also planner
Two graphs and are homeomorphic if
they can be obtained from the same graph by a sequence of
elementary subdivisions.
182
Examples of Homeomorphic Graphs
a b a b a b
Remove h
f f
add f, ,
c c g
c
d e d e d e
a b
i
k
j
c g
d e
183
Kuratowski’s Theorem (Formally)
A graph is not planar if and only if it contains a subgraph
homeomorphic to or .
homeomorphic
a subgraph to
184
Section
185
The Problem
Try to color a map such that two regions with a common
border are assigned different colors
an edge connects two
vertices if the
corresponding regions
have a common border
χ(G) = χ(G) =
187
Some Facts About χ(G)
χ(Kn) = n
χ(Km,n) =
K5 K3,5
χ(Cn) = if n is even
χ(Cn) = if n is odd
C8 C7
188
A Question
We know that K is a planner graph
K4 drawn with
K4
no crossings.
189
Application1 : Scheduling Exam.
Vertices: final exams.
An edge connects two exams if they
are common to some students
What is the minimum number of
time slots needed so that no
students have two exams at the time? χ(G) =
190
Application 2: Freq. Assignment
Vertices: base stations (BSs).
An edge connects two BSs if they can
interfere with each other using the
same frequency
What is the minimum number of
frequencies needed so that no two
χ(G) =
BSs interfere with each other?
191