0% found this document useful (0 votes)
12 views158 pages

DMS Unit v GraphTheory

The document outlines the course 'Discrete Mathematical Structures' offered by the Department of CSE at RV College of Engineering, detailing its content across various units. Key topics include graph theory concepts such as matchings, coloring, algorithms, and fundamental definitions related to graphs. The document also discusses properties of graphs, including isomorphism, degree sequences, and types of graphs, providing examples and definitions throughout.

Uploaded by

tarunhs.cd22
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views158 pages

DMS Unit v GraphTheory

The document outlines the course 'Discrete Mathematical Structures' offered by the Department of CSE at RV College of Engineering, detailing its content across various units. Key topics include graph theory concepts such as matchings, coloring, algorithms, and fundamental definitions related to graphs. The document also discusses properties of graphs, including isomorphism, degree sequences, and types of graphs, providing examples and definitions throughout.

Uploaded by

tarunhs.cd22
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 158

RV College of

Engineering Go, Change the World

Dept. of CSE, RVCE


Presentation Outline
RV College of
Engineering Go, Change the World

Course Title Discrete Mathematical


Structures
Course Code CS241AT

Host Dept Dept.of CSE


RV College of
Engineering
Course Contents & Availability of study Go, Change the World
material
UNIT-IV
Matchings and Factors: Min-Max theorem, Independent sets and covers,
Dominating sets, maximum bipartite matching.
Coloring of graphs: The chromatic number of a graph, Results for general graphs,
The chromatic polynomial of a graph, Basic properties of chromatic polynomial,
chordal graphs, powers of graphs, Edge coloring of graphs.
UNIT-V
Graph algorithms: Graph connectivity algorithms, Breadth first search and Depth
first search, Shortest path algorithms, Dijikstra’s shortest path algorithm, Minimum
cost spanning tree algorithms, Algorithm of Kruskal’s and Prim’s.
RV College of
Engineering Go, Change the World
RV College of
Engineering UNIT-I Go, Change the World

The key to Euler’s solution was in a very simple abstraction of the puzzle. Let us redraw our diagram of the city of K
̈onigsberg by representing each of the land masses as a vertex and representing each bridge as an edge connecting the vertices
corresponding to the land masses. We now have a graph that encodes the necessary information. The problem reduces to
finding a ”closed walk” in the graph which traverses each edge exactly once, this is called an Eulerian circuit. Does such a
circuit exist?
RV College of
Engineering UNIT-I Go, Change the World

Definition 1. A graph is an ordered triple (V(G), E(G),IG), where V(G) is a nonempty set ,E(G) is a set disjoint
from V(G) , and IG is an “incidence ”relation that associates with each element of E(G) an unordered pair of
elements(same or distinct) of V(G). Elements of V(G) are called the vertices (or nodes or points) of G, and
elements of E(G) are called the edges (or lines) of G. V(G) and E(G) are the vertex set and edge set of G,
respectively. If, for the edge e of G, IG(e)={u, v}, we write IG(e)=uv.

Example 1. If V(G)={v1, v2, v3, v4, v5}, E(G)={e1, e2, e3, e4, e5, e6} and I G is given by IG(e1)={v1, v5},
IG(e2)={v2, v3), IG(e3)={v2, v4}, IG(e4)={v2, v5)}, IG(e5)={v2, v5}, IG(e6)={v3, v3}, then (V(G), E(G), IG) is a
graph.

Diagrammatic Representation of a Graph. Each graph can be represented by a diagram in the plane. In this
diagram, each vertex of the graph is represented by a point, with distinct vertices being represented by distinct
points. Each edge is represented by a simple “Jordan” arc joining two (not necessarily distinct) vertices. The
diagrammatic representation of a graph aids in visualizing many concepts related to graphs and the systems of
which they are models. In a diagrammatic representation of a graph, it is possible that two edges intersect at a point
that is not necessarily a vertex of the graph.
RV College of
Engineering UNIT-I Go, Change the World

Example 2. In the graph of Fig.1., edge e3 =v2v4, edges e4 and e5 form multiple edges, e6 is a loop at v3,
N(v2)= {v3, v4, v5 }, N(v3) = {v2}}, N[v2 ]= {v2,v3, v4,v5}, and N[v2 ]= N(v2) U {v2}. Further, v2 and v5 are adjacent vertices and e3 and
e4 are adjacent edges.

Definition 3. A graph is called finite if both V(G) and E(G) are finite. A graph that is not finite is called an infinite graph.
Unless otherwise stated, all graphs considered in this course are finite. Throughout the course, we denote by n(G) and m(G)
the number of vertices and edges of the graph G respectively. The number n(G) is called the order of G and m(G) is the size
of G. When explicit reference to the graph G is not needed, V(G), E(G), n(G), and m(G) will be denoted simply by V, E, n, and
m respectively.
RV College of
Engineering UNIT-I Go, Change the World

Definition 2. If IG (e)={u,v}, then the vertices u and v are called the end vertices or ends of the edge e.
Each edge is said to join its ends, in this case, we say that e is incident with each one of its ends. Also, the vertices u and v
are then incident with e.

A set of two or more edges of a graph G is called a set of multiple or parallel edges if they have the same pair of distinct
ends. If e is an edge with end vertices u and v, we write e= uv.

An edge for which the two ends are the same is called a loop at the common vertex.

A vertex u is a neighbor of v in G, if uv is an edge of G, and u ≠ v. The set of all neighbors of v is the open neighborhood of
v or the neighbor set of v, and is denoted by N(v), the set N[v]= N(v) U {v} is the closed neighborhood of v in G.

Vertices u and v are adjacent to each other in G if and only if there is an edge of G with u and v as its ends. Two distinct
edges e and f are said to be adjacent if and only if they have a common end vertex.

A graph is simple if it has no loops and no multiple edges. Thus, for a simple graph G, the incidence function I G is one-to-
one. Hence, an edge of a simple graph is identified with the pair of its ends. A simple graph therefore may be considered as
an ordered pair (V(G), E(G)), where V(G) is a nonempty set and E(G) is a set of unordered pairs of elements of V(G) (each
edge of the graph being identified with the pair of its ends).
RV College of
Engineering UNIT-I Go, Change the World

Example 2. In the graph of Fig(1), edge e3 = v2v4;, edges e4 and e5 form multiple edges, e6 is a loop at v3, N(v2)={v3,v4,v5},
N(v3)= {v2}, N[v2 ]= {v2,v3,v4,v5} and N[v2 ]= N(v2 ) U {v2}. Further, v2 and v5 are adjacent vertices and e3 and e4 are adjacent
edges.

Definition 3. A graph is called finite if both V(G) and E(G) are finite. A graph that is not finite is called an infinite graph.
Unless otherwise stated, all graphs considered are finite. Throughout this course, we denote by n(G) and m(G) the number of
vertices and edges of the graph G, respectively. The number n(G) is called the order of G and m(G) is the size of G. When
explicit reference to the graph G is not needed, V(G), E(G), n(G), and m(G) will be denoted simply by V, E, n, and m,
respectively.

