0% found this document useful (0 votes)
81 views

Part 2 Chapter 1 - Graph Fundamentals

Here are some key graph terminology related to vertices and edges: - Adjacent vertices: Vertices that share an edge. - Degree of a vertex: The number of edges connected to the vertex. - Indegree of a directed vertex: The number of edges pointing into the vertex. - Outdegree of a directed vertex: The number of edges pointing out of the vertex. - Start/end vertices of an edge: The vertices connected by the edge. An edge connects or joins its two endpoints/end vertices. So in summary, these terms describe the relationships and connections between vertices via the graph's edges. The degree counts the number of connections, while adjacency, start/end specify which

Uploaded by

Lại Quang Huy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views

Part 2 Chapter 1 - Graph Fundamentals

Here are some key graph terminology related to vertices and edges: - Adjacent vertices: Vertices that share an edge. - Degree of a vertex: The number of edges connected to the vertex. - Indegree of a directed vertex: The number of edges pointing into the vertex. - Outdegree of a directed vertex: The number of edges pointing out of the vertex. - Start/end vertices of an edge: The vertices connected by the edge. An edge connects or joins its two endpoints/end vertices. So in summary, these terms describe the relationships and connections between vertices via the graph's edges. The degree counts the number of connections, while adjacency, start/end specify which

Uploaded by

Lại Quang Huy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 138

TRƯỜNG ĐẠI HỌC BÁCH KHOA HÀ NỘI

VIỆN CÔNG NGHỆ THÔNG TIN VÀ TRUYỀN THÔNG

Discrete Mathematics

Nguyễn Khánh Phương

Department of Computer Science


School of Information and Communication Technology
E-mail: [email protected]
PART 1
COMBINATORIAL THEORY
(Lý thuyết tổ hợp)

PART 2
GRAPH THEORY
(Lý thuyết đồ thị) 2
Content of Part 2
Chapter 1. Fundamental concepts
Chapter 2. Graph representation
Chapter 3. Graph Traversal
Chapter 4. Tree and Spanning tree
Chapter 5. Shortest path problem
Chapter 6. Maximum flow problem

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
TRƯỜNG ĐẠI HỌC BÁCH KHOA HÀ NỘI
VIỆN CÔNG NGHỆ THÔNG TIN VÀ TRUYỀN THÔNG

Chapter 1
Fundamental concepts

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Content
1. Graph in practice
2. Graph types
3. Degree of vertex
4. Subgraph
5. Isomorphism of Graphs
6. Path and cycle
7. Connectedness
8. Special graphs
9. Graph Coloring problem NGUYỄN KHÁNH PHƯƠNG
Bộ môn KHMT – ĐHBK HN
What is graph?
Not this one

• In Maths:
Drawing or diagram represent data by using coordinate
system

• In discrete mathematics:
This is discrete structure with highly intuitive, very useful
for expressing relationships.
Applications of graph in practice
Has the potential to be applied in many fields:
• Internet
• Traffic network
• Electrical network
• Water supply network
• Scheduling
• Flow optimization, circuit design
• DNA gene analysis
• Computer games
• Object oriented design
• ….

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Relationship between subjects

461
322
373 143
321

142 326
410 415 370 341

413 417
378
421
Vertex = subject
401
Directed graph = prerequisites
NGUYỄN KHÁNH PHƯƠNG
Bộ môn KHMT – ĐHBK HN
Represent maze

S
S

E
E

Vertex = room
Edge = doorways or hallways

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Electrical Circuits

Source Switch

Vertex = source, switch, resistor, … Resistor


Edge = connecting wire
NGUYỄN KHÁNH PHƯƠNG
Bộ môn KHMT – ĐHBK HN
Program statements

x1 x2
x1=q+y*z
x2=y*z-q + -
q * q
Vertex = notation/operator
y z
Edge = relationship

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Precedence

S1 a=0; 6
S2 b=1;
S3 c=a+1
5
S4 d=b+a;
S5 e=d+1;
S6 e=c+d;

4
Which statements need to execute before S6? 3
S1, S2, S3, S4

Vertex = statement
Edge = precedence 1 2

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Information Transmission in a Computer Network

56
Tokyo Hanoi
Seoul 128

16 181 New York


30 140

Beijing
Sydney
Vertex = computer
Edge = communication speed

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Traffic Flow on Highways

UW
Vertex = city
Edge = the amount of
traffic on highways
connecting cities

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Bus system

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Subway system
Street map
Content
1. Graph in practice
2. Graph types
3. Degree of vertex
4. Subgraph
5. Isomorphism of Graphs
6. Path and cycle
7. Connectedness
8. Special graphs
9. Graph Coloring problem
Undirected Graphs (Đồ thị vô hướng)
Definition. Undirected simple (multi) graph G = (V,E) consists
of 2 sets:
• Vertex set V is a finite set, each element is called vertex
• Edge set E is the set (family) of unordered pairs
(u, v), where u, v  V, u≠v

(a, b)
a b Undirected Multigraph
(b, c) Undirected (simple) graph
c

(a, b): multiple edges (parallel edges) NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Undirected Simple Graph
• Example: Simple graph G1 = (V1, E1), where
V1={a, b, c, d, e, f, g, h},
E1={(a,b), (b,c), (c,d), (a,d), (d,e), (a,e), (d,b), (f,g)}.

