SlideShare a Scribd company logo
VELAMMAL ENGINEERING COLLEGE
An Autonomous Institution, Affiliated to Anna University
Chennai, & Approved by AICTE Delhi
Online Faculty Development Program on
Data Structures (CS8391)
From 25th – 29th May 2020
Organized by
Department of Computer Science and
Engineering
In Association with Computer Society of
India
APPLICATION OF GRAPH
&
BICONNECTED GRAPH
DR.S.GUNASUNDARI
ASSOCIATE PROFESSOR
VELAMMAL ENGINEERING COLLEGE
OUTLINE
• GRAPH APPLICATIONS
– MINIMUM SPANNING TREE
• PRIMS ALGORITHM
• KRUSKAL ALGORITHM
– SHORTEST PATH
• SINGLE SOURCE- DIJIKSTRA ALGORITHM
• DFS APPLICATION
– BICONNECTED GRAPH
– EULER CIRCUIT
5/29/2020 Dept of CSE/VEC 3
APPLICATION OF GRAPH
• Graphs are widely used to model any situation
– where entities or things are related to each other in
pairs.
– For example, the following information can be
represented by graphs:
– Transportation networks
» In which nodes are airports, ports, etc.
» The edges can be airline flights, shipping
routes, etc.
– In circuit networks
» points of connection are drawn as vertices
» component wires become the edges of the
graph.
5/29/2020 Dept of CSE/VEC 4
Application of Graphs
Google maps
– Intersection of two(or more) roads are considered to be a vertex
– Road connecting two vertices is considered to be an edge
– Navigation system is based on the algorithm to calculate the shortest path
between two vertices.
Facebook
– Users are considered to be the vertices
– If they are friends then there is an edge running between them.
– undirected graph.
World Wide Web
– web pages are considered to be the vertices.
– There is an edge from a page u to other page v if there is a link of page v on
page u
– Directed graph.
Operating System
– Resource Allocation Graph
– Each process and resources are considered to be vertices.
– Edges are drawn from resources to the allocated process
5/29/2020 Dept of CSE/VEC 5
Minimum Spanning Trees
• A spanning tree of a connected, undirected graph G
– Sub-graph of G which is a tree that connects all the
vertices together.
• A graph G can have many different spanning trees.
• Minimum Spanning Tree
– Spanning tree of the smallest weight
– weight of a tree is defined as the sum of the weights on
all its edges.
• Minimum Spanning Tree problem
– Finding a minimum spanning tree for a given weighted
connected graph
5/29/2020 Dept of CSE/VEC 6
Unweighted graph Example
5/29/2020 Dept of CSE/VEC 7
Weighted graph - example
5/29/2020 Dept of CSE/VEC 8
MST - Application
• MSTs are used to find airline routes.
– Vertices in the graph denote cities
– Edges represent the routes between these cities.
– MSTs are used to optimize airline routes by finding the
least costly path with no cycles.
• MSTs are also used to find the cheapest way to connect
terminals, such as cities, electronic components or
computers via roads, airlines, railways, wires or telephone
lines.
• MSTs are applied in routing algorithms for finding the most
efficient path.
5/29/2020 Dept of CSE/VEC 9
Prim’s Algorithm
• Prim’s algorithm is a greedy algorithm
• Used to form a minimum spanning tree
for a connected weighted undirected
graph.
• Builds a tree that includes every vertex
and a subset of the edges in such a way
that the total weight of all the edges in
the tree is minimized.
• Tree vertices Vertices that are a part of
the minimum spanning tree T.
• Fringe vertices Vertices that are
currently not a part of T, but are adjacent
to some tree vertex.
• Unseen vertices Vertices that are
neither tree vertices nor fringe vertices
fall under this category.
5/29/2020 Dept of CSE/VEC 10
ALGORITHM
//Input: A weighted connected graph G = (V, E)
//Output: T , the set of edges composing a minimum
spanning tree of G
Step 1: Select a starting vertex
Step 2: Repeat Steps 3 and 4 until there are fringe
vertices
Step 3: Select an edge e connecting the tree vertex
and fringe vertex that has minimum weight
Step 4: Add the selected edge and the vertex to the
minimum spanning tree T
Step 5: EXIT
5/29/2020 Dept of CSE/VEC 11
Example 1
Step-01: Step-02:
Step-03:
Step-04
5/29/2020 Dept of CSE/VEC 12
Example 1
contd..
Step-05: Step-06:
5/29/2020 Dept of CSE/VEC 13
Example 2
Attach two labels to a vertex
• the name of the nearest tree vertex,
• the weight of the corresponding edge.
select a as starting vertex
a(-, -)
b(a, 3)
c(-, ∞)
5/29/2020 Dept of CSE/VEC 14
5/29/2020 Dept of CSE/VEC 15
5/29/2020 Dept of CSE/VEC 16
5/29/2020 Dept of CSE/VEC 17
Example 3
5/29/2020 Dept of CSE/VEC 18
Pseudo code
5/29/2020 Dept of CSE/VEC 19
T = ∅;
U = { 1 };
while (U ≠ V)
let (u, v) be the lowest cost edge such that
u ∈ U and v ∈ V - U;
T = T ∪ {(u, v)}
U = U ∪ {v}
KRUSKAL ALGORITHM
Step-01:
Sort all the edges from low weight to high weight.
Step-02:
Take the edge with the lowest weight and use it to connect the
vertices of graph.
If adding an edge creates a cycle, then reject that edge and go
for the next least weight edge.
Step-03:
Keep adding edges until all the vertices are connected and a
Minimum Spanning Tree (MST) is obtained.
5/29/2020 Dept of CSE/VEC 20
Example 1 Step-01
Step-02 Step-03
5/29/2020 Dept of CSE/VEC 21
Step-04
Step-05
Step-06
Step-07
5/29/2020 Dept of CSE/VEC 22
EXAMPLE 2
5/29/2020 Dept of CSE/VEC 23
5/29/2020 Dept of CSE/VEC 24
5/29/2020 Dept of CSE/VEC 25
Pseudo code
5/29/2020 Dept of CSE/VEC 26
Prims Vs Kruskal
Kruskal’s Algorithm is preferred when
– The graph is sparse.
– There are less number of edges in the graph
– The edges are already sorted or can be sorted in
linear time.
Prim’s Algorithm is preferred when
– The graph is dense.
– There are large number of edges in the graph
5/29/2020 Dept of CSE/VEC 27
Time Complexity
Prims
• If a graph is represented by its weight matrix, then the
running time of Prim’s algorithm is , where n = |V|
• Let graph is represented by its adjacency lists
• Running time of Prim’s algorithm is in O(m log n),
– where m = |E|, n = |V|
Kruskal
O(ElogV)
5/29/2020 Dept of CSE/VEC 28
DIJIKSTRA‘S ALGORITHM
• Single-source shortest-path problem
• For a given vertex called the source in a weighted
connected graph
– Find shortest paths to all its other vertices.
– The best-known algorithm for the single-source
shortest-paths problem is called Dijkstra’s
algorithm.
• First, it finds the shortest path from the source to a
vertex nearest to it, then to a second nearest, and so on
5/29/2020 Dept of CSE/VEC 29
DIJIKSTRA ALGORITHM
contd..
 Create a set Tree Vertices that keeps track of vertices included in
