Graph theory_notes after mst
Graph theory_notes after mst
7.2. Example. The following graph contains 9 vertices (0 to 8) with weighted edges as
shown in the figure below. We will be using Dijkstra’s algorithm to find the shortest path
from vertex "0" to vertex "4".
8 7
1 2 3
9
4 2
11 14
0 8 4 4
8
7 7 6 10
1 6 2 5
Step-by-Step Execution:
We initialize the distances to all vertices as infinity, except for the source vertex (0), which
is set to 0. The table below shows the progress of the algorithm at each step.
Initial Setup
• Source: Vertex 0
• Distances: dist(0) = 0, all other vertices set to 1.
• Unvisited Set: {0, 1, 2, 3, 4, 5, 6, 7, 8}
Step 1: Visit Vertex 0
• Neighbors: {1, 7}
• Update distances:
dist(1) = min(1, 0 + 4) = 4
dist(7) = min(1, 0 + 8) = 8
GRAPH THEORY LECTURE NOTES 29
k = 0: k = 1: k = 4:
2 4 2 2 1
1 3 2 1 3 3 4 2
4 2 1 4
2 1 k = 2: 3 4 2 1
1 3
1 4
4 2
2 3 4 2 1 2 2 1
3 1 3 4 2
2 3 2 1 4 2
3 4 4 2 1 3
1 2
4 1 k = 3:
4 2 2 2
1 3 4
G 4 2 2
2 1 3 4
The distance matrix at each iteration of k, with the updated distances in bold is shown
below.
Matrix for k = 1
A B C D
A 0 1 2 1
B 4 0 2 1
C 1 1 0 2
D 1 1 1 0
Matrix for k = 2
A B C D
A 0 1 2 1
B 4 0 2 1
C 1 1 0 2
D 3 1 1 0
Matrix for k = 3
A B C D
A 0 1 2 0
B 4 0 2 4
C 1 1 0 2
D 3 1 1 0
Matrix for k = 4
A B C D
A 0 1 2 0
B 4 0 2 4
C 5 1 0 2
D 3 1 1 0
Comparison: For graphs with non-negative edge weights, Dijkstra’s algorithm can be
used to find all shortest paths from a single vertex with running time ⇥(|E| + |V | log |V |).
Thus, running Dijkstra starting at each vertex takes time ⇥(|E||V | + |V |2 log |V |). Since
|E| = O(|V |2 ), this yields a worst-case running time of repeated Dijkstra of O(|V |3 ). While
this matches the asymptotic worst-case running time of the Floyd-Warshall algorithm, the
constants involved matter quite a lot. When a graph is dense (i.e., |E| ⇡ |V |2 ), the Floyd-
Warshall algorithm tends to perform better in practice. When the graph is sparse (i.e., |E|
is significantly smaller than |V |2 ), Dijkstra tends to dominate.
7.4. DFS and BFS. Breadth-First Search (BFS) and Depth-First Search (DFS) are two
fundamental algorithms used for traversing or searching graphs and trees.
DFS The algorithm starts at the root node and explores as far as possible along each
branch before backtracking.
Breath-first search (BFS) It starts at the tree root and explores all nodes at the present
depth prior to moving on to the nodes at the next depth level.
32 M. RANA AND ARUN MAITI
7.5. Algorithms to find minimum spanning tree. Minimum spanning tree is a spanning
tree whose sum of edge weights is the smallest possible. Prim’s algorithm is a greedy algo-
rithm that finds a minimum spanning tree for a weighted undirected graph. The algorithm
for MST is as follows :
Step 1. Intialize with an arbitrary vertex.
Step 2. Perform the following steps till there are vertices that are not included in the MST
. This vertices are known as fringe vertex
Step 3. Find edges connecting any tree vertex with the fringe vertices and find the minimum
among them.
Step 4. Add the chosen edge to the MST if it does not form any cycle.
8. Planar graph
A graph that can be drawn in the plane without edges crossing is planar. A graph drawn
in the plane is a plane graph. A face or region of a plane graph is a connected region of
R2 \ G. We define the size of a region to be the number of edges it has.
The set of regions of a planer graph G is denoted by R(G).
Consider the following graph:
GRAPH THEORY LECTURE NOTES 33
D C
A B
It is clearly planar. It has five vertices, eight edges: AB, BC, CD, DA, AE, BE, CE, and
DE. There are 5 regions in total: Face 1: The outer unbounded region around the entire
graph, Face 2: The triangle ABE, Face 3: The triangle BCE, Face 4: The triangle CDE,
Face 5: The triangle DAE.
Theorem 8.1 (Euler’s Formula). For a connected planar graph G,
|V (G)| |E(G)| + |R(G)| = 2
Proof. Proof by induction on the number of edges.
The statement is clearly true for a graph with 1 edges.
Given a graph G with n+1 edges. We can remove its one edge say e. By induction hypothesis
|V (G \ e)| |E(G \ e)| + |R(G \ e)| = 2
It is easy to see that |V (G \ e)| = |V (G)|, |E(G \ e)| = |E(G)| 1 and |R(G \ e)| = |R(G)| 1.
Substituting the values in the above equality, we obtain
|V (G)| |E(G)| + |R(G)| = 2
This completes the induction, hence the proof??
⇤
The following result gives criteria to verify planarity of graphs.
Theorem 8.2. For a planar graph G, |E(G)| 3|G| 3. Furthermore, if there is no triangle
in G, then |E(G)| 2|G| 4.
Let us denote |E(G)| = e and |G| = n. Let R(G) = {R1 , R2 , · · · , Rr } denote all the regions
of G. We know that for a planar graph
deg(Ri ) 3
This implies X
deg(Ri ) 3m (1)
By handshake lemma for planar graph
X
deg(Ri ) = 2e (2)
From (1) and (2), we get
3r 2e. (3)
From Euler’s formula, we know that
r=e n+2
Using (3) we get
2
=) (e n + 2) e
3
=) e 3n 6 (4)
34 M. RANA AND ARUN MAITI
The complete graph K4 on 4 vertices is planar and can be drawn without edge crossings,
as shown below.
2
1 3
4
A subdivision of a graph is formed by inserting vertices along its edges. For example,
subdividing an edge (u, v) by adding a vertex w gives two edges (u, w) and (w, v).
Consider the complete graph K3 and it’s subdivision by adding one vertex in the middle
of each edge of K3 . This transforms each edge into two edges.
C
A B
F E
A D B
Subdivision does not reduce the inherent "complexity" of a graph. Any attempted planar
embedding of a subdivision of a graph would still require the same non-crossing requirements
as the original. Adding vertices along edges does not create additional faces or change the
essential connectivity of the graph.
Theorem 8.3. A graph G is planar if and only if G has a subgraph that is a subdivision (or
homemorphic) of K3,3 or K5 .
"Only if " part only. . To show t K5 , K3,3 are not planar, we can use Theorem 8.3. ⇤
9. Graph Coloring
In this notes coloring of a graph will always refer to a proper vertex coloring, namely a
labeling of the graph’s vertices with colors such that no two adjacent vertices have the same
color. Since a vertex with a loop could never be properly colored, it is understood that graphs
in this context are loopless.
The smallest number of colors needed to color a graph G is called its chromatic number,
and is denoted by (G) (often denoted by (G) as well).
GRAPH THEORY LECTURE NOTES 35
Example 9.1. We will color the states of India (or any other country) with minimum number
of colors so that no two neghbouring states have the same color. For that we can first construct
the dual graph, and then use graph coloring algorithms described further below. The following
images show states of India can be colored using only 4 colors. Can you do it with lesser?
The following observations are the immediate consequences of the above definitions.
1. A graph is 1-chromatic ( (G) = 1) if and only if it is a null graph.
2. A graph having at least one edge is at least 2-chromatic.
3. A graph G having n vertices has (G) n.
4. If H is subgraph of a graph G, then (H) (G).
5. A complete graph with n vertices is n-chromatic
6. A cycle of length n 3 is 2-chromatic if n is even and 3-chromatic if n is odd.
Theorem 9.2. Every tree with n 2 vertices is bicolorable (2-chromatic or (G) = 2).
Proof. Let T be a tree with n 2 vertices. Consider any vertex v of T and assume T to be
rooted at vertex v . Assign color 1 to v. Then assign color 2 to all vertices which are adjacent
to v. Let v1 , v2 , · · · , vr be the vertices which have been assigned color 2. Now assign color 1
to all the vertices which are adjacent to v1 , v2 , · · · , vr . Continue this process till every vertex
in T has been assigned the color. We observe that in T all vertices at odd distances from
v have color 2, and v and vertices at even distances from v have color 1. Therefore along
any path in T , the vertices are of alternating colors. Since there is one and only one path
between any two vertices in a tree, no two adjacent vertices have the same color. Thus T is
colored with two colors. Hence T is 2-chromatic. ⇤
The converse of the above theorem is not true, i. e., every 2-chromatic graph need not be
a tree. The next result charaterises 2-chromatic graphs.
Theorem 9.3. A graph is 2-chromatic ( (G) = 2) if and only if it has no odd cycles.
Proof. Let G be a connected graph with cycles of only even length and let T be a spanning
tree in G. Then, by Theorem 9.2, T can be coloured with two colours. Now add the chords
36 M. RANA AND ARUN MAITI
to T one by one. As G contains cycles of even length only, the end vertices of every chord
get different colours of T . Thus G is coloured with two colours and hence is 2-chromatic. If
G is disconnected we can use the same argument for each of its components.
Conversely, let G be 2-chromatic then G cannot contain an odd-cycle as to color an odd cycle
one requires at least 3 colors. ⇤
A greedy algorithm for graph coloring. Let (G) denote the maximum degree of
vertices of a given graph G. For a given vertex ordering {v1 , v2 , · · · , vn } of G, and ordering
of (G) + 1 many colors C1 , C2 , · · · , C (G)+1 , we color first vertex (v1 ) with the first color
(C1 ), and then each vertex is given the color with the smallest number that is not already
used by one of its neighbors.
Remark 9.4. This algorithm never uses more than d(vi ) + 1 colors to color i-th vertex vi .
Therefore, we have
1 (G) (G) + 1.
The following result due to Brooks improves the above bound in most cases.
Theorem 9.5 (Only the statement). For a connected graph G,
(G) (G)
unless G is a complete graph or an odd cycle.
For planar graphs, e.g., dual graphs of maps of the states of a country, we have a much
better result to determine the chromatic numbers. Here we state and prove a weaker version
of such a result.
Theorem 9.6 (Five color theorem). For any planar graph G, (G) 5
The proof uses the following lemma.
Lemma 9.7. A planar graph G contains a vertex of degree at most 5.
Proof. We may assume that G is connected. Suppose all the vertex of G has degree 6 or
more, then by hand-shake lemma
2|E(G)| 6|V (G)|.
On the other hand, for a planar graph G we have seen earlier that
|E(G)| 3|V (G)| 3 =) 2|E(G)| 6|V (G) 6|
So there is a contradiction. Hence the proof of the lemma.
⇤
Proof of five color theorem. Proof by induction on the number of vertices. Let us assume
that the statement is true for all graphs with n vertices. Then we will show that it is true
for a given graph G with n + 1 vertices
By the above lemma, there exist a vertex v in G such that deg(v) 5.
Case 1. deg(v) 4. So, there are at most 4 colors that have been used on the neighbors of
v. There is at least one color then available for v, see below pic. So G can be colored with
five colors.
Case 2. deg(v) = 5. If two of the neighbors of v are colored with the same color, then
there is a color available for v. So we may assume that all the neighbors v, v1 , v2 , v3 , v4 , v5
GRAPH THEORY LECTURE NOTES 37
are colored with colors C1 , C2 , C3 , C4 , C5 in the clockwise order. Rest of the proof will be
presented later on.
⇤
The following stronger version of the above theorem is known to be true.
Theorem 9.8 (four color theorem). For any planar graph G, (G) 4
Exercise Find the chromatic number of the Petersen graph?
Proof. We know that for (Kn ) = n. Therefore, for k < n the proposition follows from the
definition of PG . For k n, for an arbitrary ordering of vertices v1 , v2 , v3 , · · · vn of Kn , we
have k choices of colors for the first vertex v1 , and next, (k 1) choices for v2 and so on.
Continuing this way, we have (k n + 1) choices of colors for the vertex vn . Thus, the total
number of choices to color for all the n vertices is k(k 1)(k 2) · · · (k n + 1). ⇤
The fact that the number of k-colorings is a polynomial in k follows from a recurrence
relation called the deletion–contraction recurrence or Fundamental Reduction Theorem.
Theorem 9.10. Let G be a simple graph, for a pair of vertices u and v the graph G/uv
is obtained by merging the two vertices and removing any edges between them. If u and v
are adjacent in G, let G uv denote the graph obtained by removing the edge uv. Then the
numbers of k-colorings of these graphs satisfy:
Fig. 9.2
Thus, we obtain
PG (k) = k(k 1)(k 2) · · · (k 5+1) + 4k(k 1)(k 2)(k 4+1) + 3k(k 1)(k 3+1)
= k5 6k 4 + 14k 3 15k 2 + 6k
References
[RD] Reinhard Diestel, Graph Theory, Springer, Graduate text book.
[ND] Narshingh Deo. Graph Theory with Applications to Engineering and Computer Science, 1974.