SlideShare a Scribd company logo
Design & Analysis of Algorithms
Lecture#09
Graph
Lecture Contents
Graph
Graph Terminologies
Graph Representations (Adjacency Matrix, Adjacency Link List)
Graph Traversals (Depth First, Breadth First)
Spanning Tree
Minimum Spanning Tree
 Kruskalls’ Algorithm
 Prim’s Algorithm
Shortest Path
 Dijkstra’s Algorithm
 Bellman Ford Algorithm
 A* Algorithm
Graph
A graph G (V, X) consists of two sets V & X. V is a set of
vertices & X is a set of Edges
Every edge e ϵ X joins two vertices in V
Graph G = (V, X)
where V = Set of vertices
AND X = set of edges
AND X  V x V
Example:
G = (V, X)
V = {A, B, C, D, E, F}
X = {(A,B), (A,C), (B,D), (D,E), (D,F), (C,E), (E,F), (F,C)}
Directed Graph (Digraph)
A directed graph is a graph in which all edges are directed. Directed
graph is also called a digraph.
G = (V, E)
V = {A, B, C, D, F, G}
E = {(A,B), (A,C), (B,D), (D,E), (D,F), (C,E), (E,F), (F,C)}
Undirected Graph
A undirected graph is a graph in which all edges are bidirectional.
In an undirected graph G(V,E),
∀e ϵ E
e1 (u, v) = e2 (u, v)
Connected Graph
A graph is connected if there is path between every two nodes of
that graph.
Complete Graph
A graph is complete if there is edge between every two nodes of that
graph.
Total number of edges in complete graph are given as:
𝑇𝑜𝑡𝑎𝑙 𝐸𝑑𝑔𝑒𝑠 =
𝑛(𝑛 − 1)
2
Degree, In Degree, Out Degree
Degree:
Number of edges connecting a vertex is called the
degree of node.
Degree of vertex A is 6
In Degree:
Number of edges pointing into a vertex is called its in
degree
In Degree of vertex A is 2
Out Degree:
Number of edges going out of a vertex is called its out
degree
Out Degree of vertex A is 4
Adjacency
Two nodes are said to be adjacent if they are connected through an edge.
In the example below nodes B&C, C&D, D&E are adjacent to each other.
Adjacent Nodes
Weighted Graph
A graph in which every edge has some weight (numeric
value) associated with it.
It refers to the effort while going from one vertex to other
using this edge Weighted Graph
Unweighted Graph
A graph having no weight value associated with
any of its edge is called an unweighted graph
Unweighted Graph
Reachable Node
A node is reachable from another node if there exists a path between them.
Path exists between A & E
Multigraph, Pseudo Graph
Multigraph
A graph is said to be multigraph if it allows more than
one paths between two nodes
Pseudo Graph
A graph is pseudo graph if it allows if it allows self
loops
Multigraph
Pseudo Graph
Reachable Node
A node is reachable from another node if
there exists a path between them.
For given graph paths exist between:
A & B
A & D
A & F
B & F
C & F
Path exists between A & E
Path
A path of length k is sequence of v1, v2, v3, …., vk of vertices such that (vi, vi+1) for i
= 0, 1, 2, …, k-1 is an edge of graph.
1. ABCD is a path
2. ABD is not a path
Cycle
A cycle is a path starting and ending at same vertex
ABCA makes a cycle in this graph
Hamiltonian Cycle
A Hamiltonian Cycle is a cycle in an undirected graph which visits every vertex
of graph and also returns to starting vertex.
Hamiltonian Cycle:
A, B, C, D, E, F, G, H, A
Eulerian Cycle
An Eulerian Cycle of a connected directed / undirected graph is a cycle that
traverses each vertex of a graph exactly once. There may be one vertex that is
visited more than once.
Eulerian Cycle:
A, B, C, D, E, F, C, G back to A
Subgraph
A subgraph H of graph G is a graph that has its vertices and edges as
subsets of vertices and edges of G respectively.
Graph G
V = {A, B, C, D, E, F, G}
Edges={(A,B), (A,G), (B,C), (B, G), (C,D), (C,F), (C,G), (D,E),
(D,F), (E,F)}
Subgraph H
V = {A, B, C, G}
Edges={(A,B), (A,G), (B,C), (B, G), (C,G)}
Tree
A connected graph without any cycles is call a tree graph or simply a tree.
For a tree graph, there is a unique path between every two nodes of the graph
Tree
Graph Representation
Graphs are represented through two different ways:
1. Adjacency Matrix
2. Adjacency List
Graph Adjacency Matrix Representation
Say a graph has V={1,2,3,…,n} vertices then graph is represented by a
NXN matrix A such that:
A[i, j] = 1 if there is edge between nodes i & j
= 0 otherwise
Graph G
Graph G 1 2 3 4
1 0 0 1 0
2 0 0 1 1
3 1 1 0 1
4 0 1 1 0
Space Complexity: ϴ|V2|
Graph Adjacency Matrix Representation
Adjacency matrix is dense representation i.e. too much space required for large
number of vertices
Can be very efficient for small graphs
Graph Adjacency List Representation
For each vertex, a list of adjacent vertices (neighbors) is
maintained
For the given graph:
Adj[1] = {3}
Adj[2]={3, 4}
Adj[3]={1, 2, 4}
Adj[4]={2, 3}
A possible variation can be to store the list of incoming edges
instead of outgoing edges
Graph G
Graph Adjacency List Representation
If a graph is directed then sum of lengths of all adjacency lists is equal to the
number of edges in graph
If the graph is undirected then this number is doubled
Graph G
Adjacency List for G
Graph Traversals
Graphs are traversed using two different methods:
1. Breadth First Traversal
2. Depth First Traversal
A Typical Graph Traversal
For a connected graph, pick one node as root node and visit all nodes of the
graph in some order
Starting from root we iterate for each node of the graph
During every iteration we visit the node and capture the neighboring nodes of
node in hand
Keep repeating until all nodes are visited
For graphs with disconnected nodes, we may need to visit subgraphs
containing all nodes disconnected with root node separately
Spanning Tree (ST)
“A spanning tree is a subset of Graph G, which has all the vertices covered
with minimum possible number of edges”
A spanning tree can contain no cycle
A spanning tree cannot be disconnected
A graph can have multiple spanning trees
Spanning tree T1
Graph G
Spanning tree T2
Spanning Tree (ST)
“A spanning tree is a subset of Graph G, which has all the vertices
covered with minimum possible number of edges”
Number of vertices for all spanning trees of a graph are same
Number of edges for all spanning trees of a graph are same
All spanning trees form a minimally connected graph i.e. one
takes away one edge from ST and it is no more a spanning tree
Adding one edge to ST will introduce a cycle i.e. ST is maximally
acyclic
Graph G
Spanning tree T1
Spanning Tree (ST) … Applications
Network Planning & Design
Network Routing Protocols
Cluster Analysis
Approximation Algorithms for NP-hard Problems
Image Registration & Segmentation Algorithms
Minimax Process Control
etc
Minimum Spanning Tree (MST)
“Minimum spanning tree is subset of edges of a connected,
weighted undirected graph that connects all vertices
together and bears the minimum possible total edge
weight”
Minimum Spanning Tree is also called Minimum Weight
Spanning Tree
MST is a tree so it does not contain any cycle
Graph K
Spanning Tree T1
Spanning Tree T2
Ad