shortest path tree
 Initially, this set is empty.
 Assign a distance value to all vertices in the input graph.
 Initialize all distance values as INFINITE.
 Assign distance value as 0 for the source vertex so that it is
picked first.
 While Tree Vertex doesn’t include all vertices
 Pick a vertex u which is not there in Tree Vertex and has
minimum distance value.
 Include u to Tree Vertex.
 Update distance value of all adjacent vertices of u.
For every adjacent vertex v
 if sum of distance value of u (from source) and weight of
edge u-v, is less than the distance value of v
then update the distance value of v.
5/29/2020 Dept of CSE/VEC 30
DIJIKSTRA EXAMPLE
5/29/2020 Dept of CSE/VEC 31
5/29/2020 Dept of CSE/VEC 32
from a to b : a - b of length 3
from a to d : a - b - d of length 5
from a to c : a - b - c of length 7
from a to e : a - b - d - e of length 9
• Dijikstra’s algorithm does not always work correctly
– If the edge weight is negative.
• The algorithm that is used to solve the negative
weighted, single-source shortest-paths path problem
– Bellman-Ford’s algorithm (using dynamic
programming).
• Time Analysis
– Adjacency Matrix Representation
• O(V2).
– Adjacency list
• O(ElogV)
5/29/2020 Dept of CSE/VEC 33
Biconnected Graph
• A graph with no articulation point
• If and only if any vertex is deleted, the graph remains
connected
5/29/2020 Dept of CSE/VEC 34
5/29/2020 Dept of CSE/VEC 35
First, starting at any vertex, we perform a depth-
first search and number the nodes as they are
visited.
For each vertex, v, call this preorder number
Num(v)
Low(v) is the minimum of
1. Num(v)
2. the lowest Num(w) among all back edges
(v, w)
3. the lowest Low(w) among all tree edges (v,
w)
Step 1: Find DFN
Step 2: Do Post order Traversal
and Find low value
Low(F)=min{Num(F),Num(D),-)
=min{6,4,-}=4
Low(E)=min{Num(E),-,Low(F)}
=min{5,-,4}=4
Low(D)=min{Num(D),Num(A),Low(E)}
=min{4,1,4}=1
5/29/2020 Dept of CSE/VEC 36
The root is an articulation point if and only
if it has more than one child
Any other vertex v is an articulation point if
and only if v has some child w such that
Low(w) ≥ Num(v)
Step 3: Rules to find Articulation Point
D has a child E, and Low(E) ≥ Num(D)
C and D are articulation points
C has a child G and Low(G) ≥ Num(C).
Example
Step 1: Find DFN
Step 2: Do Post order Traversal and
Find low value
Ver
tex
0 1 2 3 4 5 6 7 8 9
dfn 4 3 2 0 1 5 6 7 9 8
low 4 0 0 0 0 5 5 5 9 8
5/29/2020 Dept of CSE/VEC 37
the root, vertex 3, is an
articulation point because it has
more than one child.
vertex 1 is an articulation point
since it has a child 0 such that
low (0) ≥ dfn (1)
Vertex 7 is also an articulation
point since low (8) ≥ dfn (7)
vertex 5 is also an articulation
point since low (6) ≥ dfn (5).
Ver
tex
0 1 2 3 4 5 6 7 8 9
dfn 4 3 2 0 1 5 6 7 9 8
low 4 0 0 0 0 5 5 5 9 8
5/29/2020 Dept of CSE/VEC 38
Euler circuit
Eulerian path and circuit for
undirected graph
• Eulerian Path is a path in graph
that visits every edge exactly
once.
• Eulerian Circuit is an Eulerian
Path which starts and ends on
the same vertex.
• An Euler path starts and ends
at different vertices.
• An Euler circuit starts and ends
at the same vertex
• A graph is called Eulerian if it
has an Eulerian Cycle and
called Semi-Eulerian if it has an
Eulerian Path
5/29/2020 Dept of CSE/VEC 39
Euler Path Eg
5/29/2020 Dept of CSE/VEC 40
Euler Path to exist in a graph, exactly 2 vertices must have odd degree
Start with one of the odd vertices. End in the other one
Euler Circuit
All vertices must have even degree
5/29/2020 Dept of CSE/VEC 41
Condition for Euler Path and Euler Circuit
5/29/2020 Dept of CSE/VEC 42
DFS to find Euler circuit
5/29/2020 Dept of CSE/VEC 43
2 , 1, 0, 2
2, 1,0, 3,4,0,2
 Start with any vertex s.
 First, using DFS find any circuit
