SlideShare a Scribd company logo
For More Visit: Https://www.ThesisScientist.com
Unit 6
Graph
Definition and Terminology
A graph G consists of a non empty set V called the set of nodes (points, vertices) of the graph,
a set E, which is the set of edges of the graph and a mapping from the set of edges E to a pair
of elements of V.
Any two nodes, which are connected by an edge in a graph are called "adjacent nodes".
In a graph G(V,E) an edge which is directed from one node to another is called a "directed edge",
while an edge which has no specific direction is called an "undirected edge". A graph in which
every edge is directed is called a "directed graph" or a "digraph". A graph in which every edge is
undirected is called an "undirected graph".
If some of edges are directed and some are undirected in a graph then the graph is called a "mixed
graph".
Any graph which contains some parallel edges is called a "multigraph".
If there is no more than one edge but a pair of nodes then, such a graph is called "simple graph."
A graph in which weights are assigned to every edge is called a "weighted graph".
In a graph, a node which is not adjacent to any other node is called "isolated node".
A graph containing only isolated nodes is called a "null graph". In a directed graph for any node v
the number of edges which have v as initial node is called the "outdegree" of the node v. The
number of edges to have v as their terminal node is called the "Indegree" of v and Sum of
outdegree and indegree of a node v is called its total degree.
For More Visit: Https://www.ThesisScientist.com
l
V3
V1l
l l
l
l
V2
e1
e2
V4
V3
e3
V5
en
e6
e5
Simple
Out degree (V1) = 3
In degree (V1) = 0
l
l
l
l
Undirected
l l
l
l
Directed
ll
l l
l
l
V1
V2 V4
V5 V6 V7
V8l
V8 is isolated node
V1
V2
V3
V4
e4
l
l
ll
V8 and V4 have loops
V1
V2
V3
V7
l
l
ll
Weighted graph
l
l
l
V6
V5
V4
l
l
ll
l
Null graph
4
3
5
9
7
8
l
V3
V1l
l l
l
l
l
l l
l
l
V2
e1
e2
V4
V3
e3
V5
en
e6
e5
Simple
Out degree (V1) = 3
In degree (V1) = 0
l
l
l
l l
l
l
l
Undirected
l l
l
l
Directed
ll
l l
l
l
V1
V2 V4
V5 V6 V7
V8l
V8 is isolated node
V1
V2
V3
V4
e4
l
l
ll
V8 and V4 have loops
V1
V2
V3
V7
l
l
ll
Weighted graph
l
l
l
V6
V5
V4
l
l
ll
l
Null graph
4
3
5
9
7
8
Figure 6.1
For More Visit: Https://www.ThesisScientist.com
Definition and Terminology
A GRAPH G, consists of two sets V and E. V is a finite non-empty set of vertices. E is a set of pairs of
vertices, these pairs are called edges. V(G) and E(G) will represent the sets of vertices and edges of graph
G. In an undirected graph the pair of vertices representing any edge is unordered. Thus, the pair (V1 , V2)
and (V2, V1) represent the same edge.
In a directed graph each edge is represented by a directed pair <V1, V2>, V1 is the tail and V2 the head of
edge. Thus <V2, V1> and <V1, V2> represent two different edges.
Figure 6.2 : Three Sample Graph
The graph G1 and G2 are undirected. G3 is a directed graph.
l V(G1) = {1, 2, 3, 4,} ; E(G1) = {(1, 2), (1, 3), (1, 4), (2, 3), (2, 4) (3, 4)}
l V(G2) = {1, 2, 3, 4, 5, 6, 7} ; E(G2) = {(1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (3, 7)}
l V(G3) = {1, 2, 3}; E(G3) = {<1, 2>, <2, 1>, <2, 3>}
The graph G1 is also a tree while the graphs G1 and G3 are not. A graph may not have multiple occurrences
of the same edge, when this restriction is removed from a graph, the resulting data object is referred to as a
multigraph, which is not a graph.
Figure 6.3 : Multigraph
.
For More Visit: Https://www.ThesisScientist.com
Representation of Graphs
Three most commonly used representations are :
i) Adjacency matrices
ii) Adjacency lists
iii) Adjacency multilist
Adjacency Matrix
Let G = (V, E) be a graph with n vertices, n  1. The adjacency matrix of (G) is a 2-dimensional nxn array,
say A, with the property that A(ij) = 1 if the edge (Vi, Vj) for a directed graph G is in E(G). The adjacency
matrix for an undirected graph is symmetric as the edge (Vi, Vj) is in E(G) if the edge (Vj, Vi) is also in
E(G).
The adjacency matrix for a directed graph need not be symmetric.
Figure 6.4 : Adjacency Matrix Representation of Graph
A simple digraph which doesn't have any cycle is called "acyclic". Naturally such graphs cannot have any
loop.
Example 1
Let, V ={v1,v2,v3}
vxv ={(v1v2), (v1v3), (v2v1),(v2v3), (v3v1),(v3v2),(v1v1),(v2v2), (v3v3)}
Suppose we have graph with 3 vertices: Consider the following graph with
set V :
v1 v2 v3
For More Visit: Https://www.ThesisScientist.com
v1 0 1 0
A = v2 0 0 0 Direction from Row to Column
v3 1 1 1
This matrix is also called "Adjacency matrix"
0 1 1
1 0 1
1 1 1
For a given digraph G (V,E) an Adjacency Matrix depends upon the ordering of the elements of V. For
different orderings of the elements of V we get different adjacency matrices of the same graph G.
Path Matrix
We can extend the idea of matrix representation to multigraph and weighted graphs. For simple undirected
graphs such an extension simply gives symmetric adjacency matrix. In the case of multigraph or a weighted
graph we write aij=wij, where wij denotes the weight of the edge (Vi,Vj). If (Vi, Vj)E then we write
wij =0
For a null graph, adjacency matrix is a null matrix. If there are loops at each node but no other edges in the
graph then the adjacncy matrix is the identity or unit matrix.
V1 V2 V3 V4
V1 0 1 0 1
Let us denote the elements of A2 by aij2 then A[i] = V2 1 0 0 0
V3 1 1 0 1
V4 0 1 0 0
aij(2)= nk=1aik,akj
for any fixed k aik.akj=1, if both aik and akj equals 1 i.e., (ViVk) (VkVj) are the edges of the graph.
The matrices A2, A3 and A4 for the graph represented by the above matrix are:
V1 V2 V3 V4 V1 V2 V3 V4
V1 1 1 0 0 V1 1 1 0 1
A2 = V2 0 1 0 1 A3= V2 0 1 0 1
V3 1 2 0 1 V3 2 2 0 1
V4 0 0 0 0 V4 1 1 0 0
V1 V2 V3 V4
V1 1 2 0 1
A4 = V2 1 1 0 1
For More Visit: Https://www.ThesisScientist.com
V3 2 3 0 2
V4 1 1 0 0
((1) (2) (3).... can be considered as the length of path)
The matrix representing the paths of length less than or equal to n which exists from Vi to Vj is
Bn = A+A2+......An
if we write dij = Vnr=1(aik  bkj) V i, j = 1,2......n.
V = union of (OR)
 = And