More Related Content

Similar to Graph terminology and algorithm and tree.pptx (20)

Graphs aktu notes computer networks.pptx
Graphs aktu notes computer networks.pptxGraphs aktu notes computer networks.pptx
Graphs aktu notes computer networks.pptx
TalhaKhan528682
 
Graphs.pptx
Graphs.pptxGraphs.pptx
Graphs.pptx
satvikkushwaha1
 
Graph_data_structure_information_engineering.pptx
Graph_data_structure_information_engineering.pptxGraph_data_structure_information_engineering.pptx
Graph_data_structure_information_engineering.pptx
sahilpawar2426
 
Graph ASS DBATU.pptx
Graph ASS DBATU.pptxGraph ASS DBATU.pptx
Graph ASS DBATU.pptx
ARVIND SARDAR
 
graph ASS (1).ppt
graph ASS (1).pptgraph ASS (1).ppt
graph ASS (1).ppt
ARVIND SARDAR
 
graphass1-23022111180722548-1ba6b00a.ppt
graphass1-23022111180722548-1ba6b00a.pptgraphass1-23022111180722548-1ba6b00a.ppt
graphass1-23022111180722548-1ba6b00a.ppt
ssuser7b9bda1
 
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Mohanlal Sukhadia University (MLSU)
 
Data Structure of computer science and technology
Data Structure of computer science and technologyData Structure of computer science and technology
Data Structure of computer science and technology
bhaskarsai499
 
Spanningtreesppt
SpanningtreespptSpanningtreesppt
Spanningtreesppt
Jyoshna Cec Cse Staf bejjam
 