starting and ending in s.
 Mark all edges on the circuit as
visited
 While there are still edges in the
graph that are not marked
visited:
• Find the first vertex v on
the circuit that has unvisited
edges.
• Find a circuit starting in v
and splice this path into the first
circuit
1,0,2,1
1,0,3,4,0,2,1
Solution 1
Solution 2

More Related Content

PPTX
Trees and graphs
PPTX
Tensor Explained
PDF
Introduction to Graph Theory
PPTX
Dijkstra’S Algorithm
PDF
PPT
Set in discrete mathematics
PDF
Quick sort
PPTX
Theory of Computation Unit 3
Trees and graphs
Tensor Explained
Introduction to Graph Theory
Dijkstra’S Algorithm
Set in discrete mathematics
Quick sort
Theory of Computation Unit 3

What's hot (20)

PDF
Advanced MATLAB Tutorial for Engineers & Scientists
PPTX
Matlab m files and scripts
PDF
Master theorem
PPT
minimum spanning tree
PPTX
Kruskal Algorithm
PPTX
Prims and kruskal algorithms
PPT
Biconnected components (13024116056)
PPTX
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
PPTX
TRIES_data_structure
PPTX
Data Structure and Algorithms Merge Sort
PPT
Prim Algorithm and kruskal algorithm
PPTX
Thomas Calculus Chp 12
PPT
KRUSKAL'S algorithm from chaitra
PPTX
Graph theory
PPTX
Dijkstra
PPT
Floyd Warshall Algorithm
PPTX
Radix sort presentation
PPTX
Vector space
PPTX
Array in c language
PPSX
Matlab basic and image
Advanced MATLAB Tutorial for Engineers & Scientists
Matlab m files and scripts
Master theorem
minimum spanning tree
Kruskal Algorithm
Prims and kruskal algorithms
Biconnected components (13024116056)
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
TRIES_data_structure
Data Structure and Algorithms Merge Sort
Prim Algorithm and kruskal algorithm
Thomas Calculus Chp 12
KRUSKAL'S algorithm from chaitra
Graph theory
Dijkstra
Floyd Warshall Algorithm
Radix sort presentation
Vector space
Array in c language
Matlab basic and image
Ad