For example :
d11=(a11 b11) V(a12 b21) V ........(a1n Vbn1)
If for any k, the kth element in the row for A and the kth element in the column for B are both 1 then dij=1;
otherwise dij =0. Let us write AA =A(2), AA(x-1)=A(x) for any r=2,3........ the entry in the ith
row and jth
column of A(x) is 1 if there is at least one path of length r from Vi to Vj. The path matrix P is given by:
P=AVA(2)VA(3)V...VA(n)=Vnk=VnRs1A(k)
Warshall Algorithm
Given the adjacency matrix A , this matrix produces the path matrix P.
1. [Initialization]
PA
2 [Perform a pass]
Repeat three step A for k=1(1)n
3 [Process Rows]
Repeat step 4 for i=1(1) n.
4 [Across column]
Repeat for j=1(1)n
Pijpij V(Vik ^ Pkj)
5. [Exit]
Minimal Algorithm
Given the adjacency matrix B in which the zero elements are replaced by infinity or by some large number,
the matrix produced by the following algorithm shows the minimum length of paths between the nodes
MIN is a function that selects the algebraic minimum of its two arguments.
[1.] cB
[2.] Repeat thru step 4 for k =1(1) n
For More Visit: Https://www.ThesisScientist.com
[3.] Repeat thru step 4 forj =1(1) n
cij= MIN (cij, cik+ ckj)
[5.] exit
Example (Warshall)
Suppose we have 3 vertices v 1v2 v3
V1 V2 V3
Adjacency matrix A = V1 0 1 0
V2 0 0 0 = p
V3 1 1 1
V1 l
V3 V2
l l
V1 l
V3 V2
l l
I Iteration
 R=1, i=1, j=1,2,3 for p(1)
P11=P11V(P11 P11) =0V(00)=0
P12=P12V(P11 P12) =1V(01)=1
P13=P13V(P11 P13) =0V(00)=0
 k=1, i=2, j=1,2,3
P21=P21V(P21^P22)=0
P22=P22V(P21^ P22)=0
P23 =0
 k=1, i=3, j=1,2,3
P31=P31 V (P31^P31)=1
P32=P32 V (P31^P32)=1
p33=P33 V (P31 ^ P33) = 1
Hence,
For More Visit: Https://www.ThesisScientist.com
0 1 0
Pv = 0 0 0
1 1 1
II Insertion
for k=2 for p(2)
i=1
j=1,2,3
P11=P11V(P12 ^ P21)=0
P12=P12V(P12 ^ P22)=0
P13=P13V(P12 ^ P23)=
. .
. .
. .
Similarly, we can calculate Matrix for
k=3 and so on
Adjacency List
In this representation the n rows of the adjacency matrix are represented as n linked lists. There is one list
for each vertex in G. The nodes in list i represent the vertices that are adjacent from vertex i.
Each node has two fields, VERTEX and LINK. The vertex field contains the indices of the vertices
adjacent to vertex i.
Each node has a head node. Head nodes are sequential providing easy random access to the adjacency list
for any particular vertex.
For More Visit: Https://www.ThesisScientist.com
Figure 6.5
Adjancency Multi-list
In the adjacency list representation of an undirect graph each edge (Vi, Vj) is represented by two
entries, one on the list for Vi and the other on the list for Vj. In some situations it is necessary to be
able to determine the second entry for a particular edge and mark that edge as already having been
examined. This can be accomplished easily if the adjacency lists are actually maintained as
multilist (i.e., lists in which nodes may be shared among several lists).
For each edge there will be exactly one node, but this node will be in two lists, i.e., the adjacency
list for each of the two nodes it is incident to. The node structure will be:
where M is a one bit mark field that may be used to indicate whether or not the edge has been
examined.
e.g., Graph
M V1 V2
LINK 1
For V1
LINK 2
For V2
For More Visit: Https://www.ThesisScientist.com
The lists are :
Vertex 1 : N1  N2  N3
Vertex 2 : N1  N4  N5
Vertex 3 : N2  N4  N6
Vertex 4 : N3  N5  N6
Figure 6.7 : Adjacency Multilist for the given Graph
Traversal of a Graph
l Depth first search
l Breadth first search
Depth First Search
DFS algorithm is analogous to preorder traversal of a tree. Given an undirected graph g= (V,E) and a vertex
V in V(G), we are interested in visiting all vertices in G that are reachable from (i.e. all vertices connected
to V).
For More Visit: Https://www.ThesisScientist.com
DFS of an undirected graph precedes as follows:
The start vertex C is visited Next an unvisited vertex w adjacent to V is selected and a depth first search
initiated. (Adjacent means connected by an Arc from the search node.)
Algorithm DFS (V)
1. Given an adjacent graph G=(V,E) with n vertices an array VISITED [N] initially set to zero
this algorithm visits all vertices reachable from V and visited are global.
VISITED (V) 1
2. Check for adjacent vertex W to V and call recursively
for each vertex W adjacent to V do
if (visited (W)=0) then call DFS(W)
end
3. [exit]
Breadh First Search
Starting at vertex V and making is as visited BFS differs from DFS in that all unvisited vertices
adjacent to V are visited next. Then unvisited vertices adjacent to these vertices are visited and so
on.
Algorithm BFS (V)
1. [A BFS of G is carried out beginning at vertex V. All vertices visited are marked as
VISTED(I)=1. The graph G and array VISITED are global and VISITED is initialized to 0]
VISITED (V) 1
initialize Q to be empty [Q is queue]
2. [Perform Iterations]
loop
for all vertices W adjacent to V do
if VISITED (W) =0
then [Add (W,Q); VISITED (W) 1]
end
if Q is empty then return;
DELETE (V,Q)
forever
For More Visit: Https://www.ThesisScientist.com
<exit>
GRAPH G
V1
V2 V3
V4 V7
V8
V5 V6
V1V1
V2V2 V3V3
V4V4 V7V7
V8V8
V5V5 V6V6
Traversing by DFS : V1, V2 , V4, V8, V5, V3, V6, V7
Traversing by BFS :V1, V2, V3, V4, V5, V6, V7, V8
Analysis of Algorithms
1. DFS
If G is represented by its adjacency matrix, then the time to determine all vertices adjacent to V is
O(N). Since at most n vertices are visited, the total time is O(N2
).
2. BFS
Each vertex visited gets into the queue exactly once, so the loop.....forever is iterated at most n
times.
If an adjacency matrix is used then the for loop takes O(N) times for each vertex visited.
The total time is therefore O(N2
).
Weighted Graphs
A graph in which weights are assigned to every edge is called a Weighted graph.
Shortest Path in Weighted Graphs
Let G= (v,e,w) be a weighted graph where w is weight (in terms of time or cost) assigned to that
edge.
The length of a path in G is defined as the sum of lengths of the edges in the path.
Dijkstra's Shortest Path Algorithm
For More Visit: Https://www.ThesisScientist.com
Let TV with AT (A= starting node). Let P be the subset of vertices V-T, let L(T) denote the
length of a shortest path among all paths from A to T that does not include any other vertex in T.
We call L(T) the index of T with respect to P.
Let X be a vertex in T. Let P' be PU{X} and T' be T-{X}. Let L'(T) denote the index of a
vertex T inT' with respect to P'. We claim that
L'(T) =Min[L(T), L(X), L(W,T)]-----------(i)
Algorithm
1. Initially let P= [a] and T =V-[a] , for every vertex t in t, let l(t)= w (A,t).
2. Select the vertex in T that has the smallest index with respect to P, let it denote it vertex x.
3. If x is the vertex we wish to reach from A stop. If not let P'=PU{x} and T=T-{x}. For
every vertex t in T compute its index with respect to P' according to 1.
4. Repeat steps 2 and 3 using P' as P and T' as T.
5. Stop.
Example
Find the shortest path from A to Z for the given graph:
1.
B D
C E
A Z
1
2
4
7
5
1
2
3
6
BB DD
CC EE
AA ZZ
1
2
4
7
5
1
2
3
6
Solution:
Initially P={A} and
T={B,C,E,D,Z}
The lengths of different vertices (with respect to P) are :
L(B)=1 , L(C)=4, L(D)=L(E)= L(Z)= 
l so L(B)= 1 is the shortest value
Now let P={A,B} and T={C,D,E,Z}
For More Visit: Https://www.ThesisScientist.com
so, L(C)=3, L(D)=8, L(E)=6, L(Z)= 
l So L(C) =3, is the shortest value.
Now P={A,B, C} and T'={D,E,Z}
L'(D)= Min{8,}=8. L'(E)= Min{6,3+1}=4
L'(Z) = Min {,3+}= 
Successive observations are shown in following figures:
Thus the shortest path from A to Z is (A, B, C, E, D, Z) of length 9.
B D
C E
A Z
DD
ZZ 
2.