ON ALGORITHMIC PROBLEMS CONCERNING GRAPHS OF HIGHER DEGREE OF SYMMETRY
ON ALGORITHMIC PROBLEMS CONCERNING GRAPHS OF HIGHER DEGREE OF SYMMETRYON ALGORITHMIC PROBLEMS CONCERNING GRAPHS OF HIGHER DEGREE OF SYMMETRY
ON ALGORITHMIC PROBLEMS CONCERNING GRAPHS OF HIGHER DEGREE OF SYMMETRY
Fransiskeran
 
Slides Chapter10.1 10.2
Slides Chapter10.1 10.2Slides Chapter10.1 10.2
Slides Chapter10.1 10.2
showslidedump
 
graph_theory_1-11.pdf___________________
graph_theory_1-11.pdf___________________graph_theory_1-11.pdf___________________
graph_theory_1-11.pdf___________________
ssuser1989da
 
Unit 3 graph chapter6
Unit 3  graph chapter6Unit 3  graph chapter6
Unit 3 graph chapter6
DrkhanchanaR
 
NON-LINEAR DATA STRUCTURE-Graphs.pptx
NON-LINEAR DATA STRUCTURE-Graphs.pptxNON-LINEAR DATA STRUCTURE-Graphs.pptx
NON-LINEAR DATA STRUCTURE-Graphs.pptx
Rajitha Reddy Alugati
 
Graph Introduction.ppt
Graph Introduction.pptGraph Introduction.ppt
Graph Introduction.ppt
Faruk Hossen
 
GRAPH THEORY - Basic definition with examples
GRAPH THEORY - Basic definition with examplesGRAPH THEORY - Basic definition with examples
GRAPH THEORY - Basic definition with examples
Gayathri M
 
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjteUnit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
pournima055
 
Introduction to Graph Theory
Introduction to Graph TheoryIntroduction to Graph Theory
Introduction to Graph Theory
Premsankar Chakkingal
 
Graph Theory
Graph TheoryGraph Theory
Graph Theory
Rashmi Bhat
 
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
 
Graphs aktu notes computer networks.pptx
Graphs aktu notes computer networks.pptxGraphs aktu notes computer networks.pptx
Graphs aktu notes computer networks.pptx
TalhaKhan528682
 
Graph_data_structure_information_engineering.pptx
Graph_data_structure_information_engineering.pptxGraph_data_structure_information_engineering.pptx
Graph_data_structure_information_engineering.pptx
sahilpawar2426
 
Graph ASS DBATU.pptx
Graph ASS DBATU.pptxGraph ASS DBATU.pptx
Graph ASS DBATU.pptx
ARVIND SARDAR
 
graphass1-23022111180722548-1ba6b00a.ppt
graphass1-23022111180722548-1ba6b00a.pptgraphass1-23022111180722548-1ba6b00a.ppt
graphass1-23022111180722548-1ba6b00a.ppt
ssuser7b9bda1
 
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Mohanlal Sukhadia University (MLSU)
 
Data Structure of computer science and technology
Data Structure of computer science and technologyData Structure of computer science and technology
Data Structure of computer science and technology
bhaskarsai499
 
ON ALGORITHMIC PROBLEMS CONCERNING GRAPHS OF HIGHER DEGREE OF SYMMETRY
ON ALGORITHMIC PROBLEMS CONCERNING GRAPHS OF HIGHER DEGREE OF SYMMETRYON ALGORITHMIC PROBLEMS CONCERNING GRAPHS OF HIGHER DEGREE OF SYMMETRY
ON ALGORITHMIC PROBLEMS CONCERNING GRAPHS OF HIGHER DEGREE OF SYMMETRY
Fransiskeran
 
Slides Chapter10.1 10.2
Slides Chapter10.1 10.2Slides Chapter10.1 10.2
Slides Chapter10.1 10.2
showslidedump
 
graph_theory_1-11.pdf___________________
graph_theory_1-11.pdf___________________graph_theory_1-11.pdf___________________
graph_theory_1-11.pdf___________________
ssuser1989da
 
Unit 3 graph chapter6
Unit 3  graph chapter6Unit 3  graph chapter6
Unit 3 graph chapter6
DrkhanchanaR
 
NON-LINEAR DATA STRUCTURE-Graphs.pptx
NON-LINEAR DATA STRUCTURE-Graphs.pptxNON-LINEAR DATA STRUCTURE-Graphs.pptx
NON-LINEAR DATA STRUCTURE-Graphs.pptx
Rajitha Reddy Alugati
 
Graph Introduction.ppt
Graph Introduction.pptGraph Introduction.ppt
Graph Introduction.ppt
Faruk Hossen
 
