MADChap9 Graphs
MADChap9 Graphs
Graphs
MAD101
Ly Anh Duong
duongla3@fe.edu.vn
Table of Contents
1 Graphs and Graph Models
Relationship between
• ...
Definition 1.1
A graph G = (V, E) consists of V , a nonempty set of vertices (đỉnh) (or nodes) and E, a set of edges
(cạnh). Each edge has either one or two vertices associated with it, called its endpoints (đầu mút). An edge
is said to connect its endpoints.
Definition 1.2
A directed graph (or digraph) (V, E) consists of a nonempty set of vertices V and a set of directed edges
(or arcs) E. Each directed edge is associated with an ordered pair of vertices. The directed edge associated
with the ordered pair (u, v) is said to start at u and end at v.
Undirected graph: Each edge has no direction.
• Simple directed graph: has no loops and has no multiple directed edges
• A precedence graph
Definition 2.1
Two vertices u and v in an undirected graph G are called adjacent (or neighbors) (kề nhau) in G if u and
v are endpoints of an edge e of G. Such an edge e is called incident (cung/cạnh) with the vertices u and v
and e is said to connect u and v.
Definition 2.2
The degree of a vertex in an undirected graph is the number of edges incident with it, except that a
loop at a vertex contributes twice to the degree of that vertex. The degree of the vertex v is
denoted by deg(v).
Remark 2.1.
1. A vertex of degree zero is called isolated (đỉnh cô lập)
2. A vertex is pendant (đỉnh treo) if and only if it has degree one.
Example 2.1. What are the degrees of the vertices in the graphs G and H.
Example 2.2. What are the degrees of the vertices in the graphs G and H.
Solution.
Graph G: deg(a) = 2, deg(b) = 4, deg(c) = 4, deg(d) = 1, deg(f ) = 4, deg(e) =
3, deg(g) = 0.
Graph H: deg(a) = 4, deg(b) = deg(e) = 6, deg(c) = 1, deg(d) = 5.
Ly Anh Duong Chapter 9 Graphs duongla3@fe.edu.vn 14 / 68
THE HANDSHAKING THEOREM
2 Graph Terminology and Special Types of Graphs
Theorem 2.1
Let G = (V, E) be an undirected graph with m edges. Then
X
2m = deg(v)
v∈V
(Note that this applies even if multiple edges and loops are present.)
Example 2.3. How many edges are there in a graph with 10 vertices each of
degree six?
Theorem 2.3
Let G = (V, E) be an undirected graph with m edges. Then
X
2m = deg(v)
v∈V
(Note that this applies even if multiple edges and loops are present.)
Example 2.4. How many edges are there in a graph with 10 vertices each of
degree six?
Solution. 2m = 10.6 =⇒ m = 30
Theorem 2.4
An undirected graph has an even number of vertices of odd degree.
Example 2.6. How many edges does a graph have if its degree sequence is
5, 5, 4, 3, 2, 1, 0.
Example 2.9. How many edges does a graph have if its degree sequence is
5, 5, 4, 3, 2, 1, 0.
Definition 2.3
When (u, v) is an edge of the graph G with directed edges, u is said to be adjacent to v and v is said to be
adjacent from u.
a −→ b
• a is initial vertex
• b is terminal vertex (or end vertex)
The initial vertex and terminal vertex of a loop are the same.
• In-degree (deg − (v)): the number of edges with v as their terminal vertex,
• Out-degree (deg + (v)): the number of edges with v as their initial vertex.
Remark 2.2. A loop v have deg − (v) = deg + (v) = 1.
Theorem 2.5
Let G = (V, E) be a graph with directed edges. Then deg − (v) = deg + (v) = |E|
P P
v∈V v∈V
Example 2.11. Find the in-degree and out-degree of each vertex in the graph G
with directed edges shown in Figure.
Example 2.12. Find the in-degree and out-degree of each vertex in the graph G
with directed edges shown in Figure.
Solution.
• deg − (a) = 2, deg + (a) = 4
• deg − (b) = 2, deg + (b) = 1
• deg − (c) = 3, deg + (c) = 2
• deg − (d) = 2, deg + (d) = 2
• deg − (e) = 3, deg + (e) = 3
• deg − (f ) = deg + (f ) = 0
Definition 3.1
A complete graph on n vertices, denoted by Kn , is a simple graph that contains exactly one edge
between each pair of distinct vertices.
n(n − 1) n!
• Kn has n vertices and = Cn2 edges. Cnk =
2 k!(n − k)!
• The degree of each vertex is n − 1.
Ly Anh Duong Chapter 9 Graphs duongla3@fe.edu.vn 20 / 68
Cycles
3 Some Special Simple Graphs
Definition 3.2
A cycle Cn , n ≥ 3, consists of n vertices v1 , v2 , ..., vn and edges {v1 , v2 }, {v2 , v3 }, ..., {vn−1 , vn }, and
{vn , v1 }.
Definition 3.3
We obtain a wheel Wn when we add an additional vertex to a cycle Cn , for n ≥ 3, and connect this new
vertex to each of the n vertices in Cn , by new edges.
Definition 3.4
An n-dimensional hypercube, or n-cube, denoted by Qn , is a graph that has vertices representing the 2n
bit strings of length n. Two vertices are adjacent if and only if the bit strings that they represent differ in
exactly one bit position.
Definition 3.5
A simple graph G is called bipartite if its vertex set 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 in V2 (so that no edge in G
connects either two vertices in V1 or two vertices in V2 ). When this condition holds, we call the pair
(V1 , V2 ) a bipartition of the vertex set V of G.
Adjacency list: For each vertex u in the graph, there is a list of vertex v which
there is an edge between u and v.
Example 4.1. Use adjacency lists to describe the simple graph given in Figure.
Example 4.2. Represent the directed graph shown in Figure by listing all the
vertices that are the terminal vertices of edges starting at each vertex of the
graph.
Definition 4.1
the number of edges that are associated to {vi , vj }
Adjacency matrix A = [aij ] with aij =
0, Otherwise
Example 4.3. Use an adjacency matrix to represent the graph shown in Figure.
Solution. The matrix repre-
senting this graph is
Example 4.4. Use an adjacency matrix Example 4.5. Draw a graph with the
to represent the pseudograph shown in adjacency matrix.
Figure.
Solution.
Solution.
Solution.
1. deg(c) = 1 + 2 + 1.2 + 0 = 5 (c is loop).
2. 9.
Ly Anh Duong Chapter 9 Graphs duongla3@fe.edu.vn 33 / 68
Incidence Matrices
4 Representing Graphs & Graph Isomorphism
Definition 4.2
Let G = (V, E) be an undirected graph. Suppose that v1 , v2 , . . . , vn are the vertices and e1 , e2 , . . . , em are
the edges of G. Then the incidence matrix with respect to this ordering of V and E is the n × m matrix
M = [mij ], where
1, when edge ej is incident with vi
mij =
0, Otherwise
Example 4.7. Represent the graph shown in Figure with an incidence matrix.
Example 4.8. How many column are there in the incidence matrix of W9 ?
Example 4.9. How many 1s are there in the incidence matrix representing the
complete graph K10 ?
Definition 4.3
The simple graphs G1 = (V1 , E1 ) and G2 = (V2 , E2 ) are isomorphic if there exists a bijection f from V1
to V2 with the property that a and b are adjacent in G1 if and only if f (a) and f (b) are adjacent in G2 , for
all a and b in V1 .
Example 4.11. Show that the graphs G = (V, E) and H = (W, F), displayed in
Figure, are isomorphic.
Example 4.12. Show that the graphs displayed in Figure are not isomorphic
Example 4.13. Determine whether the graphs shown in Figure are isomorphic.
Example 4.14. Determine whether the graphs shown in Figure are isomorphic.
Example 5.1.
• a, d, c, f, e is a simple path of
length 4.
• d, e, c, a is not a path.
• b, c, f, e, b is a circuit of length 4.
Ly Anh Duong Chapter 9 Graphs duongla3@fe.edu.vn 41 / 68
Connectedness In Undirected Graphs
5 Connectivity
Definition 5.2
An undirected graph is called connected (liên thông) if there is a path between every pair of distinct
vertices of the graph. An undirected graph that is not connected is called disconnected.
Theorem 5.1
There is a simple path between every pair of distinct vertices of a connected undirected graph.
Remark 5.1. Any strongly connected directed graph is also weakly connected.
Example 5.3. G is strongly connected, H is weakly connected.
Definition 5.4: (with directed or undirected edges, with multiple edges and loops allowed)
• Let G be a graph with adjacency matrix A with respect to the ordering v1 , v2 , ..., vn of the vertices of
the graph,
• The number of different paths of length r from vi to vj equals the (i, j) th entry of Ar , where r is
a positive integer.
Example 5.4. How many paths of length four are there from a to d in the simple
graph G in figure
• Thus, we have
Definition 5.5
• Cut vertex (or articulation point) (điểm cắt, đỉnh khớp): the removal from a graph of a vertex and
all incident edges produces a subgraph with more connected components.
• Cut edge (or bridge) (cạnh cắt, cầu nối): An edge whose removal produces a graph with more
connected components than in the original graph.
Example 5.5. Find the cut vertices and cut edges in the graph shown in Figure.
Example 5.6. Using path to determine whether two graphs are isomorphic.
G and H have the same
• Number of vertices
• Number of edges
• 2 vertices degree 2
• 4 vertices degree 3
But, H has a simple circuit
with length 3 and G has a
simple circuit with length 4.
Thus, they are not isomor-
phic.
Ly Anh Duong Chapter 9 Graphs duongla3@fe.edu.vn 47 / 68
Path and Isomorphism
5 Connectivity
Example 5.7. Using path to determine whether two graphs are isomorphic
The Swiss mathematician Leonhard Euler solved this problem. His solution,
published in 1736, may be the first use of graph theory.
Can once travel across all the bridges once and return to starting point?
His answer: All of vertices must have even-degree.
Ly Anh Duong Chapter 9 Graphs duongla3@fe.edu.vn 51 / 68
Euler Paths & Circuits
6 Euler & Hamilton Paths
Definition 6.1
• An Euler circuit in a graph G is a simple circuit containing every edge of G,
• An Euler path in G is a simple path containing every edge of G.
Theorem 6.1
1. A connected multigraph with at least two vertices has an Euler circuit if and only if each of its
vertices has even degree.
2. A connected multigraph has an Euler path but not an Euler circuit if and only if it has exactly two
vertices of odd degree.
Definition 6.2
• A simple path in a graph G that passes through every vertex exactly once is called a Hamilton path.
• A simple circuit in a graph G that passes through every vertex exactly once is called a Hamilton
circuit.
Use Dijkstra’s algorithm to find the length of a shortest path between the vertices
a and z in the weighted graph displayed in Figure.
Ly Anh Duong Chapter 9 Graphs duongla3@fe.edu.vn 59 / 68
Example
7 Shortest-Path Problems
Theorem 7.2
Dijkstra’s algorithm uses O(n2 ) operations (additions and comparisons) to find the length of a shortest
path between two vertices in a connected simple undirected weighted graph with n vertices.
Example 7.1. Find the length of a shortest path between a and z in the given
weighted graph.
Theorem 7.4
Dijkstra’s algorithm uses O(n2 ) operations (additions and comparisons) to find the length of a shortest
path between two vertices in a connected simple undirected weighted graph with n vertices.
Example 7.2. Find the length of a shortest path between a and z in the given
weighted graph.
Q1. Study a simple graph having the Q2. For which values of n do Kn have
degree sequence an Euler path but no Euler circuit?
{5, 5, 4, 4, 4, 3, 3, 2, 2, 2, 2, 1, 1}. If the Select one:
graph has n edges, then n = . . .
a. 2
Select one:
a. 38 b. 1
b. 19
c. 3
c. 20
d. 17 d. 2m, ∀m > 1
Q3. Every Euler circuit in K11 is a path Q4. If Kn has x edges and y vertices,
of length . . . then x = . . ., y = . . .
Select one: Select one:
a. 45 a. n + 1, n
b. 2n, n + 1
b. 22
n(n + 1)
c. 11 c. , n
2
d. 55 n(n − 1) n
d. , 2
2
Q5. The incidence matrix of the graph Q6. Study the statements:
K2,3 has the size of i. K2,3 has no an Euler circuit, but
Select one: has an Euler path.
ii. K2,3 has an Euler circuit.
a. 30
Which statements is true?
b. 5 × 6 Select one:
a. None
c. 2 × 3
b. i
d. 6 × 5 c. ii
d. Both
n(n − 1)
Answer. Q1. 19; Q2. 2; Q3. 55; Q4. , n; Q5. 5 × 6; Q6. i
2
Ly Anh Duong Chapter 9 Graphs duongla3@fe.edu.vn 67 / 68
Q&A
Thank you for listening!