4 (a)
B D
C E
A Z
DD
ZZ 
2.

4 (a)
For More Visit: Https://www.ThesisScientist.com
Spanning Trees
It is a tree obtained from a Graph, which covers all its vertices.
Minimal Spanning Tree
It is a tree from the set of spanning trees, which has minimum weight.
There are two methods to find minimum spanning tree.
l Prim's Method
l Kruskal's method
1. Prim's Method
Draw n isolated vertices and label them as V1,V2.....Vn. Tabulate the given weights of the
edges of G in an nxn table. Set the weights of the non-existing edges as very large ()
l
l
ll
l
l
17
8
11
V4
10V5
16
V1
V2
V6
V3
9
7
7
19.5
9.512
l
l
ll
l
l
17
8
11
V4
10V5
16
V1
V2
V6
V3
9
7
7
19.5
9.512
V V2 V3 V4 V5 V6
V1 - 10 16 11 10 17
V2 10 - 9.5   19.5
V3 16 9.5 - 7  12
V4 11  7 - 8 7
V5 10   8 - 9
V6 17 19.5 12 7 9 -
For More Visit: Https://www.ThesisScientist.com
Start from vertex V1 and connect it to its nearest neighbor say Vk. Now consider V1 and Vk as one subgraph
and connect this subgraph to its closest neighbor (i.e. to a vertex other than V1 and Vk that has the smallest
entry among all entries in rows 1 and k.)
2. Kruskal's Method
In this approach Minimum cost spanning tree T is built edge by edge. Edges are considered for
inclusion in T in ascending order. An edge is included in T if it doesn't form a cycle with edges
already in T. Since G is connected and has n>0 vertices exactly (n-1) edges will be selected for
inclusion in T.
1
5
6
2
4
3
16
21 11
33 14
18
19 6
5
10
11
55
66
22
44
33
16
21 11
33 14
18
19 6
5
10
Edge Cost Action Resulting Tree
.... ...... ......... .......................
(2,3) 5 Accept
(2,4) 6 Accept
(3,4) 10 Reject "
(2,6) 11 Accept
(4,6) 14 Reject "
(1,2) 16 Accept
(4,5) 18 Accept
1 2 3 4 5 6
1 3 4 5 62
1 3 5 62
4
11 22 33 44 55 66
11 33 44 55 6622
11 33 55 6622
44
1 5
43 6
211 55
4433 66
22
5
43 6
21 55
4433 66
2211
43 6
21
5
4433 66
2211
55

More Related Content

What's hot

Application Of Graph Data Structure
Application Of Graph Data StructureApplication Of Graph Data Structure
Application Of Graph Data Structure
Gaurang Dobariya
 
List in java
List in javaList in java
List in java
nitin kumar
 
Splay Tree
Splay TreeSplay Tree
Adjacency list
Adjacency listAdjacency list
Adjacency listStefi Yu
 
Solving recurrences
Solving recurrencesSolving recurrences
Solving recurrences
Megha V
 
Data Structures : hashing (1)
Data Structures : hashing (1)Data Structures : hashing (1)
Data Structures : hashing (1)
Home
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysissumitbardhan
 
Merge sort and quick sort
Merge sort and quick sortMerge sort and quick sort
Merge sort and quick sort
Shakila Mahjabin
 
Sorting And Type of Sorting
Sorting And Type of SortingSorting And Type of Sorting
Sorting And Type of Sorting
MITULJAMANG
 
Graphs In Data Structure
Graphs In Data StructureGraphs In Data Structure
Graphs In Data StructureAnuj Modi
 
Tree Traversal
Tree TraversalTree Traversal
Tree Traversal
Md. Israil Fakir
 
Linked list
Linked listLinked list
Linked list
akshat360
 
Bfs and Dfs
Bfs and DfsBfs and Dfs
Bfs and Dfs
Masud Parvaze
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1
Amrinder Arora
 
Data structure - Graph
Data structure - GraphData structure - Graph
Data structure - Graph
Madhu Bala
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
Rajendran
 
Introduction TO Finite Automata
Introduction TO Finite AutomataIntroduction TO Finite Automata
Introduction TO Finite Automata
Ratnakar Mikkili
 
