Graph Theory Basics for CS Majors
Graph Theory Basics for CS Majors
Chapter 1 outline :
1. Presentation
2. Intuitive definition of a graph
3. Mathematical definition of a graph
4. Order, orientation, and multiplicity
4.1. Order
4.2. Orientation
4.3. Multiplicity
5. Relations between the elements of a graph
5.1. Relations between vertices
5.2. Relations between arcs and vertices
5.3. Qualifiers of graphs
6. Matrices associated with a graph
6.1. Vertex-arc incidence matrix
6.2. Adjacency or vertex-vertex incidence matrix
6.3. Vertex-edge incidence matrix
6.4. Condensed form of sparse matrices
7. Other graph representations
7.1. Representation by linked lists
7.2. Tabular representations
8. Vocabulary related to connectivity
8.1. Chain, path, and length
8.2. Connectivity
8.3. Circuit and cycle
8.4. Cocycle and cocircuit
1. Presentation
Graphs model many concrete situations where interacting objects are involved.
Road, rail or air interconnections between different urban areas,
Links between the components of an electronic circuit,
The plan of a city and its one-way streets,...
Graphs make it easier to manipulate objects and their relationships with a natural graphical
representation. All the mathematical techniques and tools developed in Graph Theory make it
easy to demonstrate properties, to deduce resolution methods, algorithms, ...
Matière : Graph theory 2nd Year Bachelor of Computer Science – 3rd Semester Responsable de la matière : Amiar Lotfi
Chapter 1 : Basic definitions page 2
What is the shortest path (in distance or time) to get from one city to another ?
How can we minimize the total length of connections in a circuit ?
Can we make one-way street without making impossible a circulation in the city ?
Example 1 :
In the following example, we have :
- A set of vertices : {1,2,3,4}
- A set of arcs : {(1,2) , (1,3), (3,2) , (3,4) , (4,3)}
Matière : Graph theory 2nd Year Bachelor of Computer Science – 3rd Semester Responsable de la matière : Amiar Lotfi
Chapter 1 : Basic definitions page 3
Example :
The graph in figure Fig.1. is of order 4.
The graph in figure Fig.2. is of order 6.
4.2. Orientation
4.2.1. Oriented graph :
A graph 𝐺 is directed if its links can only be traversed in one direction. The orientation of the
links is indicated by arrows on the links. A directed link is called an arc and is denoted by 𝑢
(see Fig.1.).
The arc 𝑢 is presented as follows :
Fig.4. Loop
4.2.2. Undirected graph :
It is made up not of couples, but of unordered pairs of vertices.
When studying some properties, it happens that the orientation of the links plays no role. We
are simply interested in the existence of link(s) between two vertices (without specifying the
order). A link without orientation is called an edge (see Fig.2.).
Remark :
In the undirected case, instead of writing 𝐺 = (𝑋, 𝑈) and 𝑢 = (𝑥𝑖 , 𝑥𝑗 ), it is often preferred to
use the notation 𝐺 = (𝑋, 𝐸) et 𝑒 = ⌈𝑥𝑖 , 𝑥𝑗 ⌉.
4.3. Multiplicity
The multiplicity of the arc 𝑢 is called the number 𝑚𝑖𝑗 defined by :
Matière : Graph theory 2nd Year Bachelor of Computer Science – 3rd Semester Responsable de la matière : Amiar Lotfi
Chapter 1 : Basic definitions page 4
Example :
Remarks :
- A multigraph 𝐺 = (𝑋, 𝐸) is a graph in which there can be multiple edges between two
vertices.
- A graph 𝐺 = (𝑋, 𝐸) is simple :
i. if it is not a multigraph ;
ii. there are no loops.
Example :
Matière : Graph theory 2nd Year Bachelor of Computer Science – 3rd Semester Responsable de la matière : Amiar Lotfi
Chapter 1 : Basic definitions page 5
Example :
𝑥2 Г+
𝐺 (𝑥1 ) = {𝑥1 , 𝑥5 } Г−
𝐺 (𝑥1 ) = {𝑥1 , 𝑥2 , 𝑥3 }
𝑥1 + −
Г𝐺 (𝑥2 ) = {𝑥1 } Г𝐺 (𝑥2 ) = {𝑥5 }
Г+
𝐺 (𝑥3 ) = {𝑥1 , 𝑥4 } Г−
𝐺 (𝑥3 ) = ∅
Г+
𝐺 (𝑥4 ) = {𝑥5 }
−
Г𝐺 (𝑥4 ) = {𝑥3 , 𝑥5 }
+
𝑥3 𝑥4 𝑥5 Г𝐺 (𝑥5 ) = {𝑥2 , 𝑥4 } Г−
𝐺 (𝑥5 ) = {𝑥1 , 𝑥4 }
Matière : Graph theory 2nd Year Bachelor of Computer Science – 3rd Semester Responsable de la matière : Amiar Lotfi
Chapter 1 : Basic definitions page 6
Example :
In the example of figure Fig.9., if we define the set 𝐴 as follows :
Remark :
A loop is counted twice.
Special cases :
- A vertex 𝑥 ∈ 𝑋 such that 𝑑(𝑥) = 0 is called an isolated vertex.
- A vertex 𝑥 ∈ 𝑋 such that 𝑑(𝑥) = 1 is called a pendant vertex.
- We denote by 𝛿(𝐺) = 𝑚𝑖𝑛𝑥∈𝑋 {𝑑(𝑥)}, the minimum degree of 𝐺 ;
and by ∆(𝐺) = 𝑚𝑎𝑥𝑥∈𝑋 {𝑑(𝑥)}, the maximum degree of 𝐺.
Remark :
When 𝛿(𝐺) = ∆(𝐺) = 𝑘 (i.e. ∀𝑥 ∈ 𝑋, 𝑑(𝑥) = 𝑘), the graph 𝐺 is called k-regular.
Matière : Graph theory 2nd Year Bachelor of Computer Science – 3rd Semester Responsable de la matière : Amiar Lotfi
Chapter 1 : Basic definitions page 7
An arc 𝑢 is called incident to 𝐴 ⊂ 𝑋 outward if the initial endpoint of 𝑢 ∈ 𝐴 but not its final
endpoint, and we denote it as 𝑢 ∈ 𝜔𝐺+ (𝐴).
An arc 𝑢 is called incident to 𝐴 ⊂ 𝑋 inward if the final endpoint of 𝑢 ∈ 𝐴 but not its initial
endpoint, and we denote it as 𝑢 ∈ 𝜔𝐺− (𝐴).
Matière : Graph theory 2nd Year Bachelor of Computer Science – 3rd Semester Responsable de la matière : Amiar Lotfi
Chapter 1 : Basic definitions page 8
Example :
Example :
Remark :
A complete and simple graph on 𝑛 vertices is denoted 𝐾𝑛 and is called an n-clique.
Example :
Matière : Graph theory 2nd Year Bachelor of Computer Science – 3rd Semester Responsable de la matière : Amiar Lotfi
Chapter 1 : Basic definitions page 9
Example :
𝑥1 𝑥2 𝑥1 𝑥2
(𝐺) its complementary graph (𝐺̅ ) is :
𝑥3 𝑥4 𝑥3 𝑥4
𝑥1 𝑥3
𝑥2 𝑥4
X1 X2
𝑥1 𝑥3
𝑥5
𝑥2 𝑥4
X1 X2 X3
Fig.18. Multipartite graph
Matière : Graph theory 2nd Year Bachelor of Computer Science – 3rd Semester Responsable de la matière : Amiar Lotfi
Chapter 1 : Basic definitions page 10
A subgraph of 𝐺 consists of considering only a part of the vertices of 𝑿 and the links induced
by 𝑼.
The subgraph generated by a set 𝐴 ⊂ 𝑋 is the graph 𝐺𝐴 = (𝐴, 𝑊) whose vertices are the
points of 𝐴 and whose arcs 𝑊 are those of 𝐺 that have both endpoints in 𝐴.
For example, if 𝐺 represents the daily air connections between the main cities of the world, a
possible subgraph is to limit it to the daily connections between the main European cities.
Let 𝐺 = (𝑋, 𝑈) be a graph and 𝐴 ⊂ 𝑋 and 𝑉 ⊂ 𝑈. The graph 𝐺𝐴,𝑉 = (𝐴, 𝑉𝐴 ) such that 𝑉𝐴 is
the set of arcs of 𝐺 having their 2 endpoints in 𝐴.
Example :
Fig.20. A graph G Fig.21. A sub-graph of G Fig.22. A partial graph of G Fig.23. A partial sub-graph
of G
Matière : Graph theory 2nd Year Bachelor of Computer Science – 3rd Semester Responsable de la matière : Amiar Lotfi
Chapter 1 : Basic definitions page 11
0 means that the vertex and the arc are not adjacent,
1 means that the vertex is the initial endpoint of the arc,
-1 means that the vertex is the terminal endpoint of the arc.
Example :
Consider the graph below :
a b c d e f g h
1 1 1 0 0 0 0 0 0
2 -1 0 -1 1 0 0 0 0
3 0 -1 1 0 -1 0 -1 0
4 0 0 0 -1 1 1 0 -1
5 0 0 0 0 0 -1 1 1
6.2. Adjacency or vertex-vertex incidence matrix
Definition 1 :
A graph 𝐺 = (𝑋, 𝑈) can be represented by an 𝑛 × 𝑛 matrix (𝑛 = |𝑋|), called an adjacency
matrix, which can only contain the values 0, 1. Each row and each column of the matrix
represents a vertex. Thus, a box indicates the relationship that exists between two vertices :
Example :
Matière : Graph theory 2nd Year Bachelor of Computer Science – 3rd Semester Responsable de la matière : Amiar Lotfi
Chapter 1 : Basic definitions page 12
Definition 2 :
The vertex-vertex adjacency or incidence matrix (also called the associated matrix) of a graph
𝐺 = (𝑋, 𝑈) is a square matrix where each row corresponds to a vertex of 𝐺 and each column
also corresponds to a vertex of 𝐺. The elements of the associated matrix indicate the number
of oriented arcs in the same direction connecting two vertices. The general term of the matrix
is :
𝑎𝑖𝑗 = 𝑚𝐺+ (𝑥𝑖 , 𝑥𝑗 ).
𝑚𝐺+ (𝑥𝑖 , 𝑥𝑗 ) : the multiplicity of a pair (𝑥𝑖 , 𝑥𝑗 ), is the number of arcs (in the graph 𝐺 ) having 𝑥𝑖
as the initial endpoint and 𝑥𝑗 as the final endpoint.
Remark :
Unlike the vertex-arc incidence matrix, loops can be represented using this matrix.
Example :
Consider the graph below :
Matière : Graph theory 2nd Year Bachelor of Computer Science – 3rd Semester Responsable de la matière : Amiar Lotfi
Chapter 1 : Basic definitions page 13
0 means that the vertex and the edge are not adjacent,
1 means that the edge is incident to the vertex.
Example :
The arcs of figure Fig.24., being numbered from 𝑎 to ℎ. We can write the SIF matrix as
follows:
The condensed form of the vertex-vertex incidence matrix of the graph in Fig.25. is as
follows:
Matière : Graph theory 2nd Year Bachelor of Computer Science – 3rd Semester Responsable de la matière : Amiar Lotfi
Chapter 1 : Basic definitions page 14
𝑥𝑖 𝑥𝑗 𝑚𝐺+ (𝑥𝑖 , 𝑥𝑗 )
𝑏 ℎ 1
𝑐 𝑐 1
𝑑 𝑒 1
𝑑 ℎ 1
𝑒 𝑓 1
𝑒 ℎ 1
𝑓 𝑒 2
(𝑔 𝑐 1)
7. Other graph representations
7.1. Representation by linked lists
A graph can be represented by lists. We propose here one possibility, but many others can be
suitable. First, we define a list of nodes and to each node, we associate a list of successor
nodes and a list of predecessor nodes.
Example :
The graph in Figure Fig.24. will be represented as follows :
a b c d e f g h
TN 2 3 2 4 3 5 3 4
Matière : Graph theory 2nd Year Bachelor of Computer Science – 3rd Semester Responsable de la matière : Amiar Lotfi
Chapter 1 : Basic definitions page 15
𝑆𝑃[𝑖] : (for all 𝑥𝑖 ∈ 𝑋) points to the first successor of vertex 𝑥𝑖 in the list 𝑆𝐿.
1 2 3 4 5 6 7 8 9
SL h c e h f h e e c
Remark :
The absence of a successor for a vertex is encoded by a zero in 𝑺𝑷.
A path from 𝑥 to 𝑦 is a chain in which the arcs are oriented and such that :
𝑥 is the initial endpoint of the first arc,
𝑦 is the terminal endpoint of the last arc,
all subsequent neighbors of a vertex in a (oriented) path are its descendants,
all previous neighbors of a vertex in a (oriented) path are its ancestors,
the terminal endpoint of an arc is the initial endpoint of the arc that follows it in the
sequence.
The length of the path or chain corresponds to the number of arcs or edges traversed.
A simple path is a path that does not contain the same arc multiple times.
A simple chain is a chain that does not contain the same edge multiple times.
An elementary path is a path that does not pass through a node more than once.
Matière : Graph theory 2nd Year Bachelor of Computer Science – 3rd Semester Responsable de la matière : Amiar Lotfi
Chapter 1 : Basic definitions page 16
An elementary chain is a chain that does not pass through a node more than once.
Example :
Consider the graph below :
8.2. Connectivity
8.2.1. Connectivity in an undirected graph
We define on the vertices set of a graph 𝐺 = (𝑋, 𝑈) the binary relation 𝑅, called the
connectivity relation, defined by :
𝑥 = 𝑦 (𝑖𝑠𝑜𝑙𝑎𝑡𝑒𝑑 𝑣𝑒𝑟𝑡𝑒𝑥)
𝑥 𝑅 𝑦 (𝑥 𝑎𝑛𝑑 𝑦 ℎ𝑎𝑣𝑒 𝑎 𝑐𝑜𝑛𝑛𝑒𝑐𝑡𝑖𝑣𝑖𝑡𝑦 𝑟𝑒𝑙𝑎𝑡𝑖𝑜𝑛𝑠ℎ𝑖𝑝) ⇔ { 𝑜𝑟
∃ 𝑎 𝑐ℎ𝑎𝑖𝑛 𝑙𝑖𝑛𝑘𝑖𝑛𝑔 𝑥 𝑡𝑜 𝑦
Matière : Graph theory 2nd Year Bachelor of Computer Science – 3rd Semester Responsable de la matière : Amiar Lotfi
Chapter 1 : Basic definitions page 17
A graph is called connected if it has only one connected component. Each connected
component is a connected graph.
A directed graph is weakly connected if there is a chain between any pair of vertices in the
graph when the orientation of the arcs is not considered.
Remark :
A directed graph is connected if the associated undirected graph is connected.
A strongly connected component is the subset of vertices such that between any two vertices,
there exists a strong connectivity relation. Moreover, any node outside the component has no
strong connectivity relationship with any elements of the component.
Matière : Graph theory 2nd Year Bachelor of Computer Science – 3rd Semester Responsable de la matière : Amiar Lotfi
Chapter 1 : Basic definitions page 18
A graph is called strongly connected if it has only one strongly connected component. Each
strongly connected component is a strongly connected graph.
Examples :
Matière : Graph theory 2nd Year Bachelor of Computer Science – 3rd Semester Responsable de la matière : Amiar Lotfi
Chapter 1 : Basic definitions page 19
Example :
8.4.1. Cocycle
Given a subset vertices 𝐴 of a graph 𝐺 = (𝑋, 𝑈), where 𝐴 𝑋, we define :
𝑤 + (𝐴) = {𝑢 = (𝑥𝑖 , 𝑥𝑗 ) ∈ 𝑈/𝑥𝑖 ∈ 𝐴 𝑎𝑛𝑑 𝑥𝑗 ∉ 𝐴} : the set of arcs having their initial
endpoint in 𝐴, and their final endpoint in (𝑋 − 𝐴) (called the set of arcs incident
externally to 𝐴).
𝑤 − (𝐴) = {𝑢 = (𝑥𝑖 , 𝑥𝑗 ) ∈ 𝑈/𝑥𝑖 ∉ 𝐴 𝑎𝑛𝑑 𝑥𝑗 ∈ 𝐴} : the set of arcs having their final
endpoint in 𝐴, and their initial endpoint in (𝑋 − 𝐴) (called the set of arcs incident
internally to 𝐴).
𝑤(𝐴) = 𝑤 + (𝐴) ∪ 𝑤 − (𝐴) : set of arcs incident to 𝐴.
Any arcs set of the form 𝑤(𝐴) is called a cocycle of 𝐴.
8.4.2. Cocircuit
A cocircuit is a cocycle whose all arcs are oriented in the same direction, that’s to say a set of
arcs of the form 𝑤 + (𝐴) (outward from 𝐴) or 𝑤 − (𝐴) (inward to 𝐴).
Example :
Matière : Graph theory 2nd Year Bachelor of Computer Science – 3rd Semester Responsable de la matière : Amiar Lotfi