Figure (2) is a graph with loops and multiple edges, while Fig (3) represents a simple graph.

Definition 4. A graph is said to be labeled if its n vertices are distinguished from one another by labels such as v1;v2;:::;vn
In Fig(4) the graph G is labeled and the graph H is not labeled.
RV College of
Engineering UNIT-I Go, Change the World
RV College of
Engineering UNIT-I Go, Change the World
RV College of
Engineering UNIT-I Go, Change the World
RV College of
Engineering UNIT-I Go, Change the World

Graph Isomorphism: A graph can exist in different forms having the same number of vertices, edges, and also the
same edge connectivity. Such graphs are called isomorphic graphs. Note that we label the graphs in this chapter mainly for the
purpose of referring to them and recognizing them from one another.

Isomorphic Graphs
Two graphs G1 and G2 are said to be isomorphic if −
•Their number of components (vertices and edges) are same.
•Their edge connectivity is retained.

There exists a function ‘f’ from vertices of G 1 to vertices of G2 [f: V(G1) ⇒ V(G2)], such that
Case (i): f is a bijection (both one-one and onto)
Case (ii): f preserves adjacency of vertices, i.e., if the edge {U, V} ∈ G 1, then the edge {f(U), f(V)} ∈ G2, then G1 ≡ G2.
Note
If G1 ≡ G2 then −
|V(G1)| = |V(G2)|
|E(G1)| = |E(G2)|
Degree sequences of G1 and G2 are same.
If the vertices {V1, V2, .. Vk} form a cycle of length K in G1, then the vertices {f(V1), f(V2),… f(Vk)} should form a cycle of
length K in G2.
All the above conditions are necessary for the graphs G 1 and G2 to be isomorphic, but not sufficient to prove that the graphs are
RV College of
Engineering UNIT-I Go, Change the World
RV College of
Engineering UNIT-I Go, Change the World
RV College of
Engineering UNIT-I Go, Change the World

Fundamental Definitions
A cycle is a simple graph whose vertices can be cyclically ordered so that two vertices are adjacent if and only if they are
consecutive in the cyclic ordering.

We usually think of paths and cycles as subgraphs within some larger graph. A subgraph H of a graph G, is a graph such that
V (H) ⊆ V (G) and E(H) ⊆ E(G) satisfying the property that for every e ∈ E(H), where e has endpoints u, v ∈ V (G) in the
graph G, then u, v ∈ V (H) and e has endpoints u, v in H, i.e. the edge relation in H is the same as in G.

A graph G is connected if for every u, v V (G) there exists a u, v-path in G. Otherwise G is called disconnected. The maximal
connected subgraphs of G are called its components.

A walk is a list v0, e1, v1, . . . , ek, vk of vertices and edges such that for 1 ≤ I ≤ k, the edge ei has endpoints vi−1 and vi.
A trail is a walk with no repeated edge. A u, v-walk or u, v-trail has first vertex u and last vertex v. When the first and last
vertex of a walk or trail are the same, we say that they are closed. A closed trail is called a circuit.

A path is a simple graph whose vertices can be ordered so that two vertices are adjacent if and only if they are consecutive
in the ordering. A path which begins at vertex u and ends at vertex v is called a u, v-path.
RV College of
Engineering UNIT-I Go, Change the World

With this new terminology, we can consider paths and cycles not just as subgraphs, but also as ordered lists of vertices and
edges. From this point of view, a path is a trail with no repeated vertex, and a cycle is a closed trail (circuit) with no repeated
vertex other than the first vertex equals the last vertex.
Alternatively, we could consider the sub graph traced out by a walk or trail.

(a) (b) (c) (d) (e) (f) (g) (h)

1. Which graphs are simple?


2. Suppose that for any graph, we decide to add a loop to one of the vertices. Does this affect whether or not the
graph is Eulerian?
3. Which graphs are connected?
4. Which graphs are Eulerian? Trace out an Eulerian circuit or explain why an Eulerian circuit is not possible.
5. Are there any graphs above that are not Eulerian, but have an Eulerian trail?
6. Give necessary conditions for a graph to be Eulerian.
7. Give necessary conditions for a graph to have an Eulerian trail.
In graphRV College of
theory,
Engineering the degree (or valency) of a vertex of a graph is the number of edges that are incident to the
Go, Change the World

vertex, and in a multigraph, loops are counted twice.[1] The degree of a vertex is denoted deg(v).
The maximum degree of a graph, denoted by ∆(G), and the minimum degree of a graph, denoted by δ(G), are the
maximum and minimum degree of its vertices.

In the graph gelow, the maximum degree is 5 and the minimum degree is 0.

In a regular graph, every vertex has the same degree, and so we can speak of the degree of the graph. A
complete graph (denoted Kn , where n is the number of vertices in the graph) is a special kind of regular graph
where all vertices have the maximum degree.

The degree sum formula states that, given a graph G=(V,E), ∑deg(v)=2|E|.

The formula implies that in any undirected graph, the number of vertices with odd degree is even. This statement
(as well as the degree sum formula) is known as the handshaking lemma. The latter name comes from a popular
mathematical problem, which is to prove that in any group of people, the number of people who have shaken
hands with an odd number of other people from the group is even.
RV College of
Go, Change the World
Degree sequence
Engineering

The degree sequence of an undirected graph is the non-increasing sequence of its vertex degrees, for the below graph
it is (5, 3, 3, 2, 2, 1, 0).

The degree sequence is a graph invariant so isomorphic graphs have the same degree sequence. However, the degree
sequence does not, in general, uniquely identify a graph; in some cases, non-isomorphic graphs have the same degree
sequence.

Two non-isomorphic graphs with the same degree sequence (3, 2, 2, 2, 2, 1, 1, 1).
RV College of
Engineering Go, Change the World

A directed graph is a set of vertices (nodes) connected by edges, with each node having a direction associated with it. In
the example fig (1) below, the graph can be traversed from vertex a to b, but not from vertex b to a.

Indegree of a vertex is the number of edges entering in to that vertex.


Outdegree of a vertex is the number of edges leaving that vertex.
RV College of
Engineering Go, Change the World

Definition: 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.
In other words, you can determine the degree of a vertex in a displayed
graph by counting the lines that touch it.
The degree of the vertex v is denoted by deg(v).
A vertex of degree 0 is called isolated, since it is not adjacent to any vertex.
Note: A vertex with a loop at it has at least degree 2 and, by definition, is not
isolated, even if it is not adjacent to any other vertex.
A vertex of degree 1 is called pendant. It is adjacent to exactly one other
vertex.
RV College of
Engineering Go, Change the World

Example: Which vertices in the following graph are


isolated, which are pendant, and what is the maximum
degree? What type of graph is it?
i h
d
a e
g
b c f j

Solution: Vertex f is isolated, and vertices a, d and j are pendant. The


maximum degree is deg(g) = 5. This graph is a pseudograph (undirected,
loops).
RV College of
Engineering Go, Change the World

Let us look at the same graph again and determine the number of
its edges and the sum of the degrees of all its vertices:

