DM Unit - 3 Graphs
DM Unit - 3 Graphs
INTRODUCTION TO GRAPHS
Graphs are discrete structures consisting of vertices and edges that connect
these vertices.
1) Graph theory deals with the techniques for solving problems that can be stated
using graphs.
2) Although graph theory was once regarded as pure mathematics, the
introduction of computers has brought it into the realm of the applied. This is
because of such applications as:
Computer graphics which uses adjacency matrices.
Data organization which relies heavily on the class of graphs called trees.
Finite state machines used in compiler construction which utilize directed
graphs.
Circuit board design where it may be necessary to determine whether a
circuit can be implemented on a planar circuit board.
Computer networking (e.g. determining whether two computers are
connected by a communication link or finding the shortest path between two
computers in a network
Graphs
A graph is the same as a relation, only with different terminology. Graph
terminology (instead of relation terminology) tends to be used with applications to
real world situations.
Uses:
3) There are several different types of graphs that differ with respect to the kind
and number of edges that connect pairs of vertices.
Pseudograph - an undirected graph that may contain multiple edges and loops.
Directed graph - a set of vertices together with a set of directed edges that
connect these vertices. Multiple edges in the same direction between two
vertices are not allowed.
Directed multigraph - a graph with directed edges that may contain multiple
directed edges.
e f
a b
c
GRAPH :A graph G = (V, E) consists of a set of objects V = {v 1, v2, …} called vertices, and another
set E = {e1, e2, …} whose elements are called edges. Each edge e k in E is identified with an
unordered pair (vi, vj) of vertices. The vertices v i, vj associated with edge ek are called the end
vertices of ek. The most common representation of graph is by means of a diagram, in which
the vertices are represented as points and each edge as a line segment joining its end vertices.
Often this diagram itself is referred to as a graph.
Example 1. Consider the graph with four vertices A, B, C and D and four edges e1,
e2, e3 and e4 where
i. e1 joins A and B e1
e2
A e4 Be
ii. e2 joins A and D 3
Thus V = {A, B, C, D} and E = {e1, e2, e3, e4}. We often represent an edge by the
set of the two vertices that it joins, so e1 = {A, B}, e2 = {A, D}, e3 = {B, C} and e4 =
{B, D} and E = {{A, B}, {A, D}, {B, C}, {B, D}}. A "picture" of this graph is
shown at the right.
Example 2. Consider the graph with four vertices A, B, C and D and four edges e1,
e2, e3 and e4 where
i. e1 goes from A to B e1
e2
A e4 Be
3
ii. e2 goes from D to A
D C
iii. e3 goes from C to B
Here V = {A, B, C, D} and E = {e1, e2, e3, e4}. For a directed graph we often
represent an edge from a vertex v to a vertex w by the ordered pair (v, w), so e1 =
(A, B), e2 = (D, A), e3 = (C, B) and e4 = (B, D) and E = {(A, B), (D, A)}, (C, B), (B,
D)}. A picture is shown at the right.
Definition 3. A weighted graph (either undirected or directed) is a graph where
each edge has a weight associated with it.
A graph obtained by deleting all the loops and parallel edges from a given
graph is called an under lying graph.
Mixed graph :
If some edges are directed and some edges are not directed is called as
mixed graph.
If e is associated with {u,v} then the edge e is said to be incident with the
vertices u and [Link] edge e is also said to connect u and v.
Degree of a vertex:
Undirected graph:
Figure: 1
Degree (v1) = 3 , Degree (v2) = 4, Degree (v3) = 3, Degree (v4) = 3,
Degree (v5) = 1
Figure: 2
Note:
Directed graph:
In a directed graph terminology reflects the fact that each edge has a
direction. In a directed graph vertex v is adjacent to u, if there is an edge leaving v
and coming to u.
Out-degree: The out-degree of a vertex is the number of edges leaving the vertex.
(deg+ = out-degree)
Example: Find the indgree and out degree of each vertex of the given directed
graph.
Total = 12 Total = 12
In degree = out degree
Since, each edge has an initial vertex and terminal vertex the sum of the indegree
and the outdegree of all vertices are the same and it is equal to number o edges.
Proof: Each edge contributes two to the sum of the degree’s of the vertices
since an edge is incident with exactly two vertices. Therefore the sum of the degree
of the vertices is twice the number of edges.
Example: How many edges are there in a graph with 10 vertices each of
degree 6.
Proof: Let V1 , V2 be set of vertices of even degree and the set of vertices of
odd degree respectively in an undirected graph G =(V,E) then
---------(1)
But the sum of two terms in (1) is 2e . Therefore the second term on the
R.H.S of (1) should also be even. Since all the terms in this sum are odd, there
must be an even number of such terms. Thus there an even number of vertices of
odd degree.
edges.
edges.
edges.
5+4+3+2+1 = 2e
Let us denote the even as 2n. Let the number f edges be ne. By
Handshaking theorem
K+ k+ k+ k+…..+K = => 2nk = =>
Finite graph:
A graph is finite iff both the vertex set and edge set are finite otherwise the
graph is infinite.
K1 K2 K3 K4 K5
Cycles: The cycle Cn, n 3 consists of n vertices v1, v2, …, vn and edges {v1, v2}, {v2,
v3}, …, {vn-1, vn}.
C3 C4 C5
cycle Cn
W3 W4 W5
n-cube
The n cubes 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.
Regular graph :
A graph in which every vertex has the same degree is called a regular graph.
Here is an example of two regular graphs with four vertices that are of degree 3
and 2 respectively.
Petersen graph :
The following graph of degree 3 with 10 vertices is called the Petersen graph
Bipartite graph:
Example :
V = { a, b, c, d } Here V1 = { a, d } and V2 = { b, c }
Problem 1: How many vertices does a regular graph with degree 4 and
edges 10 have.?
Problem 2: Are the graph G1 and G2 has shown below are biparted.
The complete Bipartite graph Km,n is the graph that has its vertex
set partitioned into two subsets of m & n vertices respectively. There is
an edge between two vertices iff one vertex is in first subset and the
other vertex is in the second subset.
Some notations
Kn : the complete graph on n vertices or n-clique.
Cn : the chordless cycle on n vertices or n-cycle.
Pn : the chordless path graph on n vertices or n-path.
Km,n : the complete bipartite graph on m+n vertices
partitioned into an m-stable set and an n-stable set.
K1,n : the star graph on n+1 vertices.
mKn : m disjoint copies of Kn.
Example:
Graph colouring :
Theorem:
Adjacency List:
a b
b c,d,a
c b , e, d
d b, c, e
e c, d
For digraph
Vertex adjacent vertices
a b
b _
c a,d
d b, e
e _
AG =(aij)mxn =
Note :
2. Sum of all the entries in any row is equal to the degree of the
vertex corresponding to that row.
3. All the entries along the leading diagonal are zero iff the graph
has no self loop.
AG =(aij)mxn =
Example :
Note : Sum of the row = number of outdegree of the vertex.
Pseudo graph
Incidence matrix:
Example:
Incidence Matrix
Let G be a graph with n vertices, e edges, and no self-loops. Define an n by e matrix A =[a ij],
whose n rows correspond to the n vertices and the e columns correspond to the e edges, as
follows:
= 0, otherwise.
a b c d e f g h
v1 0 0 0 1 0 1 0 0
v2 0 0 0 0 1 1 1 1
v3 0 0 0 0 0 0 0 1
v4 1 1 1 0 1 0 0 0
v5 0 0 1 1 0 0 1 0
v6 1 1 0 0 0 0 0 0
G1 G2
u2
v2
u1 u3 v1 v3
u5 u4
v5 v4
u1 u2 u3 u5 u6 u8
u4 u7
y1 y2 y4 y5 y6 y8
y3 y7
Problem: Determine whether the graphs G & H shown below are isomorphic.
, , , , ,
Connectivity
Path:
A path is a sequence of distinctive vertices connected by edges. Vertex v is
reachable from u if there is a path from u to v.
Connected graph :
Connected graph - An undirected graph with the property that there is a path
between every pair of vertices in the graph.
Circuit (cycle) - a path that begins and ends at the same vertex.
Simple circuit - A circuit that does not contain the same edge more than once.
Paths and cycles (circuits can help us to determine if two graphs are
isomorphic).
Note that the use of paths and cycles are typically used to show that two
graphs are not isomorphic.
Cut vertices (or articulation points) are those vertices whose removal and the
removal of all edges incident with it produces a subgraph with more connected
components than the original graph.
A directed graph is strongly connected if there is a path from 'a' to b and from
b to 'a' whenever 'a' and b are vertices in the graph.
Representing Graphs
As an example, the graph depicted in Figure 1 has vertex set V={a,b,c,d,e.f} and
edge set E = {(a,b),(b,c),(c,d),(c,e),(d,e),(e,f)}.
e f
a b
c
Every graph has associated with it an adjacency matrix, which is a binary nn
matrix A in which aij = 1 and aji = 1 if vertex vi is adjacent to vertex vj, and aij = 0
and aji = 0 otherwise. The natural graphical representation of an adjacency matrix
a b c d e f
a 0 1 0 0 0 0
b 1 0 1 0 0 0
c 0 1 0 1 1 0
d 0 0 1 0 1 0
e 0 0 1 1 0 1
f 0 0 0 0 1 0
G W
Paths and Circuits
Prove that a simple graph with n vertices may have atmost edges.
Solution : Let G = {v,e} be a simple graph with n vertices and k components.
Then +
……..(i)
+
……….(ii)
Squaring (ii) =
-k …..(iii)
We know that a simple graph with n vertices will have maximum edges.
An Euler cycle is a cycle which uses every edge of the graph exactly once.
Euler's Theorem for Euler Cycles:
a) If the graph G doesn't have any isolated vertices, then it has an Euler cycle
if and only if the following two conditions are both satisfied:
i) G is connected.
ii) The degree of each vertex of G is even.
Graph models
Niche overlap graph (in ecology) - each species is represented by a vertex.
An undirected edge connects two vertices if the two species represented by
the vertices compete (i.e. if their food sources are the same).
Example : Construct a niche overlap graphs for 6 species of birds where the
hermit thrush competes with the robin and blue jay, the robin competes with the
mocking bird, the mockingbird competes with the blue jay, and the nuthatch
competes with the woodpecker.
r bj
Influence graphs - each person in the group is represented by a vertex. There is a
directed edge from vertex 'a' to vertex b when person 'a' influences person b.
Example:
Construct an influence graph for the board members of a company if the
president can influence the director of R & D, the director of marketing,
and the director of operations. The director of R & D can influence the
director of operations. The director of marketing can influence the
director of operations. No one can influence or be influenced by the
chief financial officer.
Round-robin tournaments are tournaments where each team plays
each other team exactly once. Each team is represented by a vertex.
Example:
In a round-robin tournament, the Tigers beat the Blue Jays, the
Cardinals, and the Orioles. The Blue Jays beat the Cardinals and
Orioles. The Cardinals beat the Orioles.
Proof.
On the other hand, suppose that each vertex of G has even degree and we need
to construct an Eulerian trail.
Now, we obtain the required Eulerian trail (of G) by following the edges of C, if a
non-isolated vertex of H is reached, tracing the Eulerian trail (of that Eulerian
component of H), and then continuing along the edges of C, and so on. This
process stops when we return to the starting vertex.
Corollaries.
(1) A connected graph is Eulerian if and only if its set of edges is union of disjoint
cycles.
(2) A connected graph is semi-Eulerian if and only if it has exactly two vertices of
odd degree. (The “only if” part is obvious. For the “if” part, simply join that
two “odd vertices” by an edge, resulting in a Eulerian graph by Theorem 1.)
Hamiltonian graphs
A connected graph G is said to be Hamiltonian if there exists a cycle passing
through each vertex of G. This cycle is called Hamiltonian cycle of G. A non-
Hamiltonian graph is said to be semi-Hamiltonian if there exists a path passing
through each vertex of . This path is called Hamiltonian path of .
A Hamilton path is a path that includes each vertex of the graph exactly once.
Hamiltonian path problem : a path that passes through each of the vertices in a
graph exactly once.
No simple necessary and sufficient condition is known.
Theorem 5.4. Let G be a linear graph of n vertices. If the sum of the degrees for
each pair of vertices in G is n - 1 or larger, then there exists a hamiltonian path in
G.
Proof. (1) G is connected:
Suppose G has two or more disconnected components. Let v1 be a vertex
in one component that has n1 vertices and v2 be a vertex in another
component that has n2 vertices.
Since the degree of v1 is at most n1 - 1 and the degree of v2 is at most n2 -
1, the sum of their degrees is at most n1 + n2 - 2 < n - 1, contradicts to the
assumption.
(2) Construct a hamiltonian path:
Let there be a length p-1 (p < n) path, (v1, v2, v3, …, vp). Both v1 and vp are
adjacent only to the vertices that are in the path.
There is a cycle containing exactly the vertices v1, v2, v3, …, vp.
Assume v1 is adjacent to , where 1 < ij < p.
If vp is adjacent to one of then we have the cycle.
If vp is not adjacent to any one of then vp is
adjacent to at most p-k-1 vertices. Contradicts to the assumption.
Pick a vertex vx that is not in the cycle. Because G is connected, there is a
vertex vk that is not in the cycle with an edge between vx and vk for some
vk in {v1, v2, v3, …, vp}.
We now have the path (vx, vk, vk+1, …, vj-1, vp, vp-1, …,vj, v1, v2, v3, …, vk-
1), which contains p edges.
3. If the vertices of a trail are distinct (except the initial vertex and final vertex
possibly coincide), then the trail is called a path.
4. We say a walk/trail/path is closed if the initial vertex is also the finial vertex.
As a corollary, any simple graph with n vertices and more than edges
must be connected.
Now, we obtain the required Eulerian trail (of G) by following the edges of C, if a
non-isolated vertex of H is reached, tracing the Eulerian trail (of that Eulerian
component of H), and then continuing along the edges of C, and so on. This
process stops when we return to the starting vertex.
Lemma.
Proof of Theorem 2.
Suppose at some stage we have just reached a vertex and the resulting graph
is still connected. We will show that the next step can be carried out and produce
also a connected graph.
Case 1:
Case 2:
All edges incident with v are bridge. In case there is only 1 bridge incident with v
(by the lemma), traverse through this bridge, erase this bridge and the vertex v
(because v is now isolated). The resulting graph is still connected.
Since the graph is finite, we must finally return to u (and the remaining graph, if
exists, is still a connected graph). If there is nothing remains, that means an
Eulerian trail is found. Otherwise, the remaining graph is still Eulerian and the
algorithm can go on until we have traversed all the edges.
Hamiltonian graphs
A connected graph G is said to be Hamiltonian if there exists a cycle passing
through each vertex of G. This cycle is called Hamiltonian cycle of G. A non-
Hamiltonian graph is said to be semi-Hamiltonian if there exists a path passing
through each vertex of . This path is called Hamiltonian path of .
Theorem 3. Ore
Proof.
Consider the longest path in the graph (note that this path must
pass through every vertex). Clearly, is not adjacent.
Case 1:
Case 2:
vj vn
v1 v2 v j+1 v n-1
and B. Therefore, is adjacent to and is adjacent to , as shown in the
following figure.
Theorem :If G is a simple graph with vertices such that for each
vertex v, then G is Hamiltonian.
The origins of graph theory can be traced to the 18th century and the bridges of
Königsberg problem.
a. The city of Königsberg in East Prussia (later to become
Kaliningrad in the Soviet Union) is situated on the Pregel
River.
b. In the river are two islands that are connected to each other
and to the mainland by seven bridges.
A B
Pregel River
. C
A. B
Although in the definition of a graph neither the vertex set V nor the edge set E need be
finite, in most of the theory and almost all applications these sets are finite. A graph with a
finite number of vertices as well as a finite number of edges is called a finite graph; otherwise, it
is an infinite graph.
When a vertex vi is an end vertex of some edge ej, vi and ej are said to be incident with
(on or to) each other.
Two nonparallel edges are said to be adjacent if they are incident on a common vertex.
Similarly, two vertices are said to be adjacent if they are the end vertices of the same edge.
The number of edges incident on a vertex v i, with self-loops counted twice is called the
degree, d(vi), of vertex vi.
Since each edge contributes two degrees, the sum of the degrees of all vertices in G is
twice the number of edges in G.
A vertex having no incident edge is called an isolated vertex. In other words, isolated
vertices are vertices with zero degree. Vertex v 4 and v7 in Fig. 3-2, for example, are isolated
vertices. A vertex of degree one is called a pendent vertex or an end vertex. Vertex v3 in Fig. 3-2
is a pendant vertex. Two adjacent edges are said to be in series if their common vertex is of
degree two.
In the definition of a graph G = (V, E), it is possible for the edge set E to be empty. Such
a graph, without any edges, is called a null graph. In other words, every vertex in a null graph is
an isolated vertex. Although the edge set E may be empty, the vertex set V must not be empty;
otherwise, there is no graph. In other words, by definition, a graph must have at least one
vertex.
PART A
1. Define Graph.
A graph G = (V,E) consists of a finite non empty set V, the element of which are the vertices
of G, and a finite set E of unordered pairs of distinct elements of V called the edges of G.
6. Define Subgraph.
A graph H = (V1,E1) is a subgraph of G = (V,E) provided that V1 ,E1 and for each e ε E1 ,
both ends of e are in V1
7. Define Isomorphism
Two graphs G1 = (V1,E1) and G2 = (V2,E2) are the same or isomorphic, if there is a
bijection F from V1 to V2 such that (u,v) ε E1 if and only if ( F(u), F(v)) ε E2.
8. Define strongly connected graph
A digraph G is said to be strongly connected if for evry pair of vertices both vertices of
the pair are reachable from one another.
9. State the necessary and sufficient conditions for the existence of an Eulerian path in a connected
graph
A connected graph contains an Euler path if and only if it has exactly two vertices of odd
degree.
10. State Handshaking theorem.
Let G be a graph with at least two vertices . at least two vertices of G have the same
degree.
11. Define Connected graph.
A graph for which each pair of vertices is joined by a trail is connected.
12. Define Tree
A tree is a connected acyclic graph.
13. What is minimum cost spanning tree.
A spanning tree of minimum weight is called a minimum cost spanning tree.
14. Define forest.
A graph in which each connected component of a tree is called a forest.
15. Define spanning subgraph.
A graph H = (V1,E1) is a subgraph of G = (V,E). H is a spanning subgraph of G if H is a
subgraph of G and V1= V.
16. Define Induced subgraph.
A graph H = (V1,E1) is a subgraph of G = (V,E). H is an induced subgraph of G such that
E1 consists of all the edges of G with both ends in V1.
17. Define binary tree.
A binary tree is either a tree with no vertices or a rooted tree for which each vertex has at
most two children.
18. Define Eulerian Circuit.
A circuit in a graph that includes eacg edge exactly once, the circuit is called an Eulerian
circuit.
19. State Konigsberg bridge theorem.
Let G be a connected graph. G has an Eulerian circuit if and only if each vertex is even.