GRAPH THEORY - Basic definition with examples
GRAPH THEORY - Basic definition with examplesGRAPH THEORY - Basic definition with examples
GRAPH THEORY - Basic definition with examples
Gayathri M
 
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjteUnit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
pournima055
 
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
 

Recently uploaded (20)

five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdffive-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
AdityaSharma944496
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
Mathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdfMathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdf
TalhaShahid49
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
Machine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptxMachine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptx
rajeswari89780
 
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdfMAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
ssuser562df4
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
Smart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineeringSmart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineering
rushikeshnavghare94
 
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
charlesdick1345
 
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E..."Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
Infopitaara
 
Raish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdfRaish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdf
RaishKhanji
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
DSP and MV the Color image processing.ppt
DSP and MV the  Color image processing.pptDSP and MV the  Color image processing.ppt
DSP and MV the Color image processing.ppt
HafizAhamed8
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)
samueljackson3773
 
Oil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdfOil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdf
M7md3li2
 
ELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdfELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdf
Shiju Jacob
 
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptxLidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
RishavKumar530754
 
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Journal of Soft Computing in Civil Engineering
 
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdffive-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
AdityaSharma944496
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
Mathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdfMathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdf
TalhaShahid49
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
Machine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptxMachine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptx
rajeswari89780
 
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdfMAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
ssuser562df4
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
Smart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineeringSmart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineering
rushikeshnavghare94
 
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
charlesdick1345
 
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E..."Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
Infopitaara
 
Raish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdfRaish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdf
RaishKhanji
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
DSP and MV the Color image processing.ppt
DSP and MV the  Color image processing.pptDSP and MV the  Color image processing.ppt
DSP and MV the Color image processing.ppt
HafizAhamed8
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)
samueljackson3773
 
Oil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdfOil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdf
M7md3li2
 
ELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdfELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdf
Shiju Jacob
 
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptxLidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
RishavKumar530754
 
Ad