Similar to Day 5 application of graph ,biconnectivity fdp on ds (20)

PPTX
TREE ADT, TREE TRAVERSALS, BINARY TREE ADT
PPTX
UNIT II - Graph Algorithms techniques.pptx
PPTX
Graph Algorithms
PPTX
Unit 4 dsuc
PPTX
GRAPH - DISCRETE STRUCTURE AND ALGORITHM
PDF
Unit-10 Graphs .pdf
PPTX
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
PPT
Graphs
PPT
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
PPT
lec 09-graphs-bfs-dfs.ppt
PDF
lecture 23 algorithm design and analysis
PPTX
Spanning Tree in data structure and .pptx
PPTX
Ram minimum spanning tree
PPTX
Basic Graph Algorithms Vertex (Node): lk
PDF
Topological Sort
PPTX
UNIT III.pptx
PPTX
Unit ix graph
PPT
Data Structures-Non Linear DataStructures-Graphs
TREE ADT, TREE TRAVERSALS, BINARY TREE ADT
UNIT II - Graph Algorithms techniques.pptx
Graph Algorithms
Unit 4 dsuc
GRAPH - DISCRETE STRUCTURE AND ALGORITHM
Unit-10 Graphs .pdf
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
Graphs
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
lec 09-graphs-bfs-dfs.ppt
lecture 23 algorithm design and analysis
Spanning Tree in data structure and .pptx
Ram minimum spanning tree
Basic Graph Algorithms Vertex (Node): lk
Topological Sort
UNIT III.pptx
Unit ix graph
Data Structures-Non Linear DataStructures-Graphs
Ad

Recently uploaded (20)