i h
d
a e
g
b c f j

Result: There are 9 edges, and the sum of all degrees is 18. This is
easy to explain: Each new edge increases the sum of degrees by
exactly two.
RV College of
Engineering Go, Change the World

The Handshaking Theorem: Let G = (V, E) be an undirected graph with


e edges. Then
2e = vV deg(v)

Example: How many edges are there in a graph with 10 vertices, each
of degree 6?
Solution: The sum of the degrees of the vertices is 610 = 60.
According to the Handshaking Theorem, it follows that 2e = 60, so
there are 30 edges.
RV College of
Engineering Go, Change the World

Theorem: An undirected graph has an even number of vertices of odd


degree.
Proof: Let V1 and V2 be the set of vertices of even and odd degrees,
respectively (Thus V1  V2 = , and V1 V2 = V).
Then by Handshaking theorem
2|E| = vV deg(v) = vV1 deg(v) + vV2 deg(v)
Since both 2|E| and vV1 deg(v) are even,
vV2 deg(v) must be even.
Since deg(v) if odd for all vV2, |V2| must be even.
RV College of
Engineering Go, Change the World

Definition: 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.
The vertex u is called the initial vertex of (u, v), and v is called the terminal
vertex of (u, v).
The initial vertex and terminal vertex of a loop are the same.
RV College of
Engineering Go, Change the World

Definition: In a graph with directed edges, the in-degree of a vertex v,


denoted by deg-(v), is the number of edges with v as their terminal vertex.
The out-degree of v, denoted by deg+(v), is the number of edges with v as
their initial vertex.

Question: How does adding a loop to a vertex change the in-degree and out-
degree of that vertex?
Answer: It increases both the in-degree and the out-degree by one.
RV College of
Engineering Go, Change the World

Example: What are the in-degrees and out-degrees of the


vertices a, b, c, d in this graph:

deg-(b) = 4
deg (a) = 1
-
a deg+(b) = 2
deg+(a) = 2 b

deg-(d) = 2
deg-(c) = 0
deg+(d) = 1 d c deg+(c) = 2
RV College of
Engineering Go, Change the World

Theorem: Let G = (V, E) be a graph with directed edges. Then:


vV deg-(v) = vV deg+(v) = |E|

This is easy to see, because every new edge increases both the sum of in-
degrees and the sum of out-degrees by one.
RV College of

Special Graphs
Engineering Go, Change the World

Definition: The Null graph on n vertices is the simple graph that contains
exactly n vertices and no edges.
Example:

Definition: The Path graph or linear graph is a graph whose


vertices can be listed in the order v₁, v₂, …, vₙ such that the
edges are {vᵢ, vᵢ₊₁} where i = 1, 2, …, n − 1. The Path graph
on n vertices is denoted by Pn.
Example:
RV College of

Special Graphs
Engineering Go, Change the World

Definition: The complete graph on n vertices, denoted by Kn, is the simple


graph that contains exactly one edge between each pair of distinct vertices.

K1 K2 K3 K4 K5
RV College of

Special Graphs
Engineering Go, Change the World

Definition: The cycle Cn, n  3, consists of n vertices v1, v2, …, vn and edges {v1,
v2}, {v2, v3}, …, {vn-1, vn}, {vn, v1}.

C3 C4 C5 C6
RV College of

Special Graphs
Engineering Go, Change the World

Definition: We obtain the wheel Wn when we add an additional vertex to the


cycle Cn, for n  3, and connect this new vertex to each of the n vertices in Cn by
adding new edges.

W3 W4 W5 W6
RV College of

Special Graphs
Engineering Go, Change the World

Definition: The n-cube, denoted by Qn, is the 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.

110 111
10 11 100 101
010 011
0 1
00 01 000 001

Q1 Q2 Q3
Special Graphs
RV College of
Engineering Go, Change the World

Definition: A simple graph is called bipartite if its vertex set V can be


partitioned into two disjoint nonempty sets V1 and V2 such that every edge in
the graph connects a vertex in V1 with a vertex in V2 (so that no edge in G
connects either two vertices in V1 or two vertices in V2).
For example, consider a graph that represents each person in a village by a
vertex and each marriage by an edge.
This graph is bipartite, because each edge connects a vertex in the subset of
males with a vertex in the subset of females (if we think of traditional
marriages).
RV College of

Special Graphs
Engineering Go, Change the World

Example I: Is C3 bipartite?
v1 No, because there is no way to partition the vertices into two sets so that there are no
edges with both endpoints in the same set.

v2 v3

Example II: Is C6 bipartite?


v1 v1
v6 v6
Yes, because we can display C6 like
v2 this: v5 v2
v5

v3 v4
v3 v4
RV College of

Special Graphs
Engineering Go, Change the World

Definition: The complete bipartite graph Km,n is the graph that has its vertex set
partitioned into two subsets of m and n vertices, respectively. Two vertices are
connected if and only if they are in different subsets.

K3,2 K3,4
RV College of
Go, Change the World

Operations on Graphs
Engineering

Definition: A subgraph of a graph G = (V, E) is a graph H = (W, F) where WV


and FE.
Note: Of course, H is a valid graph, so we cannot remove any endpoints of
remaining edges when creating H.
Example:

K5 subgraph of K5
RV College of
Go, Change the World

Operations on Graphs
Engineering

Definition: The union of two simple graphs G1 =


(V1, E1) and G2 = (V2, E2) is the simple graph with vertex set V1  V2 and edge set
E1  E2.
Example 1:The union of G1 and G2 is denoted by G1  G2.

G1 G2 G1  G2 = K5
Operations on Graphs
RV College of
Engineering Go, Change the World

Example 2: The union of G and H is denoted by G  H.


Operations on Graphs
RV College of
Engineering Go, Change the World

Definition: The Intersection of two simple graphs G1 =(V1, E1) and G2 = (V2, E2) is
the simple graph with vertex set V1 ∩ V2 and edge set E1 ∩ E2.
Example : The Intersection of G and H is denoted by G ∩ H.
Operations on Graphs
RV College of
Engineering Go, Change the World

Definition: The Disjoint Union of two or more simple graphs G1 =(V1, E1)
and G2 = (V2, E2) is the simple graph with vertex set V1 U V2 and edge set
E1 U E2, and V1 ∩ V2 =Ø and edge set E1 ∩ E2= Ø.
Example:
Operations on Graphs
RV College of
Engineering Go, Change the World

Definition: The Join of two simple graphs G1 =(V1, E1) and G2 = (V2, E2) is
the simple graph with vertex set V1 U V2 and edge set E1 U E2, and from
each vertex belongs to V1 add an edge to each vertex belongs to V2.
Example:
Operations on Graphs
RV College of
Engineering Go, Change the World

Definition: The Complement of a graph G =(V, E) is a G2 = (V2, E2) such


that V2 =V and E2 contains all the edges which are not in G.
Example:
RV College of
Engineering Go, Change the World

