Professional Documents
Culture Documents
kashiram pokharel
Introduction
• Graph is a discrete structure.
• A graph G is a collection of two sets V and E.
where V is the collection of vertices V1, V2, V3,….Vn and E is the
collection of edges E1, E2, E3…..EN where edge is the line
connecting two vertices.
Hence a graph G can be represented as
• G=(V,E)
Where,
V=( V1,V2,V3,….Vn) or set of vertices
E=( e1,e2,e3…..en) or set of edges
kashiram pokharel
Uses of graph
• To design airline route map:
• Vertices are cities
• A line connects two cities if and only if there is a non‐stop flight between them in
between direction.
• To design electrical circuit:
• Vertices could be diodes, transistor, capacitor and so on
• Two vertices are connected by a line if there is a wire connecting them.
• To design a flowchart.
• In computer networks
• Computers, routers are vertices
• The connecting cables behave like edges.
• Solving puzzles and games
• In network broadcast(eg. In router for routing data)
• Find shortest path between cities in transportation.
kashiram pokharel
Type of graph:
• In terms of connection
• Connected graph
• Not connected graph
• Interms of direction
• Directed graph
• Undirected graph
• Simple graph
• Multi graph
• Pseudo graph
• Interms of strength of connection
• Strongly connected
• Weakly connected
• In terms of weight
• Weighted graph
• Unweighted graph kashiram pokharel
Connected graph:
kashiram pokharel
Not connected graph:
• A graph in which at least one node is not connected or all nodes may
not be connected is called not‐connected graph.
kashiram pokharel
Undirected graph:
• A graph which has unordered pair of vertices is called undirected graph.
suppose there is an edge between vertex A and B then it can be represented
as (A,B)or (B,A). The edges of a graph are assumed to be unordered pairs of
nodes. Sometimes we say undirected graph to emphasize this point. In an
undirected graph, we write edges using curly braces to denote unordered
pairs. For example, an undirected edge { A,B } from vertex A to vertex B is
the same thing as an undirected edge { B,A } from vertex B to vertex A.
kashiram pokharel
Simple graph:
• A simple graph, also called a strict graph is an un‐weighted,
undirected graph containing no graph loops or multiple edges
A simple graph may be either connected or disconnected.
• SIMPLE graph G is one satisfying that;
• having at most one edge (line) between any two vertices (points) and,
• Not having an edge coming back to the original vertex.
kashiram pokharel
Multi graph
kashiram pokharel
Pseudo graph:
• A pseudo graph is a non‐simple graph in which both graph loops and
multiple edges are permitted
kashiram pokharel
Directed graph:
• A directed graph or digraph is a graph which has directed pair of
vertices. suppose there is an directed edge between vertex A and B
then it can be represented as (A,B).Here A is the tail and B is the head
of the edge.
kashiram pokharel
Weighted graph:
kashiram pokharel
Unweighted graph:
• A unweighted graph is a graph in which edge doesn’t contain any
weight of it’s own .it just represent the connectivity between the
vertex
kashiram pokharel
Complete graph:
• A simple graph is said to be complete if every vertex in G is connected with
every other vertex .In other words, we can say a complete graph contains
exactly one edge between each pair of distinct vertices.a complete graph is
denoted by Kn . Kn has exactly edges
kashiram pokharel
Bipartite graph:
• A graph G is said to be bi partite graph if it’s vertices are divided into
two subset M and N .such that vertices of M subset are connected to
the vertices of N subset, but the vertices of same parts are never
connected.
• If the vertices of first part are connected to all the vertices of another
subset (second part) then Bipartite graph is called complete bi‐partite
graph and is denoted by Km,n where m is the number of vertices in M
subset and n is the number of vertices in N subset.
• For standardization, we will assume m<=n
kashiram pokharel
• The graph Km,n has m*n edge
• How many edge have each of the following
graph.?
• K3,3
• Since , K3,3 is complete bipartite graph
therefore, the number of edge =3*3=35
fig. K3,3 bipartite graph
kashiram pokharel
Properties of bi‐partite graph:
• Every tree (or graph) is a bi‐partite graph.
• A graph G is bipartite if and only if it contains odd cycle i.e all closed walks in
graph G are of even length
• A connected bipartite graph has a unique bipartition.
• A bipartite graph with no isolated node and p connected component has 2p‐1
bi partitions
• A connected graph is bipartite if and only if for every node V there is no
edge(x,y) such that
• dist(v,x)=dist(v,y)
kashiram pokharel
Show that the maximum number of edge in complete
bi‐partite graph of n vertices is n2/4
• Let G has a complete bi‐partite graph with n‐vertices .
• Let n1 and n2 are the number of vertices in the partition v1 and v2
respectively.
• Thus G has n1.n2 edge where n1+n2=n.
• But we know that maximum value of n1 and n2 subject to n1+n2=n is n2/4.
• Thus maximum number of edge in G is n2/4.
kashiram pokharel
Planner graph
• A graph is said to be planner graph if it can be drawn in the plane without
crossing or intersection of it’s edge .A non planner graph is one which
cannot be drawn in the plane without edge intersection
• A graph may be planner ever if it is usually drawn with crossing, because it
may be possible to
draw it in a different
way without crossing.
kashiram pokharel
Euler theorem for planner graph
• Let V be the number of vertices and E be the number of edges and f
be the number of faces .Then Euler formula is defined as:
V‐E+F=2
Proof ???
We use mathematical induction for the number of edge to proof the
theorem
kashiram pokharel
• Basis step:
when E=0
then
V=1
E=0
F=1 Then Euler formula becomes
V‐E+F=2
1‐0+1=2
2=2 Which is true
kashiram pokharel
Case 1
When E=1 Then
V=2
E=1
F=1
Then Euler formula becomes
V‐E+F=2
2‐1+1=2
2=2 Which is also true
kashiram pokharel
Case 2
when E=1 Then,
V=1
F=2,
then Euler formula becomes
V‐E+F=2
1‐2+2=2
2=2 which is also true
kashiram pokharel
• Inductive Hypothesis
Let us assume that the formula is also true for E number of edges
i.e.
V‐E+F=2 is also true
kashiram pokharel
• Inductive step
Now, we have to show that it is true for (E+1) edges .Assuming that the
following graph that satisfies the Euler formula.
When we add an edge to this graph following two cases arises
kashiram pokharel
• When adding an edge the number of vertices remain constant while face
increases. let V’ be the vertices and E’ be the edges and F’ be the face of the
graph formed after adding edge.
Now
V’=V
E’=E+1
F’=F+1
Then Euler formula becomes
V’‐E’+F’=2
V‐(E+1)+F+1=2
V‐E+F=2
Which is also true
kashiram pokharel
• Case 2:
When adding an edge, the face remain constant while no vertices increases.
Here,
V’=V+1
E’=E+1
F’=F
Then Euler formula becomes
V’‐E’+F’=2
V+1‐(E+1)+F=2
V‐E+F=2
Which is also true
Hence proved.
kashiram pokharel
Corollary 1:
kashiram pokharel
Corollary 3:
• If a connected planar simple graph has e edges and v vertices with v
3 and no circuits of length 3, then e 2v ‐ 4.
• Is K3,3 planar?
K3,3 has 6 vertices and 9 edges.
Obviously, v 3 and there are no circuits of length 3.
If K3,3 were planar, then e 2v – 4 would have to be true.
e 2v – 4
9 = 2*6 – 4
9 8 .which is false because e must be 8.
But e = 9.
So K3,3 is nonplanar
kashiram pokharel
Planarity testing algorithm:
• Given a graph G=(V,E) is a planner,If G can be drawn in the plane
without edge crossing.
• Kuratowski’s algorithm:
A graph G is embeddable in the plane if and only if it doesn’t contain a
subgraph homeomorphic to the complete graph K5 or complete bi partite graph
K3,3
• Wangner’s theorem:
G is planner iff G contains no subgraph which has K3,3 or K5 as minor.
(a minor is defined as a graph which doesn’t have K3,3 or as a subgraph.
However it has a subdivision of K3,3 and K5 as a minor)
kashiram pokharel
Regular graph:
• A graph G is called regular graph if it’s all vertices are of the same
degree or valency. i.e. a regular graph is a graph where each vertex
has the same number of neighbors.A regular directed graph must
also satisfy the stronger condition that the indegree and outdegree of
each vertex are equal to each other.
• If the degree of each vertex is k then graph is called k‐regular graph or
regular graph of degree k.
• All complete graph are regular graph but all regular graph are not
complete graph.
kashiram pokharel
Some terms about the regular graph:
• All the vertices have the same degree k.
• Every null graph is a regular graph of degree zero.
• A regular graph of degree 1 has one line
• If G is a two –regular graph. Then graph has a cycle.
• If G is a graph of degree 3 ,it is called a cubic graph.
kashiram pokharel
Size of k‐regular graph:
• Accouding to the definition of regular graph for all viЄv(G) then degree of vertex vi
i.e. deg(vi)=k
deg vi
=n*k
But we know that Degree of vertex=sum of in‐degree and out degree
∑ Є deg vi =∑ Є deg vi e
i.e . sum of in‐degree is equal to the sum of out‐degree and is equal to the sum of edge
of a graph.
deg vi 2e
K*n=2e
K . n= 2e
∗
e= kashiram pokharel
Walk path and circuit:
• Walk:
a walk of graph G is an finite alternating sequence of vertices and edges, beginning
and ending with vertices such that each edge is incident with the vertices
preceding and following it.
The form of walk is:
Walk (w)=viej, vi+1ej+1,………ekvk.
A walk that begins and ends at the same vertex is called closed walk. Let, u be the
initial vertex of a graph and v be the terminal vertex, if u=v then walk(w) is closed,
and if u≠v, then it is open.
kashiram pokharel
• If no edge appears more than once in a sequence of walk, then such a
sequence is called trail in G.
• Here, Vertices and edges can be repeated in walk .but in trail all edges are
distinct. so a trail is a walk if no edge is repeated.
• An open walk in which no vertex appears more than once is called simple
path or elementary path.
• Vertex can appear more than once in a walk but not in a path.;
• A circuit in a graph G is a closed trail of length 3 or more, Hence a circuit
begins and ends at the same vertex but repeats no edge.
• In a circuit vertices can be repeated in addition to the first and last.
• A circuit that repeats no vertex except for the first and last edge is called
cycle.
kashiram pokharel
Euler Paths and Circuits
• The Seven bridges of Königsberg
C
c
D
A
a d
B
b
kashiram pokharel
Euler path and circuit:
• An Euler path is a path that uses every edge of a graph exactly once. An
Euler path start and end at different vertices.
• An Euler circuit is a closed path that is formed by visiting all the edge of
the graph only once and ends in the vertex
from which we started. A graph that contains
Euler cycle is called Euler graph.
• Euler circuit:
ae1be2ce3ee4de5ce6
kashiram pokharel
Properties:
• A connected undirected graph is Eulerian if every vertex has an even
degree.
• An undirected graph is Eulerian if it is connected and can be decomposed
into edge disjoint cycle.
• A directed graph is Eulerian if it is connected and every vertex has equal
in degree and out degree.
• A directed graph is Eulerian if it is connected and can be decomposed
into edge disjoint directed cycle.
kashiram pokharel
Necessary and sufficient condition :
• Theorem:
Let G=(V,E) be a connected graph then G is an Euler graph if and only if
all vertices of G are of even degree.
This theorem consists of two parts
• Necessary condition:
If G consists of Euler cycle then every vertex of G has even degree.
• Sufficient condition:
If every vertex of G has even degree then G consists of Euler cycle.
kashiram pokharel
If G consists of Euler cycle then every vertex of G
has even degree.
• Proof:
• A graph that contains Euler cycle is Euler graph. Suppose that a graph
has an Euler path P. For every vertex v other than the starting and
ending vertices, the path P enters v the same number of times that it
leaves v (say 2s times). Therefore, there are 2s edges having v as an
endpoint.
• Therefore, all vertices other than the two endpoints of P must be
even vertices.
kashiram pokharel
Let G be an undirected graph which is connected
.then we can construct an Euler trail in G if and
only if G has exactly two vertices of odd degree.
• Proof:
??
kashiram pokharel
Eulerian‐Type Problems
• Edge‐traceable graphs.
• Diagrams‐Tracing Puzzles.
• Dominoes.
• Mazes and labyrinths,
• The Chinese Postman Problem.
• The Rotating Drum Problem.
kashiram pokharel
Hamilton graph:
• A graph that contains Hamilton cycle is called Hamilton graph .A
Hamilton cycle is formed by visiting all the vertices of the given graph
exactly once and ends in the vertex from where we have started is
called Hamilton cycle
• Hamilton cycle:
a e7 d e4 e e3 c e2 b e1 a
kashiram pokharel
• A Hamilton path in a graph is a path that includes each vertex
of the graph once and only once.
• A Hamilton circuit is a circuit that includes each vertex of
the graph once and only once. (At the end, of course, the
circuit must return to the starting vertex.)
kashiram pokharel
• Note that if a graph has a Hamilton circuit, then it automatically has a
Hamilton path–(the Hamilton circuit can always be truncated into a
Hamilton path by dropping the last vertex of the circuit.)
• For example, the Hamilton circuit A, F, B, C, G, D, E, A.
• can be truncated into the Hamilton path
A, F, B, C, G, D, E.
kashiram pokharel
kashiram pokharel
Hamilton path:
• A Hamilton path on a graph is a path going through every vertex of
the graph once and only once.
• A Hamilton graph must be 2‐connected, i.e. We have to delete at least
two vertices to split the graph in two disconnected parts.
kashiram pokharel
Necessary condition for a graph to be
Hamiltonian NOT NECESSARY
• In addition to 2‐connectiveness of the graph, mention the Grinberg
theorem and the dissection theorem for necessary condition.
• Grinberg theorem
• Let G be a plane graph of order n with Hamilton cycle c.Then
with respect to this cycle c
∑ (k ‐ 2)(Fk ‐ Gk) = 0
Dissection theorem:
kashiram pokharel
Sufficient condition for a Hamilton graph:
• Ore’s theorem
Let G be a simple graph with n‐vertices where n≥2, if
deg(v)+deg(w)≥n for each pair of non‐adjacent vertices v and w
,then G is Hamiltonian.
• Dirac’s theorem.
Let G be a simple graph with n vertices where n≥3 .If deg(v)≥ for
each vertex v.then G is Hamiltonian.
kashiram pokharel
Dirac’s theorem.
• Let G be a simple graph with n vertices where n≥3 .If deg(v)≥ for
each vertex v.then G is Hamiltonian.
kashiram pokharel
Ore’s theorem
• Let G be a simple graph with n‐vertices where n≥2, if
deg(v)+deg(w)≥n for each pair of non‐adjacent vertices v and w ,then
G is Hamiltonian
kashiram pokharel
Isomorphic graph:
• Two graph G1= (V1, E1) and G2= (V2, E2) are isomorphic if there is a one
to one and onto function F from v1 to v2 ,with the property that a and
b are adjacent in G1 if and only if f(a) and f(b) are adjacent in G2 for
all a and b in V1. such a function is called isomorphism.
kashiram pokharel
The isomorphic graph has following properties
The isomorphic graph has following properties
• F is one to one
• F is onto
• For all a,bЄV1 ,{a,b}ЄE1 if and only if{f(a),f(b)}ЄE2
When such function exists then G1and G2 are called isomorphic
graph and written as
G1≡G2
kashiram pokharel
Condition for graph isomorphism:
• Both graph G1 and G2 must have same number of vertices.
• Both must have same number of edges
• Degree sequence of both graph are same
• For all a,bЄV1,{a,b}ЄE1 if and only if {f(a),f(b)}ЄE’ when such function
exists G1 and G2 are isomorphic graph.
kashiram pokharel
Check the following graph are isomorphic or not
kashiram pokharel
• degree of graph G and G’are as follows
deg(G) deg(G’)
deg(a)=3 deg(1)=1
deg(b)=2 deg(2)=3
deg(c)=3 deg(3)=3
deg(d)=3 deg(4)=2
deg(e) =1 deg(5)=3
• They have the same number of vertices with the same degrees:
1,3,3,3,2
• Both have same number of edges i.e. 6 edges.
kashiram pokharel
• Let f:GG’ be any function defined between two graph G and G’ i.e
there exists a function for mapping the vertices as follows
F(a)= node 3
F(b)=node 4
F(c)=node 5
F(d)=node 2
F(e)=node 1
Hence, we can say that these graph are isomorphic
kashiram pokharel
Shortest path algorithm:
• This algorithm is used to solve the single source shortest path problem on a
weighted directed graph
• All the edge weights must be non‐negative.
• compute the length of shortest path from a source to all other remaining
vertices.
• each node is labeled with dist predecessor and status.
• dist of node represents the shortest dist of that node from the source
node and
• predecessor of a node represents the node which precedes the given node
in shortest path from source.
• Status of a node can be permanently visited or not.
kashiram pokharel
Procedure:
• Initially make source node as the current working node. All other
node are made unvisited node.
• Label a source node with 0 and all others with
• Examine all the temporary neighbors of the current working nodes
and after checking the condition for minimum weight re‐label the
required node.
• From all the temporary nodes find out the node which has minimum
value of dist , make the node permanent and now this is the current
working node.
• Repeat step 2 and 3 until destination node is made permanent.
kashiram pokharel
• set it to zero for our initial node and to infinity for all other nodes.
• Set the initial node as current. Mark all other nodes unvisited. Create a set of all the
unvisited nodes called the unvisited set.
• For the current node, consider all of its unvisited neighbors and calculate
their tentative dist from current node and If that node was previously marked with a
dist greater than current dist then relabel it with current value. Otherwise, keep the
previous value.
To update labels:
Lk(a, v) = min{Lk‐1(a, v), Lk‐1(a, u) + w(u, v)}
• When we are done considering all of the neighbors of the current node, mark the
current node as visited and remove it from the unvisited set. A visited node will never
be checked again.
• When unvisited set is empty then algorithm is stop and The algorithm has finished.
• Otherwise, select the unvisited node that is marked with the smallest tentative dist, set
it as the new "current node", and go back to step 3.
kashiram pokharel
Find the shortest path using dijkstra algorithm:
• Let source node =A
• Destination node=F
kashiram pokharel
• Label 0 for starting vertex and other ∞
kashiram pokharel
• Check adjacent node of A and mark node A as visited node
L(A,B)=min{dist(B) ,{dist(A)+dist(A,B)}} min(∞ ,0+2) relabel B by 2
L(A,C) =min{dist(C),{ dist(A)+dist(A,C)} min(∞ ,0+6) relabel C by 6
kashiram pokharel
• Here B is in shortest dist then, Check adjacent node of B and mark node B
as visited node
• L(A,D)=min{dist(D) ,{dist(B)+dist(B,D)}} min(∞ ,2+7) relabel D by 9
L(A,C) =min{dist(C),{ dist(B)+dist(B,C)} min(6 ,2+3) relabel C by 5
kashiram pokharel
• Now check adjacent node of c, and mark node C as visited node
• L(A,E)=min{dist(E), (dist(C)+dist(C,E))} min(∞ ,5+9) relabel E by 14
• L(A,D)=min{dist(D), (dist(C)+dist(C,D))}min(9 ,5+2) relabel D by 7
kashiram pokharel
• Check adjacent node of D, and mark node D as visited node
• L(A,E)=min{dist(E), (dist(D)+dist(D,E))} min(14,7+6 ) relabel E by 13
• L(A,F)=min{dist(D), (dist(D)+dist(D,F))}min(∞ ,7+10 ) relabel D by 17
kashiram pokharel
• check adjacent node of E, and mark node E as visited node
• L(A,F)=min{dist(F), (dist(E)+dist(E,F))} min(17,13+5 ) relabel F by 17
• Hence final graph becomes.
kashiram pokharel
Cut‐Vertex
• A vertex in a graph vЄV(G) is called a cut vertex if the graph without
that vertex has more components than it is before.
i.e. C(G‐V)>C(G)
Where, c(G)=number of connected components of G.
• A cut‐vertex is a single vertex whose removal disconnects a graph. In
the following graph the vertex c and vertex d are called cut vertices.
kashiram pokharel
Theorem1:
• A vertex in a graph v Є V(G) is a cut vertex of graph G, if and only if
there exist two more vertices u and w such that vertex v lies on every
u‐w path of graph G.
Cut edges:
• An edge in a graph e Є E(G) is called a cut edge if graph without that
edge has more component than it is before..
so we can write
C(G‐e)>C(G)
• Where C(G) is the component of graph G.
kashiram pokharel
Cut set:
• A cut set of a connected graph G is a set S of edges with the following
properties
• The removal of all edges in S disconnects G.
• The removal of some (but not all) of edges in S does not disconnects G.
• As an example consider the following graph
• We can disconnect G by removing the three edges bd, bc, and ce, but
we cannot disconnect it by removing
just two of these edges. Note that
a cut set is a set of edges in which
no edge is redundant.
kashiram pokharel
graph coloring
• graph coloring is a special case of graph labeling.
• it is a way of coloring the vertices of a graph such that no two adjacent
vertices share the same color; this is called a vertex coloring.
• Vertex coloring is the starting point of the subject, and other coloring
problems can be transformed into a vertex version.
kashiram pokharel
kashiram pokharel
• an edge coloring assigns a color to each edge so that no two adjacent
edges share the same color,
• An edge coloring with k colors is called a k‐edge‐coloring and is
equivalent to the problem of partitioning the edge set into k matchings.
• The smallest number of colors needed for an edge coloring of a graph G
is the chromatic index, or edge chromatic number, χ′(G).
kashiram pokharel
• a face coloring of a planar graph assigns a color to each face or region
so that no two faces that share a boundary have the same color.
kashiram pokharel
• A coloring using at most k colors is called a (proper) k‐coloring. The
smallest number of colors needed to color a graph G is called
its chromatic number, and is often denoted χ(G).
kashiram pokharel