SlideShare a Scribd company logo
1 of 31
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

More Related Content

Similar to Graph terminology and algorithm and tree.pptx

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)
 
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 SYMMETRYFransiskeran
 
Slides Chapter10.1 10.2
Slides Chapter10.1 10.2Slides Chapter10.1 10.2
Slides Chapter10.1 10.2showslidedump
 
Unit 3 graph chapter6
Unit 3  graph chapter6Unit 3  graph chapter6
Unit 3 graph chapter6DrkhanchanaR
 
NON-LINEAR DATA STRUCTURE-Graphs.pptx
NON-LINEAR DATA STRUCTURE-Graphs.pptxNON-LINEAR DATA STRUCTURE-Graphs.pptx
NON-LINEAR DATA STRUCTURE-Graphs.pptxRajitha Reddy Alugati
 
Graph Introduction.ppt
Graph Introduction.pptGraph Introduction.ppt
Graph Introduction.pptFaruk Hossen
 
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjteUnit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjtepournima055
 
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 symmetrygraphhoc
 
VANU no sql ppt.pptx
VANU no sql ppt.pptxVANU no sql ppt.pptx
VANU no sql ppt.pptxMJeyavarthini
 
Unit-6 Graph.ppsx ppt
Unit-6 Graph.ppsx                                       pptUnit-6 Graph.ppsx                                       ppt
Unit-6 Graph.ppsx pptDhruvilSTATUS
 
Graph Theory,Graph Terminologies,Planar Graph & Graph Colouring
Graph Theory,Graph Terminologies,Planar Graph & Graph ColouringGraph Theory,Graph Terminologies,Planar Graph & Graph Colouring
Graph Theory,Graph Terminologies,Planar Graph & Graph ColouringSaurabh Kaushik
 
graphs presentation .pptx
graphs presentation .pptxgraphs presentation .pptx
graphs presentation .pptxssuser800a48
 

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

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)
 
Spanningtreesppt
SpanningtreespptSpanningtreesppt
Spanningtreesppt
 
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
 
Slides Chapter10.1 10.2
Slides Chapter10.1 10.2Slides Chapter10.1 10.2
Slides Chapter10.1 10.2
 
Unit 3 graph chapter6
Unit 3  graph chapter6Unit 3  graph chapter6
Unit 3 graph chapter6
 
NON-LINEAR DATA STRUCTURE-Graphs.pptx
NON-LINEAR DATA STRUCTURE-Graphs.pptxNON-LINEAR DATA STRUCTURE-Graphs.pptx
NON-LINEAR DATA STRUCTURE-Graphs.pptx
 
Graph Introduction.ppt
Graph Introduction.pptGraph Introduction.ppt
Graph Introduction.ppt
 
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjteUnit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
 
Introduction to Graph Theory
Introduction to Graph TheoryIntroduction to Graph Theory
Introduction to Graph Theory
 
Graph Theory
Graph TheoryGraph Theory
Graph Theory
 
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
 
Vanmathy no sql
Vanmathy no sql Vanmathy no sql
Vanmathy no sql
 
VANU no sql ppt.pptx
VANU no sql ppt.pptxVANU no sql ppt.pptx
VANU no sql ppt.pptx
 
Unit-6 Graph.ppsx ppt
Unit-6 Graph.ppsx                                       pptUnit-6 Graph.ppsx                                       ppt
Unit-6 Graph.ppsx ppt
 
graph theory
graph theorygraph theory
graph theory
 
Graph therory
Graph theroryGraph therory
Graph therory
 
Graph Theory,Graph Terminologies,Planar Graph & Graph Colouring
Graph Theory,Graph Terminologies,Planar Graph & Graph ColouringGraph Theory,Graph Terminologies,Planar Graph & Graph Colouring
Graph Theory,Graph Terminologies,Planar Graph & Graph Colouring
 
graphs presentation .pptx
graphs presentation .pptxgraphs presentation .pptx
graphs presentation .pptx
 
DIGITAL TEXT BOOK
DIGITAL TEXT BOOKDIGITAL TEXT BOOK
DIGITAL TEXT BOOK
 
Graphs
GraphsGraphs
Graphs
 

Recently uploaded

GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 

Recently uploaded (20)

GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 

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