DM – Introduction to graphs
NGUYEN Hoang Thach
nhthach@[Link]
22/05/2020
Outline
1 Graph – Definition and examples
(Undirected) Graph
Directed graph
2 Basic properties of graphs
Undirected case
Directed case
3 Some special simple graphs
4 Subgraphs and graph operations
5 Graph representation
Adjacency list
Adjacency matrix
Incidence matrix
H.-T. Nguyen Graph 22/05/2020 2 / 44
Outline
1 Graph – Definition and examples
(Undirected) Graph
Directed graph
2 Basic properties of graphs
Undirected case
Directed case
3 Some special simple graphs
4 Subgraphs and graph operations
5 Graph representation
Adjacency list
Adjacency matrix
Incidence matrix
H.-T. Nguyen Graph 22/05/2020 3 / 44
Graph
Definition
A (undirected) graph G = (V , E ) is defined by:
1 A non-empty set V of vertices;
2 A set E of edges, which are unordered pairs of vertices.
Note: In this course, we only consider finite graphs.
H.-T. Nguyen Graph 22/05/2020 4 / 44
Visual presentation of graphs
Each vertex is represented by a point or a circle
Each edge is represented by a line connecting its endpoints
Example:
Figure: Rosen, p. 652
V = {a, b, c, d, e, f , g}
E = {{a, b} , {a, f } , {b, c} , {b, e} , {b, f } , {c, d} , {c, e} , {c, f } , {e, f }}
H.-T. Nguyen Graph 22/05/2020 5 / 44
Multigraph and loop
Definition
A graph is simple if there is at most one edge between any pair of vertices.
Edges connecting the same pair of vertices are called multiple edges. A graph
having multiple edges is also called a multigraph.
A loop is an edge connecting a vertex to itself.
Figure: Rosen, p. 650
Note: By convention, “graphs” refer to simple graphs without loops unless
otherwise stated.
H.-T. Nguyen Graph 22/05/2020 6 / 44
Examples
Social networks:
Each vertex represents a person
Two friends are connected by an edge
Figure: Rosen, p. 645
H.-T. Nguyen Graph 22/05/2020 7 / 44
Examples
Niche overlap graphs (ecology):
Each vertex represents a species
Two competing species are connected by an edge
Figure: Rosen, p. 648
H.-T. Nguyen Graph 22/05/2020 8 / 44
Examples
Protein interaction graphs (biology):
Each vertex represents a protein
Two proteins that interact are connected by an edge
Figure: Rosen, p. 648
H.-T. Nguyen Graph 22/05/2020 9 / 44
Examples
Computer networks:
Each vertex represents a server
Each edge represents a link
Figure: Rosen, p. 642
H.-T. Nguyen Graph 22/05/2020 10 / 44
Outline
1 Graph – Definition and examples
(Undirected) Graph
Directed graph
2 Basic properties of graphs
Undirected case
Directed case
3 Some special simple graphs
4 Subgraphs and graph operations
5 Graph representation
Adjacency list
Adjacency matrix
Incidence matrix
H.-T. Nguyen Graph 22/05/2020 11 / 44
Directed graph
Definition
A directed graph (or digraph) G = (V , A) is defined by:
1 A non-empty set V of vertices (or nodes);
2 A set A of arcs, which are ordered pairs of vertices.
The notions of simple directed graphs, multiple arcs, loops and directed
multigraphs are defined similarly to the undirected case.
Figure: Rosen, p. 650
H.-T. Nguyen Graph 22/05/2020 12 / 44
Examples
Round-robin tournament:
Each node represents a team
Each team play against every other team, an arc goes from the winning team
to the losing team (assume that there are no ties)
Figure: Rosen, p. 649
H.-T. Nguyen Graph 22/05/2020 13 / 44
Examples
Dependency (software):
Each node represents a module
An arc (a, b) is added if module b depends on module a
Figure: Rosen, p. 647
H.-T. Nguyen Graph 22/05/2020 14 / 44
Examples
Precedence graph:
Each node represents a statement
An arc (Si , Sj ) is added if statement Si must wait for statement Sj to be
executed
Figure: Rosen, p. 647
H.-T. Nguyen Graph 22/05/2020 15 / 44
Examples
. . . and many other examples:
citation graphs (academic)
co-author graphs (academic)
genealogical graphs
road networks
the Web
etc.
H.-T. Nguyen Graph 22/05/2020 16 / 44
Outline
1 Graph – Definition and examples
(Undirected) Graph
Directed graph
2 Basic properties of graphs
Undirected case
Directed case
3 Some special simple graphs
4 Subgraphs and graph operations
5 Graph representation
Adjacency list
Adjacency matrix
Incidence matrix
H.-T. Nguyen Graph 22/05/2020 17 / 44
Neighborhood
Let G = (V , E ) be a graph.
Definition
Two vertices u and v are adjacent if they are endpoints of the same edge e.
In this case, u is a neighbor of v and the edge e is incident with the vertices
u and v .
The set of all neighbors of a vertex v is the neighborhood of v and is denoted
by N(v ). The neighborhood of a set A of vertices
S is the union of the
neighborhoods of the vertices in A: N(A) = N(v ).
v ∈A
Figure: Rosen, p. 652
H.-T. Nguyen Graph 22/05/2020 18 / 44
Degree
Definition
The degree of a vertex v , denoted by deg(v ) or simply d(v ), is the number of
edges incident with it. A loop contributes 2 to the degree of its endpoint.
Figure: Rosen, p. 652
Note:
A vertex is isolated if it has degree 0; it is pendant if it has degree 1.
In a multigraph, the degree of a vertex may be greater than the number of its
neighbors!
H.-T. Nguyen Graph 22/05/2020 19 / 44
The handshaking theorem
Theorem
Let G = (V , E ) be an undirected graph. Then
X
deg(v ) = 2 |E | .
v ∈V
Proof: Each edge contributes 2 to the sum of degrees of all the vertices.
Corollary
There are an even number of vertices of odd degrees.
H.-T. Nguyen Graph 22/05/2020 20 / 44
Outline
1 Graph – Definition and examples
(Undirected) Graph
Directed graph
2 Basic properties of graphs
Undirected case
Directed case
3 Some special simple graphs
4 Subgraphs and graph operations
5 Graph representation
Adjacency list
Adjacency matrix
Incidence matrix
H.-T. Nguyen Graph 22/05/2020 21 / 44
Adjacency
Let G = (V , A) be a digraph.
Definition
If a = (u, v ) is an arc, then u is adjacent to v and v is adjacent from u; u is the
initial node and v is the end node of a; a is an out-going arc of u and an in-going
arc of v .
Figure: Rosen, p. 650
H.-T. Nguyen Graph 22/05/2020 22 / 44
Degrees
Definition
The out-degree (resp. in-degree) of a node v , denoted by deg+ (v ) or d + (v ) (resp.
deg− (v ) or d − (v )), is the number of out-going (resp. in-going) arcs of v .
Theorem
Let G = (V , A) be a directed graph. Then
X X
deg+ (v ) = deg− (v ) = |A| .
v ∈V v ∈V
H.-T. Nguyen Graph 22/05/2020 23 / 44
Complete graphs
Definition
A complete graph of n vertices, denoted by Kn , is a simple graph having n vertices
and such that every pair of vertices is connected by an edge.
Figure: Rosen, p. 655
H.-T. Nguyen Graph 22/05/2020 24 / 44
Paths
Definition
A path on n vertices, denoted by Pn , is a simple graph having n vertices
{v1 , v2 , . . . , vn } and n − 1 edges {{vi , vi+1 } |1 ≤ i ≤ n − 1}.
Figure: P6
H.-T. Nguyen Graph 22/05/2020 25 / 44
Cycles
Definition
A cycle on n ≥ 3 vertices, denoted by Cn , is a simple graph having n vertices
{v1 , v2 , . . . , vn } and n edges {{vi , vi+1 } |1 ≤ i ≤ n} (vn+1 ≡ v1 ).
Figure: Rosen, p. 655
H.-T. Nguyen Graph 22/05/2020 26 / 44
Wheel graphs
Definition
A wheel graph of n + 1 vertices (n ≥ 3), denoted by Wn , is a simple graph
obtained from Cn by adding a new vertex and connecting it to every vertex of Cn .
Figure: Rosen, p. 655
H.-T. Nguyen Graph 22/05/2020 27 / 44
Hypercubes
Definition
A n-dimensional hypercube, or an n-cube, denoted by Qn , is a simple graph in
which
the vertices are the binary strings of length n
two strings are adjacent iff. they differs at only one position.
Figure: Rosen, p. 655
H.-T. Nguyen Graph 22/05/2020 28 / 44
Hypercubes
Construction of Qn+1 from Qn :
1 Consider two copies Qn : Qn and Qn0
2 Change the labels of Qn and Qn0 :
Qn : s → 0s
Qn0 : s → 1s
3 Add the edges {0s, 1s}
H.-T. Nguyen Graph 22/05/2020 29 / 44
Bipartite graphs
Definition
A graph G = (V , E ) is a bipartite graph if V can be partitioned into two sets V1
and V2 so that every edge connects a vertex in V1 and a vertex in V2 .
The pair (V1 , V2 ) is a bipartition of the vertices of G.
Figure: A bipartite graph.
H.-T. Nguyen Graph 22/05/2020 30 / 44
Bipartite graphs
Examples:
The path P5 is a bipartite graph.
The cycle C6 is a bipartite graph.
The cycle C3 is not a bipartite graph.
The complete graph K4 is not a bipartite graph.
The hypercubes Q1 , Q2 , Q3 are bipartite graphs.
H.-T. Nguyen Graph 22/05/2020 31 / 44
Recognizing bipartite graphs
Is this graph bipartite?
Figure: Rosen, p. 656
It is.
H.-T. Nguyen Graph 22/05/2020 32 / 44
Recognizing bipartite graphs
Theorem
A simple graph is bipartite iff. its vertices can be colored by two different colors so
that no two adjacent vertices have the same color.
Examples:
Cn is bipartite iff. n is even.
Pn is bipartite for all n.
Qn is bipartite for all n.
H.-T. Nguyen Graph 22/05/2020 33 / 44
Complete bipartite graphs
Definition
A complete bipartite graph Km,n is a bipartite graph with bipartition V = V1 ∪ V2
such that:
V1 has m vertices, V2 has n vertices;
Two vertices are connected by an edge iff. one vertex is in V1 , the other is in
V2 .
Figure: Rosen, p. 658
H.-T. Nguyen Graph 22/05/2020 34 / 44
Subgraphs
Definition
A subgraph of a graph G = (V , E ) is a graph H = (W , F ) where W ⊂ V , F ⊂ E .
Examples:
Every graph is a subgraph of itself.
The path Pn is a subgraph of the cycle Cm if n ≤ m.
The cycle Cn is a subgraph of the wheel Wn .
Every graph on n vertices is a subgraph of Kn .
H.-T. Nguyen Graph 22/05/2020 35 / 44
Subgraphs
Definition
Let G = (V , E ) be a simple graph and let W be a subset of vertices. The
subgraph induced by W is the subgraph of G where:
The set of vertices is W ;
The set of edges consists of all edges having both endpoints in W .
Examples:
Cn is the subgraph of Wn induced by the “outer” vertices.
If m ≤ n, Km is the subgraph of Kn induced by a subset of m vertices.
Pn is not an induced subgraph of Cn .
Qn−1 is the subgraph of Qn induced by all vertices whose labels starts with 0.
H.-T. Nguyen Graph 22/05/2020 36 / 44
Some operations on graphs
Let G = (V , E ) be a simple graph.
Edge removal:
G − e = (V , E \ {e}).
Result: a subgraph of G.
Vertex removal:
G − v = (V \ {v } , E \ {e | e is incidence with v }).
Result: a subgraph of G.
Edge contraction:
Remove an edge, then merge its endpoints.
Result: not necessarily a subgraph!
H.-T. Nguyen Graph 22/05/2020 37 / 44
Outline
1 Graph – Definition and examples
(Undirected) Graph
Directed graph
2 Basic properties of graphs
Undirected case
Directed case
3 Some special simple graphs
4 Subgraphs and graph operations
5 Graph representation
Adjacency list
Adjacency matrix
Incidence matrix
H.-T. Nguyen Graph 22/05/2020 38 / 44
Adjacency list
Figure: Rosen, p. 668
H.-T. Nguyen Graph 22/05/2020 39 / 44
Adjacency list
Figure: Rosen, p. 669
H.-T. Nguyen Graph 22/05/2020 40 / 44
Outline
1 Graph – Definition and examples
(Undirected) Graph
Directed graph
2 Basic properties of graphs
Undirected case
Directed case
3 Some special simple graphs
4 Subgraphs and graph operations
5 Graph representation
Adjacency list
Adjacency matrix
Incidence matrix
H.-T. Nguyen Graph 22/05/2020 41 / 44
Adjacency matrix
Definition
The adjacency matrix of a graph G = (V , E ) is a V × V matrix of integer entries
A = (au,v ) such that:
(
1 if u, v are adjacent,
au,v =
0 otherwise.
Example: (with vertex ordering a, b, c, d, e)
H.-T. Nguyen Graph 22/05/2020 42 / 44
Outline
1 Graph – Definition and examples
(Undirected) Graph
Directed graph
2 Basic properties of graphs
Undirected case
Directed case
3 Some special simple graphs
4 Subgraphs and graph operations
5 Graph representation
Adjacency list
Adjacency matrix
Incidence matrix
H.-T. Nguyen Graph 22/05/2020 43 / 44
Incidence matrix
Definition
The incidence matrix of a graph G = (V , E ) is a V × E matrix of integer entries
M = (mv ,e ) such that:
(
1 if e is incident with v ,
mv ,e =
0 otherwise.
Example:
Note: The notions of adjacency matrix and incidence matrix can be extended for
multigraphs, for directed graphs, etc.
H.-T. Nguyen Graph 22/05/2020 44 / 44