Definitions:
A graph H is called a sub graph of G if V(H)  V(G) and E(H)  E(G).
If H is a sub graph of G, then G is said to be a super graph of H.
A sub graph H of a graph G is a proper sub graph of G if either V(H) ≠V(G)
or E(H) ≠ E(G).
A sub graph H of G is said to be an induced sub graph of G if each edge of G
having its ends in V(H) is also an edge of H.
A sub graph H of G is a spanning sub graph of G if V(H)= V(G).
RV College of
Engineering Go, Change the World
RV College of
Go, Change the World
Engineering
Graph representations
RV College of
Go, Change the World
Engineering
Graph representations

• edge list: an unordered list of all edges in the graph

2
1 3
1 1 1 2 2 3 5 5 5 7 7
2 5 6 7 3 4 6 7 4 4
4
6
5
RV College of
Go, Change the World
Engineering
Graph representations

Edge List: Pros and Cons


• advantages
• easy to loop/iterate over all edges

• disadvantages
• hard to tell if an edge
exists from A to B
• hard to tell how many edges
a vertex touches (its degree)

1 1 1 2 2 3 5 5 5 7
2 5 6 7 3 4 6 7 4 4
RV College of
Go, Change the World
Engineering
Graph representations

Adjacency Matrix
• adjacency matrix: an n × n matrix where:
• the nondiagonal entry aij is the number of edges joining
vertex i and vertex j (or the weight of the edge joining vertex i
and vertex j)
• the diagonal entry aii corresponds to the number of loops
(self-connecting edges) at vertex i
RV College of
Go, Change the World
Engineering
Graph representations

Adjacency Matrix: Pros and Cons


• advantages
• fast to tell whether edge exists between
any two vertices i and j (and to get its
weight)

• disadvantages
• consumes a lot of memory on sparse
graphs (ones with few edges)
• redundant information for undirected
graphs
RV College of
Go, Change the World
Engineering
Graph representations
Adjacency Matrix Example
• How do we figure out the degree of a given
vertex?
• How do we find out whether an edge exists
from A to B?
• How
1 2 could
3 4 5 we
6 7 look for loops in the graph? 2
1 0 1 0 0 1 1 0 1 3
2 1 0 1 0 0 0 1
3
4
0 1 0 1 0 0 0 7
0 0 1 0 1 0 1
5
1 0 0 1 0 1 1 4
6
7 1 0 0 0 1 0 0 6
0 1 0 1 1 0 0 5
RV College of
Go, Change the World
Engineering
Graph representations
Adjacency Lists
• adjacency list: stores edges as individual linked lists of
references to each vertex's neighbors
RV College of
Go, Change the World
Engineering
Graph representations

Adjacency List: Pros and Cons


• advantages:
• new nodes can be added easily
• new nodes can be connected with existing nodes
easily
• "who are my neighbors" easily answered
• disadvantages:
• determining whether an edge exists between
two nodes: O(average degree)
RV College of
Go, Change the World
Engineering
Graph representations
Adjacency List Example
• How do we figure out the degree of a given vertex?
• How do we find out whether an edge exists from A to B?
• How could we look for loops in the graph?
2
1 1 3
2 5 6
2 3 1 7
3
4
2 4 7
3 7 5
5
6 6 1 7 4 4
7 1 5
4 5 2 6
5
RV College of
Go, Change the World
Engineering
Graph representations
Runtime table

 n vertices, m edges
Edge Adjacency Adjacency
 no parallel edges
List List Matrix
 no self-loops
Space n+m n+m n2
Finding all adjacent
m deg(v) n
vertices to v

Determining if v is
m deg(v) 1
adjacent to w
adding a vertex 1 1 n2
adding an edge to v 1 1 1
removing vertex v m n? n2
removing an edge from
m deg(v) 1
v
RV College of
Go, Change the World
Engineering
Graph representations

Adjacency matrix for directed


graph
Matrix[i][j] = 1 if (v , v )E i j
0 if (vi, vj)E
1 2 3 4 5
v1 v2 v3 v4 v5
v2
v1 v3 1 v1 0 1 0 0 0
2 v2 0 0 0 1 0
v4 v5 3 v3 0 1 0 1 0
4 v4 0 0 0 0 0
G
5 v5 0 0 1 1 0
RV College of
Go, Change the World
Engineering
Graph representations

Adjacency list for directed


graph
1 v1  v2
v2 2 v2  v4
v1 v3
3 v3  v2  v4
4 v4
v4 v5
5 v5  v3  v4
G
Weighted graph
RV College of
Engineering Go, Change the World

• If each edge in G is assigned a weight, it is called a weighted graph

Chicago 1000 New York

3500
2000

Houston
RV College of
Engineering
Adjacency matrix for weighted Go, Change the World
undirected graph

Matrix[i][j] = w(vi, vj) if (vi, vj)E or (vj, vi)E


∞ otherwise
1 2 3 4 5
v2 v1 v2 v3 v4 v5
v1 2 v3
5 1 v1 ∞ 5 ∞ ∞ ∞
4 3 7 2 v2 5 ∞ 2 4 ∞
v4
8 v5
3 v3 0 2 ∞ 3 7
G 4 v4 ∞ 4 3 ∞ 8
5 v5 ∞ ∞ 7 8 ∞
RV College of
Go, Change the World
Engineering
Graph representations

Adjacency list for weighted undirected


graph
v2 1 v1  v2(5)
v1 2 v3
5
4 2 v2  v1(5)  v3(2)  v4(4)
3 7
3 v3  v2(2)  v4(3)  v5(7)
v4
8 v5
4 v4  v2(4)  v3(3)  v5(8)
G 5 v5  v3(7)  v4(8)
RV College of
Go, Change the World
Engineering
Graph representations
RV College of
Go, Change the World
Engineering
Graph representations

Incidence matrix for undirected graph


RV College of
Go, Change the World
Engineering
Graph representations

Incidence matrix for directed graph


RV College of
Go, Change the World
Engineering
Trees

General tree example

Example 1:
A

B C D E

F G
RV College of
Go, Change the World
Engineering
Trees
What is a tree?
• Connected acyclic graph is called as tree.
• Trees are structures used to represent hierarchical relationship
• Each tree consists of nodes and edges
• Each node represents an object
• Each edge represents the relationship between two nodes.

node
edge

66
RV College of
Go, Change the World
Engineering
Trees

Some applications of Trees

Organization Chart Expression Tree

President
+
VP VP
Personnel Marketing * 5

3 2
Director Director
Customer Sales
Relation
RV College of
Engineering Go, Change the World

Terminology I

• For any two nodes u and v, if there is an edge pointing from u to v, u is


called the parent of v while v is called the child of u. Such edge is denoted
as (u, v).
• In a tree, there is exactly one node without parent, which is called the
root. The nodes without children are called leaves.

root

u
u: parent of v
v: child of u
v
leaves
68
RV College of
Engineering Go, Change the World

Terminology II

• In a tree, the nodes without children are called leaves. Otherwise, they are called internal nodes.

internal nodes

leaves
RV College of
Engineering Go, Change the World