a f
b
h
e

c g
d

Graph G1
Undirected MultiGraph
• Example: Multigraph G2 = (V2, E2), where V2={a, b, c,
d, e, f, g, h},
E2={(a,b), (b,c), (b,c), (c,d), (a,d), (d,e), (a,e), (a,e),
(a, e), (d,b), (f,g)}.

a
b
f

e h
Multiple c
edges
g
d

Graph G2
Directed Graph
Definition. Directed simple (multi) graph G = (V,E) consists of 2
sets:
• Vertex set V is finite element, each element is called vertex
• Edge set E is set (family) of ordered pairs
(u, v), where u, v  V, u≠v

(v, u)
(u, v)
u v Directed multigraph
(w, v)
(Simple) Directed graph
w
~ Digraph
Simple digraph
Example: Simple digraph G3= (V3, E3), where
V3={a, b, c, d, e, f, g, h},
E3={(a,b), (b,c), (c,b), (d,c), (a,d), (b, d), (a,e), (d,e), (e,a),
(f,g), (g,f)}

a f
b
h
e

c g
d

Graph G3
NGUYỄN KHÁNH PHƯƠNG
Bộ môn KHMT – ĐHBK HN
Directed MultiGraph
Example: Directed multigraph G4= (V4, E4), where
V4={a, b, c, d, e, f, g, h},
E4={(a,b), (b,c), (c,b), (d,c), (a,d), (b, d), (a,e), (a,e),
(d,e), (e,a), (f,g), (g,f)}

a
b
f

e h
c
g
d

Graph G4
Graph types: Summary

Type Edge type Has multiple edges?


Undirected graph Undirected No

Undirected multigraph Undirected Yes


Directed graph Directed No
Directed multigraph Directed Yes

Loop (Khuyên)
• Note:
– Pseudo graph (Giả đồ thị) is multigraph that contains
loops as well as multiple edges between vertices

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Graph Terminology
We have graph terminology related to relationship
between vertices and edges:
• Adjacency (Kề nhau), connect (nối), degree (bậc), start
(bắt đầu), end (kết thúc), indegree (bán bậc vào),
outdegree (bán bậc ra),…
u u
e
e

v v

Undirected edge e=(u,v) Directed edge e=(u,v)


Adjacency (Kề)
Given G the undirected graph with edge set E. Assume eE is pair
(u,v).
Then we say:
• u, v are adjacent / neighbors / connected (kề nhau/lân cận/nối với
nhau) u
• Edge e connects u and v. e
• Vertices u and v are endpoints (đầu mút) of e. v
Adjacency in directed graph
• G is directed graph (either simple or multiple) and assume e =
(u,v) is an edge of G. We say:
– u and v are adjacent, u is adjacent to v, v is adjacent from u
– e goes out of u, e goes into v.
– e connects u with v, e goes from u to v u
– initial vertex (Đỉnh đầu) of e is u e
– terminal vertex (Đỉnh cuối) of e is v v

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Content
1. Graph in practice
2. Graph types
3. Degree of vertex
4. Subgraph
5. Isomorphism of Graphs
6. Path and cycle
7. Connectedness
8. Special graphs
9. Graph Coloring problem
Degree of a vertex (Bậc của đỉnh) in undirected graph

Assume G is undirected graph, vV is a vertex.


• Degree of vertex v, deg(v), the number of edges incident on
a vertex.
• Vertex with degree 0 is called isolated (đỉnh cô lập).
• Vertex with degree 1 is called pendant (đỉnh treo).
• Symbol often used:
(G) = min {deg(v): v  V},
(G) = max {deg(v): v  V}.

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Example
Edge(a, b) is incident with b is adjacent to c and c is adjacent to b
two vertices a and b
b
c
a
f
d e deg(f) = 0
f is isolated (đỉnh cô lập)
deg(d) = 3

(G) = min {deg(v): v  V} = 0, g deg(g) = 1


(G) = max {deg(v): v  V}= 3. g is pendant (đỉnh treo)

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Theorem: Undirected graph
Theorem 1 (The Handshaking theorem):
The undirected Graph G = (V, E):

 deg(v)  2 E
vV
(why?) Every edge connects 2 vertices
Theorem 2:
An undirected graph has even number of vertices with odd degree
Proof: V1 is the set of even
  degree vertices
  and V2 refers
  to odd degree vertices

∈ ∈ ∈

even even even


 deg(u) is even for u  V1  The first term in the right hand side is even
The sum of the two terms on the right hand side is even since sum is 2|E|
 Second term is also even:   ∈  number of vertices with
deg(u) is odd for u  V2 odd degree is even 32
Example

An undirected graph G=(V,E) with 14 vertices and 25 edges,


each vertex has degree either 3 or 5. How many vertices with
degree 3 are there in this G?
Solution:
Assume G has x vertices of degree 3.
Then, there are (14-x) vertices of degree 5.
As | E | = 25,
sum of all degrees = 2 | E | = 50.
Therefore, 3x + 5(14-x) = 50
So x = 10.
NGUYỄN KHÁNH PHƯƠNG
Bộ môn KHMT – ĐHBK HN
Degree of a vertex in directed graph
Given G directed graph, v is a vertex of G:
• In-degree (bán bậc vào) of v, deg(v), number of edges for which v
is terminal vertex (goes into v).
• Out-degree (bán bậc ra) of v, deg(v), number of edges for which v
is initial vertex (goes out of v).
• Degree of v, deg(v)=deg(v)+deg(v)

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Example
deg-(b) = 1
deg+(b)= 1 deg-(c) = 1
b c deg+(c)= 2