DOCX
573137875-Attendance-Management-System-original
PPTX
Artificial Intelligence
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
PDF
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
PPT
introduction to datamining and warehousing
PPTX
additive manufacturing of ss316l using mig welding
PPTX
Current and future trends in Computer Vision.pptx
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PPTX
Geodesy 1.pptx...............................................
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
III.4.1.2_The_Space_Environment.p pdffdf
PPT
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
PDF
Well-logging-methods_new................
PDF
737-MAX_SRG.pdf student reference guides
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
573137875-Attendance-Management-System-original
Artificial Intelligence
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
UNIT 4 Total Quality Management .pptx
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
introduction to datamining and warehousing
additive manufacturing of ss316l using mig welding
Current and future trends in Computer Vision.pptx
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
Geodesy 1.pptx...............................................
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
III.4.1.2_The_Space_Environment.p pdffdf
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
Well-logging-methods_new................
737-MAX_SRG.pdf student reference guides
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems

Day 5 application of graph ,biconnectivity fdp on ds

  • 1. VELAMMAL ENGINEERING COLLEGE An Autonomous Institution, Affiliated to Anna University Chennai, & Approved by AICTE Delhi Online Faculty Development Program on Data Structures (CS8391) From 25th – 29th May 2020 Organized by Department of Computer Science and Engineering In Association with Computer Society of India
  • 2. APPLICATION OF GRAPH & BICONNECTED GRAPH DR.S.GUNASUNDARI ASSOCIATE PROFESSOR VELAMMAL ENGINEERING COLLEGE
  • 3. OUTLINE • GRAPH APPLICATIONS – MINIMUM SPANNING TREE • PRIMS ALGORITHM • KRUSKAL ALGORITHM – SHORTEST PATH • SINGLE SOURCE- DIJIKSTRA ALGORITHM • DFS APPLICATION – BICONNECTED GRAPH – EULER CIRCUIT 5/29/2020 Dept of CSE/VEC 3
  • 4. APPLICATION OF GRAPH • Graphs are widely used to model any situation – where entities or things are related to each other in pairs. – For example, the following information can be represented by graphs: – Transportation networks » In which nodes are airports, ports, etc. » The edges can be airline flights, shipping routes, etc. – In circuit networks » points of connection are drawn as vertices » component wires become the edges of the graph. 5/29/2020 Dept of CSE/VEC 4
  • 5. Application of Graphs Google maps – Intersection of two(or more) roads are considered to be a vertex – Road connecting two vertices is considered to be an edge – Navigation system is based on the algorithm to calculate the shortest path between two vertices. Facebook – Users are considered to be the vertices – If they are friends then there is an edge running between them. – undirected graph. World Wide Web – web pages are considered to be the vertices. – There is an edge from a page u to other page v if there is a link of page v on page u – Directed graph. Operating System – Resource Allocation Graph – Each process and resources are considered to be vertices. – Edges are drawn from resources to the allocated process 5/29/2020 Dept of CSE/VEC 5
  • 6. Minimum Spanning Trees • A spanning tree of a connected, undirected graph G – Sub-graph of G which is a tree that connects all the vertices together. • A graph G can have many different spanning trees. • Minimum Spanning Tree – Spanning tree of the smallest weight – weight of a tree is defined as the sum of the weights on all its edges. • Minimum Spanning Tree problem – Finding a minimum spanning tree for a given weighted connected graph 5/29/2020 Dept of CSE/VEC 6
  • 8. Weighted graph - example 5/29/2020 Dept of CSE/VEC 8
  • 9. MST - Application • MSTs are used to find airline routes. – Vertices in the graph denote cities – Edges represent the routes between these cities. – MSTs are used to optimize airline routes by finding the least costly path with no cycles. • MSTs are also used to find the cheapest way to connect terminals, such as cities, electronic components or computers via roads, airlines, railways, wires or telephone lines. • MSTs are applied in routing algorithms for finding the most efficient path. 5/29/2020 Dept of CSE/VEC 9
  • 10. Prim’s Algorithm • Prim’s algorithm is a greedy algorithm • Used to form a minimum spanning tree for a connected weighted undirected graph. • Builds a tree that includes every vertex and a subset of the edges in such a way that the total weight of all the edges in the tree is minimized. • Tree vertices Vertices that are a part of the minimum spanning tree T. • Fringe vertices Vertices that are currently not a part of T, but are adjacent to some tree vertex. • Unseen vertices Vertices that are neither tree vertices nor fringe vertices fall under this category. 5/29/2020 Dept of CSE/VEC 10
  • 11. ALGORITHM //Input: A weighted connected graph G = (V, E) //Output: T , the set of edges composing a minimum spanning tree of G Step 1: Select a starting vertex Step 2: Repeat Steps 3 and 4 until there are fringe vertices Step 3: Select an edge e connecting the tree vertex and fringe vertex that has minimum weight Step 4: Add the selected edge and the vertex to the minimum spanning tree T Step 5: EXIT 5/29/2020 Dept of CSE/VEC 11
  • 14. Example 2 Attach two labels to a vertex • the name of the nearest tree vertex, • the weight of the corresponding edge. select a as starting vertex a(-, -) b(a, 3) c(-, ∞) 5/29/2020 Dept of CSE/VEC 14
  • 15. 5/29/2020 Dept of CSE/VEC 15
  • 16. 5/29/2020 Dept of CSE/VEC 16
  • 17. 5/29/2020 Dept of CSE/VEC 17
  • 18. Example 3 5/29/2020 Dept of CSE/VEC 18
  • 19. Pseudo code 5/29/2020 Dept of CSE/VEC 19 T = ∅; U = { 1 }; while (U ≠ V) let (u, v) be the lowest cost edge such that u ∈ U and v ∈ V - U; T = T ∪ {(u, v)} U = U ∪ {v}
  • 20. KRUSKAL ALGORITHM Step-01: Sort all the edges from low weight to high weight. Step-02: Take the edge with the lowest weight and use it to connect the vertices of graph. If adding an edge creates a cycle, then reject that edge and go for the next least weight edge. Step-03: Keep adding edges until all the vertices are connected and a Minimum Spanning Tree (MST) is obtained. 5/29/2020 Dept of CSE/VEC 20
  • 21. Example 1 Step-01 Step-02 Step-03 5/29/2020 Dept of CSE/VEC 21
  • 23. EXAMPLE 2 5/29/2020 Dept of CSE/VEC 23
  • 24. 5/29/2020 Dept of CSE/VEC 24
  • 25. 5/29/2020 Dept of CSE/VEC 25
  • 26. Pseudo code 5/29/2020 Dept of CSE/VEC 26
  • 27. Prims Vs Kruskal Kruskal’s Algorithm is preferred when – The graph is sparse. – There are less number of edges in the graph – The edges are already sorted or can be sorted in linear time. Prim’s Algorithm is preferred when – The graph is dense. – There are large number of edges in the graph 5/29/2020 Dept of CSE/VEC 27
  • 28. Time Complexity Prims • If a graph is represented by its weight matrix, then the running time of Prim’s algorithm is , where n = |V| • Let graph is represented by its adjacency lists • Running time of Prim’s algorithm is in O(m log n), – where m = |E|, n = |V| Kruskal O(ElogV) 5/29/2020 Dept of CSE/VEC 28
  • 29. DIJIKSTRA‘S ALGORITHM • Single-source shortest-path problem • For a given vertex called the source in a weighted connected graph – Find shortest paths to all its other vertices. – The best-known algorithm for the single-source shortest-paths problem is called Dijkstra’s algorithm. • First, it finds the shortest path from the source to a vertex nearest to it, then to a second nearest, and so on 5/29/2020 Dept of CSE/VEC 29
  • 30. DIJIKSTRA ALGORITHM contd..  Create a set Tree Vertices that keeps track of vertices included in shortest path tree  Initially, this set is empty.  Assign a distance value to all vertices in the input graph.  Initialize all distance values as INFINITE.  Assign distance value as 0 for the source vertex so that it is picked first.  While Tree Vertex doesn’t include all vertices  Pick a vertex u which is not there in Tree Vertex and has minimum distance value.  Include u to Tree Vertex.  Update distance value of all adjacent vertices of u. For every adjacent vertex v  if sum of distance value of u (from source) and weight of edge u-v, is less than the distance value of v then update the distance value of v. 5/29/2020 Dept of CSE/VEC 30
  • 32. 5/29/2020 Dept of CSE/VEC 32 from a to b : a - b of length 3 from a to d : a - b - d of length 5 from a to c : a - b - c of length 7 from a to e : a - b - d - e of length 9
  • 33. • Dijikstra’s algorithm does not always work correctly – If the edge weight is negative. • The algorithm that is used to solve the negative weighted, single-source shortest-paths path problem – Bellman-Ford’s algorithm (using dynamic programming). • Time Analysis – Adjacency Matrix Representation • O(V2). – Adjacency list • O(ElogV) 5/29/2020 Dept of CSE/VEC 33
  • 34. Biconnected Graph • A graph with no articulation point • If and only if any vertex is deleted, the graph remains connected 5/29/2020 Dept of CSE/VEC 34
  • 35. 5/29/2020 Dept of CSE/VEC 35 First, starting at any vertex, we perform a depth- first search and number the nodes as they are visited. For each vertex, v, call this preorder number Num(v) Low(v) is the minimum of 1. Num(v) 2. the lowest Num(w) among all back edges (v, w) 3. the lowest Low(w) among all tree edges (v, w) Step 1: Find DFN Step 2: Do Post order Traversal and Find low value Low(F)=min{Num(F),Num(D),-) =min{6,4,-}=4 Low(E)=min{Num(E),-,Low(F)} =min{5,-,4}=4 Low(D)=min{Num(D),Num(A),Low(E)} =min{4,1,4}=1
  • 36. 5/29/2020 Dept of CSE/VEC 36 The root is an articulation point if and only if it has more than one child Any other vertex v is an articulation point if and only if v has some child w such that Low(w) ≥ Num(v) Step 3: Rules to find Articulation Point D has a child E, and Low(E) ≥ Num(D) C and D are articulation points C has a child G and Low(G) ≥ Num(C).
  • 37. Example Step 1: Find DFN Step 2: Do Post order Traversal and Find low value Ver tex 0 1 2 3 4 5 6 7 8 9 dfn 4 3 2 0 1 5 6 7 9 8 low 4 0 0 0 0 5 5 5 9 8 5/29/2020 Dept of CSE/VEC 37
  • 38. the root, vertex 3, is an articulation point because it has more than one child. vertex 1 is an articulation point since it has a child 0 such that low (0) ≥ dfn (1) Vertex 7 is also an articulation point since low (8) ≥ dfn (7) vertex 5 is also an articulation point since low (6) ≥ dfn (5). Ver tex 0 1 2 3 4 5 6 7 8 9 dfn 4 3 2 0 1 5 6 7 9 8 low 4 0 0 0 0 5 5 5 9 8 5/29/2020 Dept of CSE/VEC 38
  • 39. Euler circuit Eulerian path and circuit for undirected graph • Eulerian Path is a path in graph that visits every edge exactly once. • Eulerian Circuit is an Eulerian Path which starts and ends on the same vertex. • An Euler path starts and ends at different vertices. • An Euler circuit starts and ends at the same vertex • A graph is called Eulerian if it has an Eulerian Cycle and called Semi-Eulerian if it has an Eulerian Path 5/29/2020 Dept of CSE/VEC 39
  • 40. Euler Path Eg 5/29/2020 Dept of CSE/VEC 40 Euler Path to exist in a graph, exactly 2 vertices must have odd degree Start with one of the odd vertices. End in the other one
  • 41. Euler Circuit All vertices must have even degree 5/29/2020 Dept of CSE/VEC 41
  • 42. Condition for Euler Path and Euler Circuit 5/29/2020 Dept of CSE/VEC 42
  • 43. DFS to find Euler circuit 5/29/2020 Dept of CSE/VEC 43 2 , 1, 0, 2 2, 1,0, 3,4,0,2  Start with any vertex s.  First, using DFS find any circuit starting and ending in s.  Mark all edges on the circuit as visited  While there are still edges in the graph that are not marked visited: • Find the first vertex v on the circuit that has unvisited edges. • Find a circuit starting in v and splice this path into the first circuit 1,0,2,1 1,0,3,4,0,2,1 Solution 1 Solution 2