Best,worst,average case .17581556 045
Best,worst,average case .17581556 045Best,worst,average case .17581556 045
Best,worst,average case .17581556 045
university of Gujrat, pakistan
 
Morphological Image Processing
Morphological Image ProcessingMorphological Image Processing
Morphological Image Processing
kumari36
 

What's hot (20)

Application Of Graph Data Structure
Application Of Graph Data StructureApplication Of Graph Data Structure
Application Of Graph Data Structure
 
AVL Tree
AVL TreeAVL Tree
AVL Tree
 
List in java
List in javaList in java
List in java
 
Splay Tree
Splay TreeSplay Tree
Splay Tree
 
Adjacency list
Adjacency listAdjacency list
Adjacency list
 
Solving recurrences
Solving recurrencesSolving recurrences
Solving recurrences
 
Data Structures : hashing (1)
Data Structures : hashing (1)Data Structures : hashing (1)
Data Structures : hashing (1)
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
 
Merge sort and quick sort
Merge sort and quick sortMerge sort and quick sort
Merge sort and quick sort
 
Sorting And Type of Sorting
Sorting And Type of SortingSorting And Type of Sorting
Sorting And Type of Sorting
 
Graphs In Data Structure
Graphs In Data StructureGraphs In Data Structure
Graphs In Data Structure
 
Tree Traversal
Tree TraversalTree Traversal
Tree Traversal
 
Linked list
Linked listLinked list
Linked list
 
Bfs and Dfs
Bfs and DfsBfs and Dfs
Bfs and Dfs
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1
 
Data structure - Graph
Data structure - GraphData structure - Graph
Data structure - Graph
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
 
Introduction TO Finite Automata
Introduction TO Finite AutomataIntroduction TO Finite Automata
Introduction TO Finite Automata
 
Best,worst,average case .17581556 045
Best,worst,average case .17581556 045Best,worst,average case .17581556 045
Best,worst,average case .17581556 045
 
Morphological Image Processing
Morphological Image ProcessingMorphological Image Processing
Morphological Image Processing
 

Similar to Graph in Data Structure

Chap 6 Graph.ppt
Chap 6 Graph.pptChap 6 Graph.ppt
Chap 6 Graph.ppt
shashankbhadouria4
 
Graphs
GraphsGraphs
Graphs
amudha arul
 
Graph representation
Graph representationGraph representation
Graph representation
DEEPIKA T
 
Fallsem2015 16 cp4194-13-oct-2015_rm01_graphs
Fallsem2015 16 cp4194-13-oct-2015_rm01_graphsFallsem2015 16 cp4194-13-oct-2015_rm01_graphs
Fallsem2015 16 cp4194-13-oct-2015_rm01_graphs
SnehilKeshari
 
Class01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdf
Class01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdfClass01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdf
Class01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdf
ChristianKapsales1
 
Grpahs in Data Structure
Grpahs in Data StructureGrpahs in Data Structure
Grpahs in Data Structure
AvichalVishnoi
 
Graph
GraphGraph
Lecture 5b graphs and hashing
Lecture 5b graphs and hashingLecture 5b graphs and hashing
Lecture 5b graphs and hashingVictor Palmar
 
chapter6.PPT
chapter6.PPTchapter6.PPT
chapter6.PPT
krish448427
 
Dsa.PPT
Dsa.PPTDsa.PPT
Dsa.PPT
boltkat
 
Data Structures and Agorithm: DS 21 Graph Theory.pptx
Data Structures and Agorithm: DS 21 Graph Theory.pptxData Structures and Agorithm: DS 21 Graph Theory.pptx
Data Structures and Agorithm: DS 21 Graph Theory.pptx
RashidFaridChishti
 
Introduction to Graph Theory
Introduction to Graph TheoryIntroduction to Graph Theory
Introduction to Graph Theory
Premsankar Chakkingal
 
09_DS_MCA_Graphs.pdf
09_DS_MCA_Graphs.pdf09_DS_MCA_Graphs.pdf
09_DS_MCA_Graphs.pdf
Prasanna David
 
Discrete maths assignment
Discrete maths assignmentDiscrete maths assignment
Discrete maths assignmentKeshav Somani
 
Matrix representation of graph
Matrix representation of graphMatrix representation of graph
Matrix representation of graph
Rounak Biswas
 
Graph terminology and algorithm and tree.pptx
Graph terminology and algorithm and tree.pptxGraph terminology and algorithm and tree.pptx
Graph terminology and algorithm and tree.pptx
asimshahzad8611
 
graph.pptx
graph.pptxgraph.pptx
graph.pptx
hijigaf
 
Graph Theory
Graph TheoryGraph Theory
Graph Theory
kailash shaw
 
graph_theory_1-11.pdf___________________
graph_theory_1-11.pdf___________________graph_theory_1-11.pdf___________________
graph_theory_1-11.pdf___________________
ssuser1989da
 
Graph theory concepts complex networks presents-rouhollah nabati
Graph theory concepts   complex networks presents-rouhollah nabatiGraph theory concepts   complex networks presents-rouhollah nabati
Graph theory concepts complex networks presents-rouhollah nabati
nabati
 

Similar to Graph in Data Structure (20)

Chap 6 Graph.ppt
Chap 6 Graph.pptChap 6 Graph.ppt
Chap 6 Graph.ppt
 
Graphs
GraphsGraphs
Graphs
 
Graph representation
Graph representationGraph representation
Graph representation
 
Fallsem2015 16 cp4194-13-oct-2015_rm01_graphs
Fallsem2015 16 cp4194-13-oct-2015_rm01_graphsFallsem2015 16 cp4194-13-oct-2015_rm01_graphs
Fallsem2015 16 cp4194-13-oct-2015_rm01_graphs
 
Class01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdf
Class01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdfClass01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdf
Class01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdf
 
Grpahs in Data Structure
Grpahs in Data StructureGrpahs in Data Structure
Grpahs in Data Structure
 
Graph
GraphGraph
Graph
 
Lecture 5b graphs and hashing
Lecture 5b graphs and hashingLecture 5b graphs and hashing
Lecture 5b graphs and hashing
 
chapter6.PPT
chapter6.PPTchapter6.PPT
chapter6.PPT
 
Dsa.PPT
Dsa.PPTDsa.PPT
Dsa.PPT
 
Data Structures and Agorithm: DS 21 Graph Theory.pptx
Data Structures and Agorithm: DS 21 Graph Theory.pptxData Structures and Agorithm: DS 21 Graph Theory.pptx
Data Structures and Agorithm: DS 21 Graph Theory.pptx
 
Introduction to Graph Theory
Introduction to Graph TheoryIntroduction to Graph Theory
Introduction to Graph Theory
 