a
deg-(f) = 0
f
deg-(a) =0 deg+(f)= 0
deg+(a)= 2 d e
a- source vertex deg-(d) = 2 deg-(e) = 2
deg+(d)= 1 deg+(e)= 0
e –target vertex

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Theorem: Directed graph
Theorem 3 The directed Graph (either simple or multiple) G = (V, E):
1

vV
deg (v)   deg (v)   deg(v)  E

vV

2 vV

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK36
HN
Content
1. Graph in practice
2. Graph types
3. Degree of vertex
4. Subgraph
5. Isomorphism of Graphs
6. Path and cycle
7. Connectedness
8. Special graphs
9. Graph Coloring problem NGUYỄN KHÁNH PHƯƠNG
Bộ môn KHMT – ĐHBK HN
4. Subgraph (Đồ thị con)
A subgraph of a graph G = (V, E) is a graph H =(V’, E’) where V’ is a subset
of V and E’ is a subset of E.
Denoted by: HG
Example: V = {u, v, w}, E = ({u, v}, {v, w}, {w, u}}
u u u

H1 G
G
v w v
v w H2  G
v w
v w v w

x y
x y x y
38
G HG F G
The deletion of vertices
Definition. G = (V, E) is undirected graph. Assume S  V. We call the
removal of vertices set S from the graph is to remove all vertices in S
and their adjacent edges.
We denote the obtained graph by G-S

G v w GS v w

u Assume S={x,u}  u
x y x y

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Spanning Subgraph (Đồ thị con bao trùm)
Definition.
Subgraph H  G is called spanning subgraph of G if vertex set of H is
vertex set of G: V(H) = V(G).

Definition.
We write H = G + {(u,v), (u,w)} to mean
E(H) = E(G) {(u,v), (u,w)}, where (u,v), (u,w)E(G).

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
The union of graphs
The union of two simple graphs G1=(V1, E1) and G2=(V2, E2) is the simple
graph G1 G2=(V1 V2, E1 E2).
Example: a b c a b c

G1 G2

d e d f

a b c

G1 G2

d e f
41
The union of graphs (Hợp của hai đồ thị)
The union of two simple graphs G1=(V1, E1) and G2=(V2, E2) is the simple
graph G1 G2=(V1 V2, E1 E2).
Example:

a b c a b c

d e d f

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Content
1. Graph in practice
2. Graph types
3. Degree of vertex
4. Subgraph
5. Isomorphism of Graphs
6. Path and cycle
7. Connectedness
8. Special graphs
9. Graph Coloring problem NGUYỄN KHÁNH PHƯƠNG
Bộ môn KHMT – ĐHBK HN
Isomorphism of Graphs

u1 u2 v1 v2
G is isomorphic to H
u3 u4 v3 v4
G H
Definition. The simple graphs G1=(V1,E1) and G2=(V2,E2) are
isomorphic if there is an one-to-one and onto function f from V1 to
V2 with the property that a and b is adjacent in G1 iff f(a) and f(b)
is adjacent in G2, a,bV1
f is called an isomorphism.

Application Example:
In chemistry, to find if two compounds have the same structure 44
Example. Show that G and H are isomorphic.
u1 u2 v1 v2

u3 u4 v4
v3
G H
Solution.
The function f with f(u1) = v1, f(u2) = v4, f(u3) = v3, and f(u4) = v2 is a
one-to-one correspondence between V(G) and V(H).
Isomorphism graphs there will be:
(1) The same number of vertices
(2) The same number of edges
(3) The same number of degree

45
Isomorphism of Graphs
Given figures, judging whether they are isomorphic in general is not an
easy task.
Example. Show that G and H are not isomorphic.

G H

Solultion :
G has a vertex of degree = 1 , H doesn’t

46
Example. Determine whether G and H are not isomorphic.

a b s t
e w x
f
g
h z y
d c
v u
G H
Solultion : In G, deg(a)=2, which must correspond to either t, u,
x, or y in H. Degree each of these four vertices in H is adjacent to
another vertex of degree two in H, which is not true for a in G
 G and H are not isomorphic.

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK47
HN
Example. Determine whether the graphs G and H are isomorphic.

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

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Example. Determine whether the graphs G and H are isomorphic.

u1 G u2 v1 H v3

u5 v2
u6
v6
v5
u4 u3 v4

Solution:
f(u1)=v6, f(u2)=v3, f(u3)=v4, f(u4)=v5, f(u5)=v1, f(u6)=v2
Yes

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Example. Determine whether the graphs G and H are isomorphic.