Graph terminology and algorithm and tree.pptx

  • 1. Design & Analysis of Algorithms Lecture#09 Graph
  • 2. Lecture Contents Graph Graph Terminologies Graph Representations (Adjacency Matrix, Adjacency Link List) Graph Traversals (Depth First, Breadth First) Spanning Tree Minimum Spanning Tree  Kruskalls’ Algorithm  Prim’s Algorithm Shortest Path  Dijkstra’s Algorithm  Bellman Ford Algorithm  A* Algorithm
  • 3. Graph A graph G (V, X) consists of two sets V & X. V is a set of vertices & X is a set of Edges Every edge e ϵ X joins two vertices in V Graph G = (V, X) where V = Set of vertices AND X = set of edges AND X  V x V Example: G = (V, X) V = {A, B, C, D, E, F} X = {(A,B), (A,C), (B,D), (D,E), (D,F), (C,E), (E,F), (F,C)}
  • 4. Directed Graph (Digraph) A directed graph is a graph in which all edges are directed. Directed graph is also called a digraph. G = (V, E) V = {A, B, C, D, F, G} E = {(A,B), (A,C), (B,D), (D,E), (D,F), (C,E), (E,F), (F,C)}
  • 5. Undirected Graph A undirected graph is a graph in which all edges are bidirectional. In an undirected graph G(V,E), ∀e ϵ E e1 (u, v) = e2 (u, v)
  • 6. Connected Graph A graph is connected if there is path between every two nodes of that graph.
  • 7. Complete Graph A graph is complete if there is edge between every two nodes of that graph. Total number of edges in complete graph are given as: 𝑇𝑜𝑡𝑎𝑙 𝐸𝑑𝑔𝑒𝑠 = 𝑛(𝑛 − 1) 2
  • 8. Degree, In Degree, Out Degree Degree: Number of edges connecting a vertex is called the degree of node. Degree of vertex A is 6 In Degree: Number of edges pointing into a vertex is called its in degree In Degree of vertex A is 2 Out Degree: Number of edges going out of a vertex is called its out degree Out Degree of vertex A is 4
  • 9. Adjacency Two nodes are said to be adjacent if they are connected through an edge. In the example below nodes B&C, C&D, D&E are adjacent to each other. Adjacent Nodes
  • 10. Weighted Graph A graph in which every edge has some weight (numeric value) associated with it. It refers to the effort while going from one vertex to other using this edge Weighted Graph
  • 11. Unweighted Graph A graph having no weight value associated with any of its edge is called an unweighted graph Unweighted Graph
  • 12. Reachable Node A node is reachable from another node if there exists a path between them. Path exists between A & E
  • 13. Multigraph, Pseudo Graph Multigraph A graph is said to be multigraph if it allows more than one paths between two nodes Pseudo Graph A graph is pseudo graph if it allows if it allows self loops Multigraph Pseudo Graph
  • 14. Reachable Node A node is reachable from another node if there exists a path between them. For given graph paths exist between: A & B A & D A & F B & F C & F Path exists between A & E
  • 15. Path A path of length k is sequence of v1, v2, v3, …., vk of vertices such that (vi, vi+1) for i = 0, 1, 2, …, k-1 is an edge of graph. 1. ABCD is a path 2. ABD is not a path
  • 16. Cycle A cycle is a path starting and ending at same vertex ABCA makes a cycle in this graph
  • 17. Hamiltonian Cycle A Hamiltonian Cycle is a cycle in an undirected graph which visits every vertex of graph and also returns to starting vertex. Hamiltonian Cycle: A, B, C, D, E, F, G, H, A
  • 18. Eulerian Cycle An Eulerian Cycle of a connected directed / undirected graph is a cycle that traverses each vertex of a graph exactly once. There may be one vertex that is visited more than once. Eulerian Cycle: A, B, C, D, E, F, C, G back to A
  • 19. Subgraph A subgraph H of graph G is a graph that has its vertices and edges as subsets of vertices and edges of G respectively. Graph G V = {A, B, C, D, E, F, G} Edges={(A,B), (A,G), (B,C), (B, G), (C,D), (C,F), (C,G), (D,E), (D,F), (E,F)} Subgraph H V = {A, B, C, G} Edges={(A,B), (A,G), (B,C), (B, G), (C,G)}
  • 20. Tree A connected graph without any cycles is call a tree graph or simply a tree. For a tree graph, there is a unique path between every two nodes of the graph Tree
  • 21. Graph Representation Graphs are represented through two different ways: 1. Adjacency Matrix 2. Adjacency List
  • 22. Graph Adjacency Matrix Representation Say a graph has V={1,2,3,…,n} vertices then graph is represented by a NXN matrix A such that: A[i, j] = 1 if there is edge between nodes i & j = 0 otherwise Graph G Graph G 1 2 3 4 1 0 0 1 0 2 0 0 1 1 3 1 1 0 1 4 0 1 1 0 Space Complexity: ϴ|V2|
  • 23. Graph Adjacency Matrix Representation Adjacency matrix is dense representation i.e. too much space required for large number of vertices Can be very efficient for small graphs
  • 24. Graph Adjacency List Representation For each vertex, a list of adjacent vertices (neighbors) is maintained For the given graph: Adj[1] = {3} Adj[2]={3, 4} Adj[3]={1, 2, 4} Adj[4]={2, 3} A possible variation can be to store the list of incoming edges instead of outgoing edges Graph G
  • 25. Graph Adjacency List Representation If a graph is directed then sum of lengths of all adjacency lists is equal to the number of edges in graph If the graph is undirected then this number is doubled Graph G Adjacency List for G
  • 26. Graph Traversals Graphs are traversed using two different methods: 1. Breadth First Traversal 2. Depth First Traversal
  • 27. A Typical Graph Traversal For a connected graph, pick one node as root node and visit all nodes of the graph in some order Starting from root we iterate for each node of the graph During every iteration we visit the node and capture the neighboring nodes of node in hand Keep repeating until all nodes are visited For graphs with disconnected nodes, we may need to visit subgraphs containing all nodes disconnected with root node separately
  • 28. Spanning Tree (ST) “A spanning tree is a subset of Graph G, which has all the vertices covered with minimum possible number of edges” A spanning tree can contain no cycle A spanning tree cannot be disconnected A graph can have multiple spanning trees Spanning tree T1 Graph G Spanning tree T2
  • 29. Spanning Tree (ST) “A spanning tree is a subset of Graph G, which has all the vertices covered with minimum possible number of edges” Number of vertices for all spanning trees of a graph are same Number of edges for all spanning trees of a graph are same All spanning trees form a minimally connected graph i.e. one takes away one edge from ST and it is no more a spanning tree Adding one edge to ST will introduce a cycle i.e. ST is maximally acyclic Graph G Spanning tree T1
  • 30. Spanning Tree (ST) … Applications Network Planning & Design Network Routing Protocols Cluster Analysis Approximation Algorithms for NP-hard Problems Image Registration & Segmentation Algorithms Minimax Process Control etc
  • 31. Minimum Spanning Tree (MST) “Minimum spanning tree is subset of edges of a connected, weighted undirected graph that connects all vertices together and bears the minimum possible total edge weight” Minimum Spanning Tree is also called Minimum Weight Spanning Tree MST is a tree so it does not contain any cycle Graph K Spanning Tree T1 Spanning Tree T2