09_DS_MCA_Graphs.pdf
09_DS_MCA_Graphs.pdf09_DS_MCA_Graphs.pdf
09_DS_MCA_Graphs.pdf
 
Discrete maths assignment
Discrete maths assignmentDiscrete maths assignment
Discrete maths assignment
 
Matrix representation of graph
Matrix representation of graphMatrix representation of graph
Matrix representation of graph
 
Graph terminology and algorithm and tree.pptx
Graph terminology and algorithm and tree.pptxGraph terminology and algorithm and tree.pptx
Graph terminology and algorithm and tree.pptx
 
graph.pptx
graph.pptxgraph.pptx
graph.pptx
 
Graph Theory
Graph TheoryGraph Theory
Graph Theory
 
graph_theory_1-11.pdf___________________
graph_theory_1-11.pdf___________________graph_theory_1-11.pdf___________________
graph_theory_1-11.pdf___________________
 
Graph theory concepts complex networks presents-rouhollah nabati
Graph theory concepts   complex networks presents-rouhollah nabatiGraph theory concepts   complex networks presents-rouhollah nabati
Graph theory concepts complex networks presents-rouhollah nabati
 

More from Prof Ansari

Sci Hub New Domain
Sci Hub New DomainSci Hub New Domain
Sci Hub New Domain
Prof Ansari
 
Sci Hub cc Not Working
Sci Hub cc Not WorkingSci Hub cc Not Working
Sci Hub cc Not Working
Prof Ansari
 
basics of computer network
basics of computer networkbasics of computer network
basics of computer network
Prof Ansari
 
JAVA INTRODUCTION
JAVA INTRODUCTIONJAVA INTRODUCTION
JAVA INTRODUCTION
Prof Ansari
 
Project Evaluation and Estimation in Software Development
Project Evaluation and Estimation in Software DevelopmentProject Evaluation and Estimation in Software Development
Project Evaluation and Estimation in Software Development
Prof Ansari
 
Stepwise Project planning in software development
Stepwise Project planning in software developmentStepwise Project planning in software development
Stepwise Project planning in software development
Prof Ansari
 
Database and Math Relations
Database and Math RelationsDatabase and Math Relations
Database and Math Relations
Prof Ansari
 
Normalisation in Database management System (DBMS)
Normalisation in Database management System (DBMS)Normalisation in Database management System (DBMS)
Normalisation in Database management System (DBMS)
Prof Ansari
 
Entity-Relationship Data Model in DBMS
Entity-Relationship Data Model in DBMSEntity-Relationship Data Model in DBMS
Entity-Relationship Data Model in DBMS
Prof Ansari
 
A Detail Database Architecture
A Detail Database ArchitectureA Detail Database Architecture
A Detail Database Architecture
Prof Ansari
 
INTRODUCTION TO Database Management System (DBMS)
INTRODUCTION TO Database Management System (DBMS)INTRODUCTION TO Database Management System (DBMS)
INTRODUCTION TO Database Management System (DBMS)
Prof Ansari
 
Master thesis on Vehicular Ad hoc Networks (VANET)
Master thesis on Vehicular Ad hoc Networks (VANET)Master thesis on Vehicular Ad hoc Networks (VANET)
Master thesis on Vehicular Ad hoc Networks (VANET)
Prof Ansari
 
Master Thesis on Vehicular Ad-hoc Network (VANET)
Master Thesis on Vehicular Ad-hoc Network (VANET)Master Thesis on Vehicular Ad-hoc Network (VANET)
Master Thesis on Vehicular Ad-hoc Network (VANET)
Prof Ansari
 
INTERFACING WITH INTEL 8251A (USART)
INTERFACING WITH INTEL 8251A (USART)INTERFACING WITH INTEL 8251A (USART)
INTERFACING WITH INTEL 8251A (USART)
Prof Ansari
 
HOST AND NETWORK SECURITY by ThesisScientist.com
HOST AND NETWORK SECURITY by ThesisScientist.comHOST AND NETWORK SECURITY by ThesisScientist.com
HOST AND NETWORK SECURITY by ThesisScientist.com
Prof Ansari
 
SYSTEM NETWORK ADMINISTRATIONS GOALS and TIPS
SYSTEM NETWORK ADMINISTRATIONS GOALS and TIPSSYSTEM NETWORK ADMINISTRATIONS GOALS and TIPS
SYSTEM NETWORK ADMINISTRATIONS GOALS and TIPS
Prof Ansari
 
INTRODUCTION TO VISUAL BASICS
INTRODUCTION TO VISUAL BASICS INTRODUCTION TO VISUAL BASICS
INTRODUCTION TO VISUAL BASICS
Prof Ansari
 
introduction to Blogging ppt
introduction to Blogging pptintroduction to Blogging ppt
introduction to Blogging ppt
Prof Ansari
 
INTRODUCTION TO SOFTWARE ENGINEERING
INTRODUCTION TO SOFTWARE ENGINEERINGINTRODUCTION TO SOFTWARE ENGINEERING
INTRODUCTION TO SOFTWARE ENGINEERING
Prof Ansari
 
Introduction to E-commerce
Introduction to E-commerceIntroduction to E-commerce
Introduction to E-commerce
Prof Ansari
 

More from Prof Ansari (20)

Sci Hub New Domain
Sci Hub New DomainSci Hub New Domain
Sci Hub New Domain
 
Sci Hub cc Not Working
Sci Hub cc Not WorkingSci Hub cc Not Working
Sci Hub cc Not Working
 
basics of computer network
basics of computer networkbasics of computer network
basics of computer network
 
JAVA INTRODUCTION
JAVA INTRODUCTIONJAVA INTRODUCTION
JAVA INTRODUCTION
 
Project Evaluation and Estimation in Software Development
Project Evaluation and Estimation in Software DevelopmentProject Evaluation and Estimation in Software Development
Project Evaluation and Estimation in Software Development
 
Stepwise Project planning in software development
Stepwise Project planning in software developmentStepwise Project planning in software development
Stepwise Project planning in software development
 
Database and Math Relations
Database and Math RelationsDatabase and Math Relations
Database and Math Relations
 
Normalisation in Database management System (DBMS)
Normalisation in Database management System (DBMS)Normalisation in Database management System (DBMS)
Normalisation in Database management System (DBMS)
 
Entity-Relationship Data Model in DBMS
Entity-Relationship Data Model in DBMSEntity-Relationship Data Model in DBMS
Entity-Relationship Data Model in DBMS
 
A Detail Database Architecture
A Detail Database ArchitectureA Detail Database Architecture
A Detail Database Architecture
 
INTRODUCTION TO Database Management System (DBMS)
INTRODUCTION TO Database Management System (DBMS)INTRODUCTION TO Database Management System (DBMS)
INTRODUCTION TO Database Management System (DBMS)
 