a
b • Same number of vertices
• Same number of edges
d • Different number of
vertices with degree 2
c e
(1 ≠ 3)

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Content
1. Graph in practice
2. Graph types
3. Degree of vertex
4. Subgraph
5. Isomorphism of Graphs
6. Path and cycle
7. Connectedness
8. Special graphs
9. Graph Coloring problem
Path
Definition for Directed Graphs
A Path of length n > 0 from u to v in G is a sequence of n edges e1, e2 , e3, …,
en of G such that f (e1) = (xo, x1), f (e2) = (x1, x2), …, f (en) = (xn-1, xn), where x0 =
u and xn = v.
A path is said to pass through x0, x1, …, xn or traverse e1, e2 , e3, …, en

• A path is called elementary (đường đi cơ bản) if all the edges are


distinct.
• A path is called simple (đường đi đơn) if all the vertices are distinct.
• A path is closed if v0 = vn.
• A closed elementary path is called a cycle. A cycle is called simple if
all the vertices are distinct (except v0 = vn).

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK52
HN
Path
A path is called elementary if all the edges are distinct.
A path is called simple if all the vertices are distinct.

Path: 5, 2, 3, 4 [OR: {5, 2}, {2, 3}, {3, 4} 5


OR: c,b,e] c d
all the vertices are distinct simple path a b 3 e
1 2 4

Path (directed) 1, 2, 5, 3, 4
5
[OR: (1, 2), (2, 5), (5, 3), (3, 4) c d
OR: a, c, d, e] a b 3 e
1 2 4
• is the simple path

53
Path
• P1= (1, 2, 3) is the simple path
• P2=(4,5,2,6,5,1) is the path but not the simple path

1
a b
P1
d
4 2 3
P2 h
c e
5 g
f
6
54
Cycle
• A closed elementary path is called a cycle.
– A path is called elementary if all the edges are distinct.
– A path is closed if v0 = vn.
• A cycle is called simple if all the vertices are distinct (except v0 = vn).

2
a b
Simple cycle: (1, 2, 3, 1) e
1 3
d c
4
2
a b
e
1 3
Simple cycle: (1, 2, 3, 4, 1) d c

55
Cycle on directed graph

• C1=(V,X,Y,W,U,V) is simple cycle


• C2=(U,W,X,Y,W,V,U) is cycle but not simple cycle

V
a b

U d X Z
C2 h
c e C1
W g

f
Y
56
Content
1. Graph in practice
2. Graph types
3. Degree of vertex
4. Subgraph
5. Isomorphism of Graphs
6. Path and cycle
7. Connectedness
8. Special graphs
9. Graph Coloring problem NGUYỄN KHÁNH PHƯƠNG
Bộ môn KHMT – ĐHBK HN
Connectedness
Undirected Graph
An undirected graph is connected if there exists is a simple path between
every pair of vertices
Example: G (V, E) is connected since for V = {v1, v2, v3, v4, v5}, there exists a path
between {vi, vj}, 1 ≤ i, j≤ 5 v1 v4
v3

v2 v5
Articulation Point (Cut vertex): removal of a vertex produces a subgraph with more
connected components than in the original graph. The removal of a cut vertex from a
connected graph produces a graph that is not connected
Bridge: An edge whose removal produces a subgraph with more connected components
than in the original graph.
b c e: cut vertex
e

a d (e,g): bridge
g 58
Connectedness
• If a graph is not connected then it splits up into a number of connected subgraphs,
called its connected components.
• The connected components of G can be defined as its maximal connected subgraphs.
This means that G1 is a connected component of G if:
– G1 is a connected subgraph of G
– G1 is not itself a proper subgraph of any other connected subgraph of G. This
second condition is what we mean by the term maximal; it says that if H is a
connected subgraph such that G1  H, then G1 = H.
Example: Graph G has 3 connected components: G1, G2, G3
b c
i
f a

j k G2 d e
G3
G1 g
59
Connectedness
Directed Graph
• A directed graph is strongly connected if there is a path from u to v and
from v to u whenever u and v are vertices in the graph
• A directed graph is weakly connected if its corresponding undirected graph
is connected.
A strongly connected Graph can be weakly connected but the vice-versa is
not true (why?)
b c
Strongly connected graph
a f
d e

b c b c
a f f
a
d e d e
60
Weakly connected graph
Connectedness
Directed Graph
• Strongly connected Components: subgraphs of a Graph G that are
strongly connected
Example: G1 is the strongly connected component in G

G G1
61
k-Connectivity(k-liên thông)
Not all connected graphs have the same value!
Question: Which following graphs are more valuable computer network
1) G1

2) G2

3) G3

4) G4
k-Connectivity(k-liên thông)
Answer: We want a computer network still working even
when one computer fails
G1) 2nd best. Connected, but there
is a weak point - “cut vertex”
G2) 3rd best. Connected, but each
computer is a weak point

G3) The worst!


Not connected

G4) The best! Not connected only


when there are 2 computers fail
Content
1. Graph in practice
2. Graph types
3. Degree of vertex
4. Subgraph
5. Isomorphism of Graphs
6. Path and cycle
7. Connectedness
8. Special graphs
9. Graph Coloring problem
Some special graphs
1. Null graph
2. Complete graphs Kn
3. Cycles Cn
4. Wheels Wn
5. n-Cubes Qn
6. Bipartite graphs
7. Complete bipartite graphs Km,n
8. r-regular graph
9. Planar graph
10. Euler graph and Hamilton graph 65
Null graph
Definition: Null graph (Nn) is an undirected graph G =
(V, E) where E = 