Terminology III
• If two nodes have the same parent, they are siblings.
• A node u is an ancestor of v if u is parent of v or parent of parent of v or

• A node v is a descendent of u if v is child of v or child of child of v or …

v and w are siblings


u and v are ancestors of x v w
v and x are descendents of u
x
RV College of
Engineering Go, Change the World

Terminology IV

• A subtree is any node together with all its descendants.

T
A subtree of T
v v
RV College of
Engineering Go, Change the World

Terminology V
• Level of a node n: number of nodes on the path from root to node n
• Height of a tree: maximum level among all of its node

Level 1

Level 2
height=4
n Level 3

Level 4
Binary Tree
RV College of
Engineering Go, Change the World

• Binary Tree: Tree in which every node has at most 2 children


• Left child of u: the child on the left of u
• Right child of u: the child on the right of u

x: left child of u
u v y: right child of u
w: right child of v
x y z: left child of w
w
z
Full binary tree
RV College of
Engineering Go, Change the World

• If T is empty, T is a full binary tree of height 0.


• If T is not empty and of height h >0, T is a full binary tree if both subtrees
of the root of T are full binary trees of height h-1.

Full binary tree


of height 3
Property of binary tree (I)
RV College of
Engineering Go, Change the World

• A full binary tree of height h has 2h-1 nodes


No. of nodes = 20 + 21 + … + 2(h-1)
= 2h – 1

Level 1: 20 nodes

Level 2: 21 nodes

Level 3: 22 nodes
Tree Traversal
RV College of
Engineering Go, Change the World

• Given a binary tree, we may like to do some operations on all nodes in a binary tree. For
example, we may want to double the value in every node in a binary tree.
• To do this, we need a traversal algorithm which visits every node in the binary tree.
RV College of
Engineering Go, Change the World

Ways to traverse a tree

• There are three main ways to traverse a tree:


• Pre-order:
• (1) visit the root node, (2) recursively visit left subtree in pre-order, (3) recursively visit right
subtree in pre-order.
• In-order:
• (1) recursively visit left subtree in in-order, (2) visit the root node, (3) recursively visit the right
subtree in in-order.
• Post-order:
• (1) recursively visit left subtree in post-order, (2) recursively visit right subtree in post-order, (3)
visit the root node.
• Level-order:
• Traverse the nodes level by level
• In different situations, we use different traversal algorithm.
Examples for expression tree
RV College of
Engineering Go, Change the World

• By pre-order, (prefix)
+*23/84
• By in-order, (infix) +
2*3+8/4
• By post-order, (postfix) * /
23*84/+
2 3 8 4
• By level-order,
+*/2384
• Note 1: Infix is what we read!
• Note 2: Postfix expression can be computed efficiently using stack
RV College of
Go, Change the World
Engineering
Trees
1. A simple graph is a tree if and only if any two distinct vertices are connected by a unique path.
2. Every connected graph contains a spanning tree.
3. The number of edges in a tree on n vertices is n-1. Conversely, a connected graph on n vertices and n-1 edges
is a tree.
4. A tree with at least two vertices contains at least two pendant vertices (i.e., end vertices or vertices of degree 1).

5. A connected graph G is a tree if and only if every edge of G is a cut edge of G.

6. A connected graph G with at least two vertices is a tree if and only if its degree sequence{d1,d2,…,dn} satisfies the
condition: i=1 n di=2(n-1) with di >0 for each i.

7.If u and v are non adjacent vertices of a tree T, then T+ uv contains a unique cycle.