Master thesis on Vehicular Ad hoc Networks (VANET)
Master thesis on Vehicular Ad hoc Networks (VANET)Master thesis on Vehicular Ad hoc Networks (VANET)
Master thesis on Vehicular Ad hoc Networks (VANET)
 
Master Thesis on Vehicular Ad-hoc Network (VANET)
Master Thesis on Vehicular Ad-hoc Network (VANET)Master Thesis on Vehicular Ad-hoc Network (VANET)
Master Thesis on Vehicular Ad-hoc Network (VANET)
 
INTERFACING WITH INTEL 8251A (USART)
INTERFACING WITH INTEL 8251A (USART)INTERFACING WITH INTEL 8251A (USART)
INTERFACING WITH INTEL 8251A (USART)
 
HOST AND NETWORK SECURITY by ThesisScientist.com
HOST AND NETWORK SECURITY by ThesisScientist.comHOST AND NETWORK SECURITY by ThesisScientist.com
HOST AND NETWORK SECURITY by ThesisScientist.com
 
SYSTEM NETWORK ADMINISTRATIONS GOALS and TIPS
SYSTEM NETWORK ADMINISTRATIONS GOALS and TIPSSYSTEM NETWORK ADMINISTRATIONS GOALS and TIPS
SYSTEM NETWORK ADMINISTRATIONS GOALS and TIPS
 
INTRODUCTION TO VISUAL BASICS
INTRODUCTION TO VISUAL BASICS INTRODUCTION TO VISUAL BASICS
INTRODUCTION TO VISUAL BASICS
 
introduction to Blogging ppt
introduction to Blogging pptintroduction to Blogging ppt
introduction to Blogging ppt
 
INTRODUCTION TO SOFTWARE ENGINEERING
INTRODUCTION TO SOFTWARE ENGINEERINGINTRODUCTION TO SOFTWARE ENGINEERING
INTRODUCTION TO SOFTWARE ENGINEERING
 
Introduction to E-commerce
Introduction to E-commerceIntroduction to E-commerce
Introduction to E-commerce
 

Recently uploaded

一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
WENKENLI1
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
TeeVichai
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
ongomchris
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
BrazilAccount1
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
aqil azizi
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 

Recently uploaded (20)

一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 