N1 N2 N3 N4

66
Complete graph
Complete graph (Kn): is the simple graph that contains exactly one
edge between each pair of distinct vertices.
Example:

K1 K2 K3 K4 K5 K6

n 1
n(n  1)
Note: Graph Kn has  i 
i 1 2
edges

67
Complete Graphs (Đồ thị đầy đủ)

K25
Complete Graphs (Đồ thị đầy đủ)

K42
Cycles
Cycle (Cn , n ≥ 3): is an undirected graph consisting of n vertices v1,
v2, v3 … vn and edges {v1, v2}, {v2, v3}, {v3, v4} … {vn-1, vn}, {vn, v1}

Example:

C3 C4 C5 C6 C7 C8

Note: Graph Cn has ? edges

70
Wheels
Wheel (Wn , n ≥ 3): is an undirected graph obtained by adding additional
vertex to Cn and connecting all vertices to this new vertex by new edges.
Example:

C3 C4 C5 C6 C7 C8

W3 W4 W5 W6 W7 W8

Wheel Wn has ? edges 71


N-cubes
N-cubes (Qn): vertices represented by 2n bit strings of length n. Two
vertices are adjacent if and only if the bit strings that they represent differ
by exactly one bit positions
Example: 10 11 #vertices: 2n. #edges: ?
0 1