8. Every tree has a center consisting of either a single vertex or two adjacent vertices.
RV College of
Go, Change the World
Engineering
Trees
Definitions: Let G be a connected graph.
1. The diameter of G is defined as max{d(u,v) : u,v Ɛ V(G) and is denoted by diam(G).
2. If v is a vertex of G, its eccentricity e(v) is defined by e(v)= max {d(v, u) : u Ɛ V(G).
3. The radius r(G) of G is the minimum eccentricity of G: that is, r(G)= min{e(v) : v Ɛ V(G).
4. A vertex v of G is called a central vertex if e(v)= r(G). The set of central vertices of G is called the center of G.
RV College of
Go, Change the World
Engineering
Trees
1. A branch at a vertex u of a tree T is a maximal sub tree containing u as an end vertex. Hence the number of branches
at u is deg(u).
2. The weight of a vertex u of T is the maximum number of edges in any branch at u.
3. A vertex v is a centroid vertex of T if v has minimum weight.
The set of all centroid vertices is called the centroid of T .
RV College of
Engineering Counting the Number of Spanning Trees Go, Change the World

Counting the number of spanning trees in a graph occurs as a natural problem in many branches of science. Spanning
trees were used by Kirchoff to generate a“cycle basis” for the cycles in the graphs of electrical networks.

The number of spanning trees of a connected labeled graph G will be denoted by Ʈ(G). If G is disconnected, we take
Ʈ(G)=0.

There is a recursive formula for (G). Before establish this formula, let us define the concept of edge contraction in graphs.

Definition: An edge e of a graph G is said to be contracted if it is deleted from G and its ends are identified. The resulting
graph is denoted by G o e. Edge contraction is illustrated in Fig. below. If e is not a loop of G, then n(G o e)= n(G)-1,
m(G o e)= m(G)-1.

If e is not a loop of a connected graph G, Ʈ(G)= Ʈ(G-e) + Ʈ(G o e).


RV College of
Engineering Counting the Number of Spanning Trees Go, Change the World
RV College of
Engineering Counting the Number of Spanning Trees Go, Change the World

Example 1: How many spanning trees are there for K3?

Example 2: How many spanning trees are there for K4?


RV College of
Engineering Go, Change the World

How many spanning trees does the K3 have?


RV College of
Engineering Go, Change the World
RV College of
Engineering Go, Change the World
RV College of
Engineering Counting the Number of Spanning Trees Go, Change the World

Example 3: How many spanning trees are there for the graph G below?
RV College of
Engineering Counting the Number of Spanning Trees Go, Change the World
RV College of
Engineering Minimum Cost Spanning Trees Go, Change the World

Kruskal's algorithm to find the minimum cost spanning tree uses the greedy approach.
This algorithm treats the graph as a forest and every node it has as an individual tree. A tree connects to another only
and only if, it has the least cost among all available options and does not violate MST properties.

To understand Kruskal's algorithm let us consider the following example −


RV College of
Engineering Minimum Cost Spanning Trees Go, Change the World

Step 1 - Remove all loops and Parallel Edges Remove all loops and parallel edges from the given graph.

In case of parallel edges, keep the one which has the least cost associated and remove all others.
RV College of
Engineering Minimum Cost Spanning Trees Go, Change the World

Step 2 - Arrange all edges in their increasing order of weight


The next step is to create a set of edges and weight, and arrange them in an ascending order of weightage (cost).

Step 3 - Add the edge which has the least weightage


Now we start adding edges to the graph beginning from the one which has the least weight. Throughout, we shall keep
checking that the spanning properties remain intact. In case, by adding one edge, the spanning tree property does not
hold then we shall consider not to include the edge in the graph.
RV College of
Engineering Minimum Cost Spanning Trees Go, Change the World

The least cost is 2 and edges involved are B,D and D,T. We add them. Adding them does not violate spanning tree properties, so
we continue to our next edge selection.
Next cost is 3, and associated edges are A,C and C,D. We add them again −

Next cost in the table is 4, and we observe that adding it will


create a circuit in the graph. −
RV College of
Engineering Minimum Cost Spanning Trees Go, Change the World

We observe that edges with cost 5 and 6 also create circuits. We ignore them and move on.

We ignore it. In the process we shall ignore/avoid all edges that create a circuit.
RV College of
Engineering Minimum Cost Spanning Trees Go, Change the World

By adding edge S,A we have included all the nodes of the graph and we now have minimum cost spanning tree.

Now we are left with only one node to be added. Between the two least cost edges available 7 and 8, we shall add the edge with cost 7.
RV College of
Engineering Minimum Cost Spanning Trees Go, Change the World
RV College of
Engineering Minimum Cost Spanning Trees Go, Change the World

Prim's algorithm to find minimum cost spanning tree (as Kruskal's algorithm) uses the greedy approach. Prim's
algorithm shares a similarity with the shortest path first algorithms.

Prim's algorithm, in contrast with Kruskal's algorithm, treats the nodes as a single tree and keeps on adding new nodes
to the spanning tree from the given graph.
To contrast with Kruskal's algorithm and to understand Prim's algorithm better, we shall use the same example −
RV College of
Engineering Minimum Cost Spanning Trees Go, Change the World

Step 1 - Remove all loops and parallel edges

Remove all loops and parallel edges from the given graph. In case of parallel edges, keep the one which has the least
cost associated and remove all others.
RV College of
Engineering Minimum Cost Spanning Trees Go, Change the World

Step 2 - Choose any arbitrary node as root node


In this case, we choose S node as the root node of Prim's spanning tree. This node is arbitrarily chosen, so any node can be
the root node. One may wonder why any video can be a root node. So the answer is, in the spanning tree all the nodes of a
graph are included and because it is connected then there must be at least one edge, which will join it to the rest of the tree.

Step 3 - Check outgoing edges and select the one with less cost

Now, the tree S-7-A is treated as one node and we check for all edges going out from it. We select the one which has the
lowest cost and include it in the tree.
RV College of
Engineering Minimum Cost Spanning Trees Go, Change the World

After this step, S-7-A-3-C tree is formed. Now we'll again treat it as a node and will check all the edges again. However, we will
choose only the least cost edge. In this case, C-3-D is the new edge, which is less than other edges' cost 8, 6, 4, etc.
RV College of
Engineering Minimum Cost Spanning Trees Go, Change the World

After adding node D to the spanning tree, we now have two edges going out of it having the same cost, i.e. D-2-T and D-2-B.
Thus, we can add either one. But the next step will again yield edge 2 as the least cost. Hence, we are showing a spanning
tree with both edges included.

We may find that the output spanning tree of the same graph using two different algorithms is same.
RV College of
Go, Change the World
Engineering
Eulerian and Hamiltonian Graphs
Euler Trails and Circuits

• The Seven bridges of Königsberg

C
c

D
A
a d

B
b
RV College of
Go, Change the World
Engineering
Eulerian and Hamiltonian Graphs

•An Euler trail is a path using every edge of the graph G


exactly once.
•An Euler circuit is an Euler path that returns to its start.

Does this graph have an


A D
Euler circuit?
No.
B
RV College of
Go, Change the World
Engineering
Eulerian and Hamiltonian Graphs

Necessary and Sufficient Conditions


•How about multigraphs?

•A connected multigraph has a Euler circuit


iff each of its vertices has an even degree.
•A connected multigraph has a Euler path
but not an Euler circuit iff it has exactly
two vertices of odd degree.
RV College of
Go, Change the World
Engineering
Example

•Which of the following graphs has an Euler circuit?

a b a b a b

e e

d c d c c d e

yes no no
(a, e, c, d, e, b, a)
RV College of
Engineering Go, Change the World

Example

•Which of the following graphs has an Euler trail?

a b a b a b

e e

d c d c c d e

yes no yes
(a, e, c, d, e, b, a ) (a, c, d, e, b, d, a, b)
RV College of
Engineering Go, Change the World

Euler Circuit in Directed Graphs

NO (a, g, c, b, g, e, d, f, a) NO
RV College of
Engineering Go, Change the World

Euler Path in Directed Graphs

NO (a, g, c, b, g, e, d, f, a) (c, a, b, c, d, b)
RV College of
Engineering Go, Change the World

Hamilton Paths and Cycles

•A Hamilton path in a graph G is a path which visits every


vertex in G exactly once.

•A Hamilton cycle is a Hamilton path that returns to its start.


RV College of
Engineering Go, Change the World

Hamilton Circuits

Dodecahedron puzzle and it equivalent graph

Is there a cycle in this graph that passes through each vertex exactly once?
RV College of
Engineering Go, Change the World

Hamilton Circuits

Yes; this has a cycle that passes through each vertex exactly once.
RV College of
Engineering Go, Change the World

Finding Hamilton Circuits

Which of these three figures has a Hamilton cycle? Of, if no Hamilton


cycle, a Hamilton path?
RV College of
Engineering Go, Change the World

Finding Hamilton Circuits

• G1 has a Hamilton cycle: a, b, c, d, e, a


• G2 does not have a Hamilton cycle, but does have a Hamilton path: a, b,
c, d
• G3 has neither.
RV College of
Engineering Go, Change the World

Finding Hamilton Circuits

•Unlike the Euler circuit problem, finding Hamilton cycle is


hard.
•There is no simple set of necessary and sufficient
conditions, and no simple algorithm.
RV College of
Engineering Go, Change the World

Properties to look for ...

•No vertex of degree 1


•If a node has degree 2, then both edges incident to it must be
in any Hamilton cycle.
•No smaller cycles contained in any Hamilton cycle (the
start/endpoint of any smaller circuit would have to be visited
twice).
RV College of
Engineering Go, Change the World

A Sufficient Condition

Let G be a connected simple graph with n vertices with n 


3.
If the degree of each vertex is  n/2,
then G has a Hamilton cycle.
RV College of
Engineering Properties of Planar Go, Change the World

Graphs

Definition:
A graph that can be drawn in the plane without any of its edges
intersecting is called a planar graph. A graph that is so drawn in the
plane is also said to be embedded in the plane.

Applications:
circuit layout problems
RV College of
Engineering Go, Change the World

Definition:
A planar graph G that is drawn in the plane
so that no two edges intersect (that is, G is embedded in the plane) is called a plane graph.

(a) planar, (b) a plane graph (c) another


not a plane graph plane graph
RV College of
Engineering Go, Change the World

Note. A given planar graph can give rise to


several different plane graph.

Definition:
Let G be a plane graph. The connected pieces of the plane that remain when the vertices and edges of G are
removed are called the regions of G.

G1
R3: exterior
R1
R2 G1 has 3 regions.
RV College of
Engineering Go, Change the World

Definition:
Every plane graph has exactly one unbounded region, called the exterior region. The vertices and edges of G that
are incident with a region R form a sub graph of G called the boundary of R.

G2

G2 has only 1 region.


RV College of
Engineering Go, Change the World

Fig 2
Boundary of R1:
v1 v2
G3 v1 v2
R1 v3
v3 Boundary of R5:
v5 v4 R5 v1 v2

v6 R2 v7
v3
R3 v5 v4
v8 v9
R4 v6 v7

G3 has 5 regions.
v9
RV College of
Engineering Go, Change the World

Observe:
(1) Each cycle edge belongs to the boundary
of two regions.
(2) Each bridge is on the boundary of only one region.
(exterior)
RV College of
Go, Change the World
Thm 1: (Euler’s Formula)
Engineering

If G is a connected plane graph with p vertices, q edges, and r regions, then


p - q + r = 2.

pf: (by induction on q)


(basis) If q = 0, then G  K1; so p = 1, r =1,
and p - q + r = 2.

(inductive) Assume the result is true for any


graph with q = k - 1 edges, where k  1.

Let G be a graph with k edges. Suppose G has


p vertices and r regions.
RV College of
Engineering Go, Change the World

If G is a tree, then G has p vertices, p-1 edges and


1 region.
 p - q + r = p – (p-1) + 1 = 2.

If G is not a tree, then some edge e of G is on a cycle.

Hence G-e is a connected plane graph having


order p and size k-1, and r-1 regions.

 p - (k-1) + (r-1) = 2 (by assumption)

p- k+r=2
#
RV College of
Engineering Go, Change the World

Theorem : Euler’s Formula

 If G is a connected planar graph, then any plane graph


depiction of G has r = e - v + 2 regions.
• Recall: Connected planar graphs have paths between each pair of
vertices.
• v = number of vertices
• e = number of edges
• r = number of regions
 This is important because there are many different plane
graph depictions that can be drawn for a planar graph,
however, the number of regions will not change.
RV College of
Engineering Go, Change the World

Proof of Euler’s Formula


• Let’s draw a plane graph depiction of G, edge by edge.

• Let Gn denote the connected plane graph after n edges have


been added.
• Let v denote the number of vertices G
in n
n
• Let e denote the number of edges inGn
n
• Let r denote the number of regions G
in
n n
RV College of
Engineering Go, Change the World

Proof of Euler’s Formula (cont’d)

• Let’s start by drawing G1


v1 2
e1 1
r1 1

Euler’s formula is valid for G,1since


r=e-v+2
1=1-2+2

We obtainG
2 G1
by adding an edge at one of from the
verticesGof .
1
Proof of Euler’s Formula (cont’d)
RV College of
Engineering Go, Change the World

Gn from
In general, we can obtain Gn  1 by addingnan th edge to
one of theG
vertices
n 1 of .
• The new edge might link two vertices already
Ginn  1 .
• Or, the new edge might add another vertexGto
n 1 .

We will use the method of induction to complete the proof:


We have shown that the theorem is trueG for
1 .
Gn  1 for any n>1, and prove it is Gn
Next, let’s assume that it is true for
true for .

Let (x,y) be then th edge that is addedGto toGget .


n 1 n
There are two cases to consider.
RV College of
Engineering Go, Change the World

Proof of Euler’s Formula (cont’d)


Gnin 1
In the first case, x and y are both .
Then they are on the boundary of a common region K , possibly an
unbounded region.

Edge (x, y) splits K into two regions.


y
Then,
rn rn  1  1 K
en en  1  1
vn vn  1
Each side of Euler’s formula grows by one. x
So, if the formula was true Gforn  1 , it will also be trueGfor .
n
RV College of
Engineering Go, Change the World

Proof of Euler’s Formula (cont’d)


In the second case, one of the vertices x,y is G
not in
n 1 . Let’s say that it is x.

Then, adding (x,y) implies that x is also added, but that no new regions are formed
(no existing regions are split).
x rn rn  1
y
en en  1  1
K
vn vn  1  1

So, the value on each side of Euler’s equation is unchanged.


The validity of Euler’s formula for
Gn  1 implies its validity
G for .
n

By induction, Euler’s formula is true forGall


n
’s and the full graph G.
RV College of
Engineering Go, Change the World

Example of Euler’s Formula

• How many regions would there be in a plane graph


with 10 vertices each of degree 3?

By Theorem 1, Sec. 1.3:  (degrees of vertices) 2e


 (10 * 3) 30 2e
15= e
By Euler's Formula, r = e - v +2
r = 15-10+2 = 7
Answer: There are 7 regions.
RV College of
Engineering Go, Change the World

Corollary
• If G is a connected planar graph with e > 1, then e ≤ 3v – 6

• Proof:
• Define the degree of a region as the number of edges on its boundary. If an edge
occurs twice along the boundary, then count it twice. The region K has degree 12.

K
RV College of
Engineering Go, Change the World

Proof of Corollary continued


• Note that no region can be less than degree 3.
• A region of degree 2 would be bounded by two edges
joining the same pair of vertices (parallel edges)

• A region of degree 1 would be bounded by a loop edge.

• Neither of these is allowed, and so a region must have at least degree 3.


RV College of
Engineering Go, Change the World

Proof of Corollary continued

2
Since 2e =  (degrees of r), we know that 2e  3r  e r
3
Also, we know r =e - v  2 from Euler's Formula.
Substitute Euler's Formula in to get:
2
e e  v  2
3
1
=> 0 ( e  v  2) *3
3
=> 0 e - 3v  6
=> e 3v - 6
RV College of
Engineering Go, Change the World

Fig 4 Two embeddings of a planar graph

(a) (b)
RV College of
Engineering Go, Change the World

Definition:
A plane graph G is called maximal planar if, for every pair u, v of nonadjacent
vertices of G, the graph G+uv is nonplanar.

Thus, in any embedding of a maximal planar graph G


of order at least 3, the boundary of every region of G
is a triangle.
RV College of
Go, Change the World
Thm 2: If G is a maximal planar graph with p  3 vertices and q edges, then
Engineering

q = 3p - 6.

pf:
Embed the graph G in the plane, resulting in
 p - q + r = 2.
r regions.
Since the boundary of every region of G is a
triangle, every edge lies on the boundary of
two regions.
  | {the edges of the boundary of R} | 3r 2q
 region R
 p - q + 2q / 3 = 2.

 q = 3p - 6
RV College of
Go, Change the World
Cor. 2(a): If G is a maximal planar bipartite graph with p  3 vertices and q edges, then q = 2p - 4.
Engineering

The boundary of every region is a 4-cycle.


4r = 2q  p - q + q / 2 = 2  q = 2p - 4.

If G is not maximal planar, we can add edges


to G to produce a maximal planar graph.
RV College of
Engineering Go, Change the World

Fig 5 Two important nonplanar graph

K5 K3,3
RV College of
Engineering Go, Change the World

Definition:
A subdivision of a graph G is a graph obtained by inserting vertices (of degree 2) into the edges of G.
RV College of
Engineering Go, Change the World

Subdivisions of graphs.
H
G

H is a subdivision of G.

F is not a subdivision of G.
-
RV College of
Engineering Go, Change the World

Thm 5: (Kuratowski’s Theorem)


A graph is planar if and only if it contains no subgraph that is isomorphic to or is a subdivision of K5 or
K3,3.

Fig 7 The Petersen graph is nonplanar.


1 2 3
1

4 5 6

10 7
4 5 6
2 3

8 9

(a) Petersen (b) Subdivision of K3,3


RV College of
Engineering Go, Change the World
Dual of a planar graph

Example: 1
RV College of
Engineering Go, Change the World
Dual of a planar graph

Example: 2
RV College of
Go, Change the World
Engineering
Graph Coloring
Vertex Colorings

Applications of Graph Coloring


Let us begin with a practical application of graph coloring known as the storage
problem. Suppose a university’s Department of Chemistry wants to store its
chemicals. It is quite probable that some chemicals cause violent reactions when
brought together. Such chemicals are incompatible chemicals. For safe storage,
incompatible chemicals should be kept in distinct rooms.
The easiest way to accomplish this is, of course, to store one chemical in each
room. But this is certainly not the best way of doing it since we will be using
more rooms than are really needed (unless, of course, all the chemicals are
mutually incompatible!).
RV College of
Go, Change the World
Engineering
Graph Coloring

So we ask: What is the minimum number of rooms required to store all the
chemicals so that in each room only compatible chemicals are stored?
We convert the above storage problem into a problem in graphs. Form a graph
G=(V, E) by making V correspond bijectively to the set of available chemicals
and making u adjacent to v if and only if the chemicals corresponding to u and v
are incompatible. Then, any set of compatible chemicals correspond to a set of
independent vertices of G: Thus, a safe storing of chemicals corresponds to a
partition of V into independent subsets of G: The cardinality of such a minimum
partition of V is then the required number of rooms. The minimum cardinality is
called the chromatic number of the graph G.
RV College of
Go, Change the World
Engineering
Graph Coloring

Definition 1: The chromatic number of a graph G is the minimum number of


colors needed for a proper vertex coloring of G. G is k-chromatic if χ(G)= k.
Definition 2: A k-coloring of a graph G is a vertex coloring of G that uses at
most k colors.
Definition 3: A graph G is said to be k-colorable if G admits a proper vertex
coloring using at most k colors.
RV College of
Go, Change the World
Engineering
Graph Coloring
In considering the chromatic number of a graph, only the adjacency of vertices
is taken into account. Hence, multiple edges and loops may be discarded while
considering chromatic numbers, unless needed otherwise. As a consequence,
we may restrict ourselves to simple graphs when dealing with (vertex)
chromatic numbers.

It is clear that χ(Kn)= n:


Further, χ(G)= 2 if and only if G is bipartite having at least one edge.
In particular, χ(T)= 2 for any tree T with at least one edge (since any tree
is bipartite).

Further χ(Cn)=( 2 if n is even or 3 if n is odd.


RV College of
Go, Change the World
Engineering
Graph Coloring

Exercise 1: Determine the chromatic number of


i. The Petersen graph
Ii, Wheel Wn
RV College of
Go, Change the World
Engineering
Graph Coloring

Edge Colorings of Graphs

The Timetable Problem:


Suppose in a school there are r teachers, T1,T2,…………,Tr, and s classes,
C1,C2,………..,Cs. Each teacher Ti is expected to teach the class Cj for pij
periods. It is clear that during any particular period, no more than one teacher
can handle a particular class and no more than one class can be engaged by
any teacher. Our aim is to draw up a timetable for the day that requires only
the minimum number of periods. This problem is known as the “timetable
problem.”
RV College of
Go, Change the World
Engineering
Graph Coloring
To convert this problem into a graph-theoretic one, we form the bipartite graph
G= G(T, C) with bipartition (T, C), where T represents the set of teachers Ti and
C represents the set of classes Cj : Further, Ti is made adjacent to Cj in G with pij
parallel edges if and only if teacher Ti is to handle class Cj for pij periods.

Now color the edges of G so that no two adjacent edges receive the same color.
Then the edges in a particular color class, that is, the edges in that color, form a
matching in G and correspond to a schedule of work for a particular period.
Hence, the minimum number of periods required is the minimum number of
colors in an edge coloring of G in which adjacent edges receive distinct colors,
in other words, it is the edgechromatic number of G.
RV College of
Go, Change the World
Engineering
Graph Coloring

Definition 4: An edge coloring of a loopless graph G is a function ∏:E(G) S;


where S is a set of distinct colors; it is proper if no two adjacent edges receive
the same color.

Definition 5: The minimum k for which a loop less graph G has a proper k-
edge coloring is called the edge-chromatic number or chromatic index of G:
It is denoted by χ’(.G).
G is k-edge-chromatic if χ’(.G)=k.
RV College of
Go, Change the World
Engineering
Graph Coloring

Example: i) If G is bipartite graph, then χ’(G)=?

// χ’(G)=Δ(G)

ii) If G is Kn, then χ’(G)=?

// χ’ (Kn)= n-1 if n is even


// χ’(Kn)=n if n is odd.
RV College of
Go, Change the World
Engineering
Graph Coloring

Chromatic Polynomials
For a graph G and a given set of λ colors, the function f(G, λ) is defined to be
the number of ways of (vertex) coloring G properly using the λ colors. Hence,
f(G, λ)= 0 when G has no proper λ -coloring. Clearly, the minimum for which
f(G, λ) > 0 is the chromatic number χ (G) of G.

It is easy to see that f(Kn)=λ(λ-1)(λ-2)……(λ-n+1) for λ≥ n.


This is because any vertex of Kn can be colored by any one of the given λ
colors.
After coloring a vertex of Kn, a second vertex of Kn can be colored by any one
of the remaining ( λ- 1) colors, and so on. In particular, f(K3, λ)=λ(λ-1)(λ-2).
RV College of
Go, Change the World
Engineering
Graph Coloring

What is f(Cn, λ)=?


f(C4, λ)=?

How to find the chromatic polynomial for a graph G in general?


// Use decomposition theorem

Theorem : Let G be any graph. Then f(G, λ)= f(G-e, λ) – f(Goe, λ) for
any edge e of G.
RV College of
Go, Change the World
Engineering
Graph Coloring
Proof: f(G-e, λ) denotes the number of proper colorings of G-e using λ colors.
Hence, it is the sum of the number of proper colorings of G-e in which u and
v receive the same color and the number of proper colorings of G-e in which
u and v receive distinct colors. The former number is f(Goe, λ), and the latter
number is f(G, λ)

If G and H are disjoint graphs, then f(G U H, λ)= f(G, λ)f(H, λ).
RV College of
Go, Change the World
Engineering
Graph Coloring
RV College of
Go, Change the World
Engineering
Graph Coloring

You might also like