Graph in Data Structure

  • 1. For More Visit: Https://www.ThesisScientist.com Unit 6 Graph Definition and Terminology A graph G consists of a non empty set V called the set of nodes (points, vertices) of the graph, a set E, which is the set of edges of the graph and a mapping from the set of edges E to a pair of elements of V. Any two nodes, which are connected by an edge in a graph are called "adjacent nodes". In a graph G(V,E) an edge which is directed from one node to another is called a "directed edge", while an edge which has no specific direction is called an "undirected edge". A graph in which every edge is directed is called a "directed graph" or a "digraph". A graph in which every edge is undirected is called an "undirected graph". If some of edges are directed and some are undirected in a graph then the graph is called a "mixed graph". Any graph which contains some parallel edges is called a "multigraph". If there is no more than one edge but a pair of nodes then, such a graph is called "simple graph." A graph in which weights are assigned to every edge is called a "weighted graph". In a graph, a node which is not adjacent to any other node is called "isolated node". A graph containing only isolated nodes is called a "null graph". In a directed graph for any node v the number of edges which have v as initial node is called the "outdegree" of the node v. The number of edges to have v as their terminal node is called the "Indegree" of v and Sum of outdegree and indegree of a node v is called its total degree.
  • 2. For More Visit: Https://www.ThesisScientist.com l V3 V1l l l l l V2 e1 e2 V4 V3 e3 V5 en e6 e5 Simple Out degree (V1) = 3 In degree (V1) = 0 l l l l Undirected l l l l Directed ll l l l l V1 V2 V4 V5 V6 V7 V8l V8 is isolated node V1 V2 V3 V4 e4 l l ll V8 and V4 have loops V1 V2 V3 V7 l l ll Weighted graph l l l V6 V5 V4 l l ll l Null graph 4 3 5 9 7 8 l V3 V1l l l l l l l l l l V2 e1 e2 V4 V3 e3 V5 en e6 e5 Simple Out degree (V1) = 3 In degree (V1) = 0 l l l l l l l l Undirected l l l l Directed ll l l l l V1 V2 V4 V5 V6 V7 V8l V8 is isolated node V1 V2 V3 V4 e4 l l ll V8 and V4 have loops V1 V2 V3 V7 l l ll Weighted graph l l l V6 V5 V4 l l ll l Null graph 4 3 5 9 7 8 Figure 6.1
  • 3. For More Visit: Https://www.ThesisScientist.com Definition and Terminology A GRAPH G, consists of two sets V and E. V is a finite non-empty set of vertices. E is a set of pairs of vertices, these pairs are called edges. V(G) and E(G) will represent the sets of vertices and edges of graph G. In an undirected graph the pair of vertices representing any edge is unordered. Thus, the pair (V1 , V2) and (V2, V1) represent the same edge. In a directed graph each edge is represented by a directed pair <V1, V2>, V1 is the tail and V2 the head of edge. Thus <V2, V1> and <V1, V2> represent two different edges. Figure 6.2 : Three Sample Graph The graph G1 and G2 are undirected. G3 is a directed graph. l V(G1) = {1, 2, 3, 4,} ; E(G1) = {(1, 2), (1, 3), (1, 4), (2, 3), (2, 4) (3, 4)} l V(G2) = {1, 2, 3, 4, 5, 6, 7} ; E(G2) = {(1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (3, 7)} l V(G3) = {1, 2, 3}; E(G3) = {<1, 2>, <2, 1>, <2, 3>} The graph G1 is also a tree while the graphs G1 and G3 are not. A graph may not have multiple occurrences of the same edge, when this restriction is removed from a graph, the resulting data object is referred to as a multigraph, which is not a graph. Figure 6.3 : Multigraph .
  • 4. For More Visit: Https://www.ThesisScientist.com Representation of Graphs Three most commonly used representations are : i) Adjacency matrices ii) Adjacency lists iii) Adjacency multilist Adjacency Matrix Let G = (V, E) be a graph with n vertices, n  1. The adjacency matrix of (G) is a 2-dimensional nxn array, say A, with the property that A(ij) = 1 if the edge (Vi, Vj) for a directed graph G is in E(G). The adjacency matrix for an undirected graph is symmetric as the edge (Vi, Vj) is in E(G) if the edge (Vj, Vi) is also in E(G). The adjacency matrix for a directed graph need not be symmetric. Figure 6.4 : Adjacency Matrix Representation of Graph A simple digraph which doesn't have any cycle is called "acyclic". Naturally such graphs cannot have any loop. Example 1 Let, V ={v1,v2,v3} vxv ={(v1v2), (v1v3), (v2v1),(v2v3), (v3v1),(v3v2),(v1v1),(v2v2), (v3v3)} Suppose we have graph with 3 vertices: Consider the following graph with set V : v1 v2 v3
  • 5. For More Visit: Https://www.ThesisScientist.com v1 0 1 0 A = v2 0 0 0 Direction from Row to Column v3 1 1 1 This matrix is also called "Adjacency matrix" 0 1 1 1 0 1 1 1 1 For a given digraph G (V,E) an Adjacency Matrix depends upon the ordering of the elements of V. For different orderings of the elements of V we get different adjacency matrices of the same graph G. Path Matrix We can extend the idea of matrix representation to multigraph and weighted graphs. For simple undirected graphs such an extension simply gives symmetric adjacency matrix. In the case of multigraph or a weighted graph we write aij=wij, where wij denotes the weight of the edge (Vi,Vj). If (Vi, Vj)E then we write wij =0 For a null graph, adjacency matrix is a null matrix. If there are loops at each node but no other edges in the graph then the adjacncy matrix is the identity or unit matrix. V1 V2 V3 V4 V1 0 1 0 1 Let us denote the elements of A2 by aij2 then A[i] = V2 1 0 0 0 V3 1 1 0 1 V4 0 1 0 0 aij(2)= nk=1aik,akj for any fixed k aik.akj=1, if both aik and akj equals 1 i.e., (ViVk) (VkVj) are the edges of the graph. The matrices A2, A3 and A4 for the graph represented by the above matrix are: V1 V2 V3 V4 V1 V2 V3 V4 V1 1 1 0 0 V1 1 1 0 1 A2 = V2 0 1 0 1 A3= V2 0 1 0 1 V3 1 2 0 1 V3 2 2 0 1 V4 0 0 0 0 V4 1 1 0 0 V1 V2 V3 V4 V1 1 2 0 1 A4 = V2 1 1 0 1
  • 6. For More Visit: Https://www.ThesisScientist.com V3 2 3 0 2 V4 1 1 0 0 ((1) (2) (3).... can be considered as the length of path) The matrix representing the paths of length less than or equal to n which exists from Vi to Vj is Bn = A+A2+......An if we write dij = Vnr=1(aik  bkj) V i, j = 1,2......n. V = union of (OR)  = And For example : d11=(a11 b11) V(a12 b21) V ........(a1n Vbn1) If for any k, the kth element in the row for A and the kth element in the column for B are both 1 then dij=1; otherwise dij =0. Let us write AA =A(2), AA(x-1)=A(x) for any r=2,3........ the entry in the ith row and jth column of A(x) is 1 if there is at least one path of length r from Vi to Vj. The path matrix P is given by: P=AVA(2)VA(3)V...VA(n)=Vnk=VnRs1A(k) Warshall Algorithm Given the adjacency matrix A , this matrix produces the path matrix P. 1. [Initialization] PA 2 [Perform a pass] Repeat three step A for k=1(1)n 3 [Process Rows] Repeat step 4 for i=1(1) n. 4 [Across column] Repeat for j=1(1)n Pijpij V(Vik ^ Pkj) 5. [Exit] Minimal Algorithm Given the adjacency matrix B in which the zero elements are replaced by infinity or by some large number, the matrix produced by the following algorithm shows the minimum length of paths between the nodes MIN is a function that selects the algebraic minimum of its two arguments. [1.] cB [2.] Repeat thru step 4 for k =1(1) n
  • 7. For More Visit: Https://www.ThesisScientist.com [3.] Repeat thru step 4 forj =1(1) n cij= MIN (cij, cik+ ckj) [5.] exit Example (Warshall) Suppose we have 3 vertices v 1v2 v3 V1 V2 V3 Adjacency matrix A = V1 0 1 0 V2 0 0 0 = p V3 1 1 1 V1 l V3 V2 l l V1 l V3 V2 l l I Iteration  R=1, i=1, j=1,2,3 for p(1) P11=P11V(P11 P11) =0V(00)=0 P12=P12V(P11 P12) =1V(01)=1 P13=P13V(P11 P13) =0V(00)=0  k=1, i=2, j=1,2,3 P21=P21V(P21^P22)=0 P22=P22V(P21^ P22)=0 P23 =0  k=1, i=3, j=1,2,3 P31=P31 V (P31^P31)=1 P32=P32 V (P31^P32)=1 p33=P33 V (P31 ^ P33) = 1 Hence,
  • 8. For More Visit: Https://www.ThesisScientist.com 0 1 0 Pv = 0 0 0 1 1 1 II Insertion for k=2 for p(2) i=1 j=1,2,3 P11=P11V(P12 ^ P21)=0 P12=P12V(P12 ^ P22)=0 P13=P13V(P12 ^ P23)= . . . . . . Similarly, we can calculate Matrix for k=3 and so on Adjacency List In this representation the n rows of the adjacency matrix are represented as n linked lists. There is one list for each vertex in G. The nodes in list i represent the vertices that are adjacent from vertex i. Each node has two fields, VERTEX and LINK. The vertex field contains the indices of the vertices adjacent to vertex i. Each node has a head node. Head nodes are sequential providing easy random access to the adjacency list for any particular vertex.
  • 9. For More Visit: Https://www.ThesisScientist.com Figure 6.5 Adjancency Multi-list In the adjacency list representation of an undirect graph each edge (Vi, Vj) is represented by two entries, one on the list for Vi and the other on the list for Vj. In some situations it is necessary to be able to determine the second entry for a particular edge and mark that edge as already having been examined. This can be accomplished easily if the adjacency lists are actually maintained as multilist (i.e., lists in which nodes may be shared among several lists). For each edge there will be exactly one node, but this node will be in two lists, i.e., the adjacency list for each of the two nodes it is incident to. The node structure will be: where M is a one bit mark field that may be used to indicate whether or not the edge has been examined. e.g., Graph M V1 V2 LINK 1 For V1 LINK 2 For V2
  • 10. For More Visit: Https://www.ThesisScientist.com The lists are : Vertex 1 : N1  N2  N3 Vertex 2 : N1  N4  N5 Vertex 3 : N2  N4  N6 Vertex 4 : N3  N5  N6 Figure 6.7 : Adjacency Multilist for the given Graph Traversal of a Graph l Depth first search l Breadth first search Depth First Search DFS algorithm is analogous to preorder traversal of a tree. Given an undirected graph g= (V,E) and a vertex V in V(G), we are interested in visiting all vertices in G that are reachable from (i.e. all vertices connected to V).
  • 11. For More Visit: Https://www.ThesisScientist.com DFS of an undirected graph precedes as follows: The start vertex C is visited Next an unvisited vertex w adjacent to V is selected and a depth first search initiated. (Adjacent means connected by an Arc from the search node.) Algorithm DFS (V) 1. Given an adjacent graph G=(V,E) with n vertices an array VISITED [N] initially set to zero this algorithm visits all vertices reachable from V and visited are global. VISITED (V) 1 2. Check for adjacent vertex W to V and call recursively for each vertex W adjacent to V do if (visited (W)=0) then call DFS(W) end 3. [exit] Breadh First Search Starting at vertex V and making is as visited BFS differs from DFS in that all unvisited vertices adjacent to V are visited next. Then unvisited vertices adjacent to these vertices are visited and so on. Algorithm BFS (V) 1. [A BFS of G is carried out beginning at vertex V. All vertices visited are marked as VISTED(I)=1. The graph G and array VISITED are global and VISITED is initialized to 0] VISITED (V) 1 initialize Q to be empty [Q is queue] 2. [Perform Iterations] loop for all vertices W adjacent to V do if VISITED (W) =0 then [Add (W,Q); VISITED (W) 1] end if Q is empty then return; DELETE (V,Q) forever
  • 12. For More Visit: Https://www.ThesisScientist.com <exit> GRAPH G V1 V2 V3 V4 V7 V8 V5 V6 V1V1 V2V2 V3V3 V4V4 V7V7 V8V8 V5V5 V6V6 Traversing by DFS : V1, V2 , V4, V8, V5, V3, V6, V7 Traversing by BFS :V1, V2, V3, V4, V5, V6, V7, V8 Analysis of Algorithms 1. DFS If G is represented by its adjacency matrix, then the time to determine all vertices adjacent to V is O(N). Since at most n vertices are visited, the total time is O(N2 ). 2. BFS Each vertex visited gets into the queue exactly once, so the loop.....forever is iterated at most n times. If an adjacency matrix is used then the for loop takes O(N) times for each vertex visited. The total time is therefore O(N2 ). Weighted Graphs A graph in which weights are assigned to every edge is called a Weighted graph. Shortest Path in Weighted Graphs Let G= (v,e,w) be a weighted graph where w is weight (in terms of time or cost) assigned to that edge. The length of a path in G is defined as the sum of lengths of the edges in the path. Dijkstra's Shortest Path Algorithm
  • 13. For More Visit: Https://www.ThesisScientist.com Let TV with AT (A= starting node). Let P be the subset of vertices V-T, let L(T) denote the length of a shortest path among all paths from A to T that does not include any other vertex in T. We call L(T) the index of T with respect to P. Let X be a vertex in T. Let P' be PU{X} and T' be T-{X}. Let L'(T) denote the index of a vertex T inT' with respect to P'. We claim that L'(T) =Min[L(T), L(X), L(W,T)]-----------(i) Algorithm 1. Initially let P= [a] and T =V-[a] , for every vertex t in t, let l(t)= w (A,t). 2. Select the vertex in T that has the smallest index with respect to P, let it denote it vertex x. 3. If x is the vertex we wish to reach from A stop. If not let P'=PU{x} and T=T-{x}. For every vertex t in T compute its index with respect to P' according to 1. 4. Repeat steps 2 and 3 using P' as P and T' as T. 5. Stop. Example Find the shortest path from A to Z for the given graph: 1. B D C E A Z 1 2 4 7 5 1 2 3 6 BB DD CC EE AA ZZ 1 2 4 7 5 1 2 3 6 Solution: Initially P={A} and T={B,C,E,D,Z} The lengths of different vertices (with respect to P) are : L(B)=1 , L(C)=4, L(D)=L(E)= L(Z)=  l so L(B)= 1 is the shortest value Now let P={A,B} and T={C,D,E,Z}
  • 14. For More Visit: Https://www.ThesisScientist.com so, L(C)=3, L(D)=8, L(E)=6, L(Z)=  l So L(C) =3, is the shortest value. Now P={A,B, C} and T'={D,E,Z} L'(D)= Min{8,}=8. L'(E)= Min{6,3+1}=4 L'(Z) = Min {,3+}=  Successive observations are shown in following figures: Thus the shortest path from A to Z is (A, B, C, E, D, Z) of length 9. B D C E A Z DD ZZ  2.  4 (a) B D C E A Z DD ZZ  2.  4 (a)
  • 15. For More Visit: Https://www.ThesisScientist.com Spanning Trees It is a tree obtained from a Graph, which covers all its vertices. Minimal Spanning Tree It is a tree from the set of spanning trees, which has minimum weight. There are two methods to find minimum spanning tree. l Prim's Method l Kruskal's method 1. Prim's Method Draw n isolated vertices and label them as V1,V2.....Vn. Tabulate the given weights of the edges of G in an nxn table. Set the weights of the non-existing edges as very large () l l ll l l 17 8 11 V4 10V5 16 V1 V2 V6 V3 9 7 7 19.5 9.512 l l ll l l 17 8 11 V4 10V5 16 V1 V2 V6 V3 9 7 7 19.5 9.512 V V2 V3 V4 V5 V6 V1 - 10 16 11 10 17 V2 10 - 9.5   19.5 V3 16 9.5 - 7  12 V4 11  7 - 8 7 V5 10   8 - 9 V6 17 19.5 12 7 9 -
  • 16. For More Visit: Https://www.ThesisScientist.com Start from vertex V1 and connect it to its nearest neighbor say Vk. Now consider V1 and Vk as one subgraph and connect this subgraph to its closest neighbor (i.e. to a vertex other than V1 and Vk that has the smallest entry among all entries in rows 1 and k.) 2. Kruskal's Method In this approach Minimum cost spanning tree T is built edge by edge. Edges are considered for inclusion in T in ascending order. An edge is included in T if it doesn't form a cycle with edges already in T. Since G is connected and has n>0 vertices exactly (n-1) edges will be selected for inclusion in T. 1 5 6 2 4 3 16 21 11 33 14 18 19 6 5 10 11 55 66 22 44 33 16 21 11 33 14 18 19 6 5 10 Edge Cost Action Resulting Tree .... ...... ......... ....................... (2,3) 5 Accept (2,4) 6 Accept (3,4) 10 Reject " (2,6) 11 Accept (4,6) 14 Reject " (1,2) 16 Accept (4,5) 18 Accept 1 2 3 4 5 6 1 3 4 5 62 1 3 5 62 4 11 22 33 44 55 66 11 33 44 55 6622 11 33 55 6622 44 1 5 43 6 211 55 4433 66 22 5 43 6 21 55 4433 66 2211 43 6 21 5 4433 66 2211 55