Q0 Q1
00 01 Q3 Q4
Q2
• Q0={{v0},} (1 vertex, not edge)
• nN: if Qn=(V,E) where V={v1,…,va} and E={e1,…,eb}, then
Qn+1=(V{v1´,…,va´},
E{e1´,…,eb´}{{v1,v1´},{v2,v2´},…,{va,va´}})
It means Qn+1 obtained by connecting pairs of verticies of Qn và Q’n
72
Some special graphs
1. Null graph
2. Complete graphs Kn
3. Cycles Cn
4. Wheels Wn
5. n-Cubes Qn
6. Bipartite graphs
7. Complete bipartite graphs Km,n
8. r-regular graph
9. Planar graph
10. Euler graph and Hamilton graph 73
Bipartite graph
Graph G=(V,E) is a bipartite graph if and only if
V = V1V2 ,V1∩V2=
eE: v1V1,v2V2: e={v1,v2}
(In a simple graph G, if V can be partitioned into two disjoint sets V1 and
V2 such that every edge in the graph connects a vertex in V1 and a vertex
V2 (so that no edge in G connects either two vertices in V1 or two vertices
in V2)
Example:

V1 V2 74
Example. Is the graph G bipartite ?

a b a
c

g
c e
b

f
f d d
g
e

G Yes !
75
Bipartite graph: Examples of application
• Document/Term Graphs: Here set V1 are documents and set V2 are terms or
words, and there is an edge (v1, v2) if the word v2 is in the document v1. Such
graphs are use often to analyze text, for example to cluster the documents.
• Movies preferences: In 2009, Netflix gave a $1Million prize to the group that
was best able to predict how much someone would enjoy a movie based on
their preferences. This can be viewed as a bipartite graph problem. The
viewers are the vertices V1 and the movies the vertices V2 and there is an edge
from v1 to v2 if v1 viewed v2. In this case, the edges are weighted by the rating
the viewer gave. The winner was algorithm called “BellKor’s Pragmatic
Chaos”.
• Students and classes: We might create a graph that maps every student to the
classes they are taking. Such a graph can be used to determine conflicts, e.g.
when classes cannot be scheduled together.
• Object recognition
• Food Recommendation System
• …
76
Complete bipartite graph
With m,nN, complete bipartite graph Km,n is bipartite graph where
• |V1| = m, |V2| = n
• E = {(v1,v2)|v1V1 và v2V2}.
Km,n is the graph that has its vertex set portioned into two subsets of m
and n vertices, respectively. There is an edge between two vertices if and
only if one vertex is in the first subset and the other vertex is in the
second subset.
Example:

Km,n has _____ vertices


and _____ edges.

K3,3 K4,3
77
r-regular graph
Definition. Graph G = (V, E) is r-regular graph if each vertex vV
has degree deg(v)= r (has the same number of neighbors)
Example:

0-regular graph 1-regular graph 2-regular graph 3-regular graph

78
Some special graphs
1. Null graph
2. Complete graphs Kn
3. Cycles Cn
4. Wheels Wn
5. n-Cubes Qn
6. Bipartite graphs
7. Complete bipartite graphs Km,n
8. r-regular graph
9. Planar graph
10. Euler graph and Hamilton graph 79
Planar Graphs (Đồ thị phẳng)
• A graph is called planar if it can be drawn in the plane
without any edges crossing.
– A crossing of edges is the intersection of the lines or arcs
representing them at a point other than their common endpoint.
– Such a drawing is called a planar representation of the graph.
Example: K4 is planar graph?

Yes, K4 is planar graph


A graph may be planar even if it is usually drawn with crossings, since it may be
possible to draw it in another way without crossings.
Planar Graphs (Đồ thị phẳng)
• A graph is called planar if it can be drawn in the plane
without any edges crossing.
Example: Q3 is planar graph?

Yes, Q3 is planar graph!


A graph may be planar even if it represents a 3-dimensional object.
Example: Three house and three utilities problem
• Is it possible to join the three houses to the three utilities in
such a way that none of the connections cross?

K3,3
 Phrased another way, this question is equivalent to: Given
the complete bipartite graph K3,3, can K3,3 be drawn in the
plane so that no two of its edges cross? (K3,3 is planar graph?)
K3,3 and K5 are not planar graphs
• K3,3 and K5 are not planar graphs.

• We can prove that a particular graph is planar by showing how


it can be drawn without any crossings.
• However, not all graphs are planar.
• It may be difficult to show that a graph is nonplanar. We would
have to show that there is no way to draw the graph without any
edges crossing.
Planar Graphs (Đồ thị phẳng)
The number of planar graphs when number of vertices n=1, 2, 3, … are
respectively 1, 2, 4, 11, 33, 142, 822, 6966, 79853,….

Planar graph Planar connected graph

And the number of corresponding planar connected graphs are 1, 1, 2, 6, 20, 99,
646, 5974, 71885,…
Regions
• Euler showed that all planar representations of a graph split the plane
into the same number of regions, including an unbounded region.
Example:

G1
R3: exterior
R1
G1 has 3 regions.
R2

R4 R3 R2

G2 has 4 regions. R1

G2
Regions
• In any planar representation of K3,3, vertex v1 must be connected to
both v4 and v5, and v2 also must be connected to both v4 and v5.
v1 v2 v3

v4 v5 v6
Regions
• The four edges {v1, v4}, {v4, v2}, {v2, v5}, {v5,
v1} form a closed curve that splits the plane
into two regions, R1 and R2.

• Next, we note that v3 must be in either R1 or R2.


Case 1: Assume v3 is in R2. Then the edges {v3, v4} and {v4, v5} separate
R2 into two subregions, R21 and R22.
Regions
• Now there is no way to place vertex v6 without
forcing a crossing:
– If v6 is in R1 then {v6, v3} must cross an edge
– If v6 is in R21 then {v6, v2} must cross an edge
– If v6 is in R22 then {v6, v1} must cross an edge
Regions
• The four edges {v1, v4}, {v4, v2}, {v2, v5}, {v5,
v1} form a closed curve that splits the plane
into two regions, R1 and R2.

• Next, we note that v3 must be in either R1 or R2.


Case 2: Assume v3 is in R1. Then the edges {v3, v4} and {v4, v5} separate
R1 into two subregions, R11 and R12.
Regions
• Now there is no way to place vertex v6 without
forcing a crossing:
– If v6 is in R2 then {v6, v3} must cross an edge
– If v6 is in R11 then {v6, v2} must cross an edge
– If v6 is in R12 then {v6, v1} must cross an edge
Planar Graphs
• Consequently, the graph K3,3 must be nonplanar.

K3,3
Regions
• Euler devised a formula for expressing the relationship
between the number of vertices, edges, and regions of a
planar graph.
• These may help us determine if a graph can be planar or not.

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Euler’s Formula
• Let G be a connected planar simple graph with e
edges and v vertices. Let r be the number of regions
in a planar representation of G. Then r = e - v + 2.

R4 R3 R2
# of edges, e = 6
R1 # of vertices, v = 4
# of regions, r = e - v + 2 = 4

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Euler’s Formula (Cont.)
• Corollary 1: If G is a connected planar simple graph with e
edges and v vertices where v  3, then e  3v - 6.
Is K5 planar?
• K5 has 5 vertices and 10 edges.
• We see that v  3.
• So, if K5 is planar, it must be true that e  3v – 6.
• 3v – 6 = 3*5 – 6 = 15 – 6 = 9.
• So e must be  9.
• But e = 10.
• So, K5 is nonplanar.

K5
Euler’s Formula (Cont.)
• Corollary 2: If G is a connected planar simple graph, then G
must have a vertex of degree not exceeding 5.

If G has one or two vertices, it is true;


thus, we assume that G has at least three vertices.

If the degree of each vertex were at least 6, then by Handshaking


Theorem,
2e ≥ 6v, i.e., e ≥ 3v, 2e   deg(v )
vV
but this contradicts the inequality from
Corollary 1: e ≤ 3v – 6.

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Euler’s Formula (Cont.)
• Corollary 3: If a connected planar simple graph has e edges and
v vertices with v  3 and no circuits of length 3, then e  2v - 4.

Is K3,3 planar?
• K3,3 has 6 vertices and 9 edges.
• Obviously, v  3 and there are no circuits of length 3.
• If K3,3 were planar, then e  2v – 4 would have to be true.
• 2v – 4 = 2*6 – 4 = 8
• So e must be  8.
• But e = 9.
• So K3,3 is nonplanar.
Some special graphs
1. Null graph
2. Complete graphs Kn
3. Cycles Cn
4. Wheels Wn
5. n-Cubes Qn
6. Bipartite graphs
7. Complete bipartite graphs Km,n
8. r-regular graph
9. Planar graph
10. Euler graph and Hamilton graph 97
Seven Bridges of Königsberg
• The city of Königsberg, Russia was set on both sides of the Pregel River,
and included two large islands (Kneiphof and Lomse) which were
connected to each other, or to the two mainland portions of the city, by
seven bridges. The problem was to devise a walk through the city that
would cross each of those bridges exactly once.
• In 1736, Euler proved that the problem has no solution.

Leonhard Euler
1707-1783
Seven Bridges of Königsberg
• To prove it, Euler reformulated the problem in graph terms:
– Each land mass ~ a vertex
– Each bridge ~ an edge A
1 2 6
A 5
B D
2 3
1 4 7
B
4 5 C
3 D 6
C 7
A
Is there a way to go through all 7 bridges, each exactly 1 2 6
once, and then return to the starting position? 5 D
B
3 4
Whether or not there exists a cycle on a graph G that 7
traverses through every edge of G exactly once.
C
Euler graph
• Definition
• Recognize Euler graph
Euler graph
• Euler path (Eulerian trail, Euler walk) in graph is a path
that traverses through every edge exactly once.
• Euler cycle (Eulerian circuit, Euler tour) in graph is a
Euler path begins and ends at the same vertex (is a cycle
that traverses through every edge exactly once).

• Graph consisting of Euler cycle is called as Euler graph.


• Graph consisting of Euler path is called as Half Euler
graph.
• Apparently, all Euler graphs are also half-Euler graphs.
Example
a b a b

c d e c d e

Half Euler graph Euler graph


Euler path: a, c, d, b, e, d, a, b Euler cycle: a, c, d, e, b, d, f, b, a

Euler path in graph is a path that traverses through every edge exactly once.
Euler cycle in graph is a cycle that traverses through every edge exactly once.

Half Euler graph: graph consists of Euler path

Euler graph: graph consists of Euler cycle


Euler’s 1st theorem
• If a graph has any vertices of odd degree, then it can not have any
Euler cycle.
• If a graph is connected and every vertex has an even degree, then it
has at least one Euler cycle.
Proof:
• If a node has an odd degree, and the cycle starts at this node, then it
must end elsewhere. This is because after we leave the node the first
time the node has even degree, and every time we return to the node
we must leave it. (On the paired arc.)
• If a node has an odd degree, and the cycle begins else where, then it
must end at the node. This is a contradiction, since a cycle must end
where it began.
If a graph has all even degree nodes, then an Euler Circuit exists.

Algorithm:
• Step One: Randomly move from node to node, until stuck.
Since all nodes had even degree, the circuit must have
stopped at its starting point. (It is a circuit.)
• Step Two: If any of the arcs have not been included in our
circuit, find an arc that touches our partial circuit, and add in
a new circuit.
– Each time we add a new circuit, we have included more
nodes.
– Since there are only a finite number of nodes, eventually
the whole graph is included.
Euler’s 2nd theorem
• If a graph has more than two vertices of odd degree, then it cannot
have an Euler path.
• If a graph is connected and has exactly two vertices of odd degree,
then is has at least one Euler path. Any such path must start at one of
the odd degree vertices and must end at the other odd degree vertex.
Euler’s theorems
If a graph is connected and if the number of odd degree vertices
• = 0, then Euler cycle (Theorem 1)
• = 2, then Euler path (Theorem 2)
– This Euler path must start at one of the odd degree vertices and must end
at the other odd degree vertex.
Is there a way to go through all 7 bridges, each exactly
A once, and then return to the starting position?

1 2 6
5 D Whether or not there exists a cycle on a graph G that
B traverses through every edge of G exactly once.
3 4
7 Answer: There exists vertex of odd degree  don’t have Euler cycle
C
Whether or not there exists Euler path in G?
Answer: There are 3 vertices of degree 3, one vertex of degree 5 
don’t have Euler path
Example

Vertex of Vertex of
odd degree odd degree

a b a b

c d e c d e

Half Euler graph Euler graph


Hamilton graph
• Definition
• Recognize Hamilton graph
Euler graph
• Euler path (Eulerian trail, Euler walk) in graph is a path
that traverses through every edge exactly once.
• Euler cycle (Eulerian circuit, Euler tour) in graph is a
Euler path begins and ends at the same vertex (is a cycle
that traverses through every edge exactly once).
• Graph consisting of Euler cycle is called as Euler graph.
• Graph consisting of Euler path is called as Half Euler
graph.
Hamilton graph
• Hamilton path in graph is a path that traverses every vertex
exactly once.
• Hamilton cycle in graph is a cycle that traverses every vertex
exactly once.
• Graph consisting of Hamilton cycle is called as Hamilton
graph.
• Graph consisting of Hamilton path is called as Half Hamilton
graph.
• Apparently, all Hamilton graphs are also half-Hamilton graphs.
Example: Hamilton graph
• Is graph consisting of Hamilton cycle: traverse every vertex
exactly once.
Example: Proof Qn (n  3) is Hamilton graph.
Proof Induction to n.
• Basic step: n=3 true
• Inductive step: Assume Qn-1 is Hamilton graph.
Consider Qn:

x x’ x x’
y y’

y y’

3 - cube (n 1)-cube (n 1)-cube


Hamilton graph
• Graph has 2 vertices of degree 1 not Hamilton graph

• The above graph is Half Hamilton graph


Half Hamilton graph

• Vertices of degree 1 must be either the starting or ending


position of the Hamilton path.
Graph has 3 vertices of degree 1
 Not Halft Hamilton graph
Theorem about existence of Hamilton path
• Theorem Dirac: If G is simple connected graph with n3 vertices,
and v deg(v)  n/2, then G has Hamilton cycle.

• Theorem Ore: If G is simple connected graph with n3 vertices, and


deg(u) + deg(v)  n for all vertices pair u, v not adjacent, then G has
Hamilton cycle.

Paul Adrien Maurice Dirac Oystein Ore


1902 - 1984 1899 - 1968
(USA) (Norway)
Content
1. Graph in practice
2. Graph types
3. Degree of vertex
4. Subgraph
5. Isomorphism of Graphs
6. Path and cycle
7. Connectedness
8. Special graphs
9. Graph Coloring problem
Graph coloring problem: Application example

flights need gates, but times overlap.


how many gates needed?

time
122

145

Flights 67

257

306

99
Graph coloring problem: Application example

Needs gate at same time

145

• Each vertex represents a flight

• Each edge represents a conflict


306

99
Graph coloring problem: Application example
Conflict Graph

257 122
145

67
306

9
flights need gates, but times overlap.
• Each vertex represents a flight
how many gates needed?

• Each edge represents a conflict

assignment of gates to all vertices such that two


adjacent vertices get different gates.
Graph coloring problem: Application example

257 122 145

Assign gates:

67 257, 306
306 67, 122,145
99

3 colors 99
3 gates
What is Coloring?
• Graph Coloring Problem is an assignment of colors to all vertices
of a given graph such that two adjacent vertices get different
colors.

• Objective: use minimum number of colors.

3-colorable
Optimum Coloring

Definition. min #colors for G is chromatic number, (G)

What graphs have chromatic number one?

when there are no edges…

What graphs have chromatic number 2?

What graphs have chromatic number larger than 2?

A path? A cycle? A triangle?


Simple cycle

 (Ceven ) = 2

 odd

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Complete graph

 n

NGUYỄN KHÁNH PHƯƠNG


Bộ môn KHMT – ĐHBK HN
Wheel

W5
 (Wodd ) = 4  (Weven ) = 3
Tree

root
Pick any vertex as “root.”
if (unique) path from root is

even length:

odd length:

Can prove more formally using induction.


2-colorable graph

When exactly is a graph 2-colorable?

This is 2-colorable.

2 colorable: tree, even cycle, etc.

Not 2 colorable: triangle, odd cycle, etc.


Bipartite graphs

When exactly is a graph 2-colorable?

Is a bipartite graph 2-colorable?

Is a 2-colorable graph bipartite?

Fact. A graph is 2-colorable if and only if it is bipartite.


Bipartite graphs

When exactly is a graph bipartite?

Can a bipartite graph has an odd cycle? NO

If a graph does not have an odd cycle, then it is bipartite?

Theorem. A graph is bipartite if and only if it has no odd cycle.


Bipartite graphs

When exactly is a graph bipartite?

No such edge because no 5-cycle 1. The idea is like coloring a


tree.
2. Pick a vertex v, color it red.
3. Color all its neighbor green.
4. Color all neighbors of green
vertices red
5. Repeat until all vertices are
No such edge because no triangle colored.

If a graph does not have an odd cycle, then it is bipartite?

Theorem. A graph is bipartite if and only if it has no odd cycle.


Coloring problem: Some examples of Applications
Application 1: Schedule Final Exam

This is a graph coloring problem.


• Each vertex is a course,
• Two courses are connected with an edge
if they have a student in common.

How many colors are necessary ?


Coloring problem: Some examples of Applications

Many problems can be formulated as a graph coloring problem


including Time Tabling, Scheduling, Register Allocation, Channel
Assignment.
Coloring problem: Some examples of Applications
Application 1: Schedule Final Exam

This is a graph coloring problem.

The graph is obviously not 1-colorable because there exist edges


The graph is not 2-colorable because there exist triangles
Is it 3-colorable ? Try to color by Red, Green, Blue

How many colors are necessary ?


Coloring problem: Some examples of Applications
Application 1: Schedule Final Exam

This is a graph coloring problem.

Pick a triangle and color the vertices


3203-Red, 3157-Blue, 4118-Green
Coloring problem: Some examples of Applications
Application 1: Schedule Final Exam

This is a graph coloring problem.

Pick a triangle and color the vertices


3203-Red, 3157-Blue, 4118-Green
So 4156 must be Blue
Coloring problem: Some examples of Applications
Application 1: Schedule Final Exam

This is a graph coloring problem.

So 3261 and 4115 must be Red


3137 and 1007 easy to color – pick Blue

Slot 2

Slot 1
Slot 3
Thus, we need 3 time slots
Coloring problem: Some examples of Applications
Application 2: Register allocation

This is a graph coloring problem.

• Given a program, we want to execute it as quick as possible.


• Calculations can be done most quickly if the values are stored in registers.
• But registers are very expensive, and there are only a few in a computer.
• Therefore, we need to use the registers efficiently.
Coloring problem: Some examples of Applications
Application 2: Register allocation

This is a graph coloring problem.

• Each vertex is a variable.


• Two variables are connected with an edge if they cannot be put into the same register.

a and b cannot use the same register, because they store different values.
c and d cannot use the same register otherwise the value of c is overwritten.

Each color corresponds to a register.

You might also like