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

PDF
Serie algos approximationx
PDF
Mes devoirs 4 si
PDF
Exercices en turbo pascal sur la récursivité
DOCX
Résumer sur les fichier et les enregistrement
PPTX
4.2 variantsof turing machines (types of tm)
PPT
Chapter 11 - Sorting and Searching
PDF
Algorithmique et Structures de Données II
PDF
Projet de programmation la conversion entre les bases
Serie algos approximationx
Mes devoirs 4 si
Exercices en turbo pascal sur la récursivité
Résumer sur les fichier et les enregistrement
4.2 variantsof turing machines (types of tm)
Chapter 11 - Sorting and Searching
Algorithmique et Structures de Données II
Projet de programmation la conversion entre les bases

What's hot (20)

PDF
Algorithmes d'approximation
PDF
Les algorithmes recurrents
PPTX
Les algorithmes d’approximation
PDF
PDF
Devoirs Algorithme + correction pour 4 si
PDF
Les enregistrements
PDF
03 Analysis of Algorithms: Probabilistic Analysis
PDF
Chapitre 4 récursivité
PDF
Récursivité
PDF
Chapitre 2 -Complexité des problèmes avec correction.pdf
PDF
Python file handling
PDF
Binary Search - Design & Analysis of Algorithms
PPTX
Theory of computation Lec2
PPT
Complexity of Algorithm
PDF
Chapitre 1 rappel
PDF
Time and Space Complexity
PDF
bac info : série récursivité
PPTX
Algorithm Complexity and Main Concepts
PPTX
Exception Handling in object oriented programming using C++
PDF
Chapitre 2 complexité
Algorithmes d'approximation
Les algorithmes recurrents
Les algorithmes d’approximation
Devoirs Algorithme + correction pour 4 si
Les enregistrements
03 Analysis of Algorithms: Probabilistic Analysis
Chapitre 4 récursivité
Récursivité
Chapitre 2 -Complexité des problèmes avec correction.pdf
Python file handling
Binary Search - Design & Analysis of Algorithms
Theory of computation Lec2
Complexity of Algorithm
Chapitre 1 rappel
Time and Space Complexity
bac info : série récursivité
Algorithm Complexity and Main Concepts
Exception Handling in object oriented programming using C++
Chapitre 2 complexité
Ad

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

PPTX
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
PDF
Topological Sort
PDF
Flight-schedule using Dijkstra's algorithm with comparison of routes findings
PPTX
1 sollins algorithm
PPTX
141222 graphulo ingraphblas
 
PPTX
141205 graphulo ingraphblas
PPTX
Minimum spanning tree.pptx data structure programming
PPTX
Minimum Spanning Tree (Data Structure and Algorithm)
PPTX
Lecture 10 - Graph part 2.pptx,discrete mathemactics
PPTX
kruskal and prims algorithm _
PDF
A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstr...
PDF
Shortest path by using suitable algorithm.pdf
PDF
The shortest not necessarily the best. other path on the basis of the optimal...
PDF
The shortest not necessarily the best other path on the basis of the optimal ...
PDF
An analysis between exact and approximate algorithms for the k-center proble...
PPT
Design and Analysis of Algorithm -Shortest paths problem
PPTX
Single sourceshortestpath by emad
PPT
Graphs in Data Structure
PPTX
Minimum spanning tree
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
Topological Sort
Flight-schedule using Dijkstra's algorithm with comparison of routes findings
1 sollins algorithm
141222 graphulo ingraphblas
 
141205 graphulo ingraphblas
Minimum spanning tree.pptx data structure programming
Minimum Spanning Tree (Data Structure and Algorithm)
Lecture 10 - Graph part 2.pptx,discrete mathemactics
kruskal and prims algorithm _
A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstr...
Shortest path by using suitable algorithm.pdf
The shortest not necessarily the best. other path on the basis of the optimal...
The shortest not necessarily the best other path on the basis of the optimal ...
An analysis between exact and approximate algorithms for the k-center proble...
Design and Analysis of Algorithm -Shortest paths problem
Single sourceshortestpath by emad
Graphs in Data Structure
Minimum spanning tree
Ad

Recently uploaded (20)

PPTX
Lesson 3_Tessellation.pptx finite Mathematics
PDF
composite construction of structures.pdf
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPT
Mechanical Engineering MATERIALS Selection
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
Construction Project Organization Group 2.pptx
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
Well-logging-methods_new................
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
web development for engineering and engineering
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PDF
Arduino robotics embedded978-1-4302-3184-4.pdf
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PPTX
Sustainable Sites - Green Building Construction
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PDF
PPT on Performance Review to get promotions
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
Lesson 3_Tessellation.pptx finite Mathematics
composite construction of structures.pdf
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Mechanical Engineering MATERIALS Selection
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Construction Project Organization Group 2.pptx
Foundation to blockchain - A guide to Blockchain Tech
Well-logging-methods_new................
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
web development for engineering and engineering
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Arduino robotics embedded978-1-4302-3184-4.pdf
Lecture Notes Electrical Wiring System Components
Strings in CPP - Strings in C++ are sequences of characters used to store and...
Sustainable Sites - Green Building Construction
OOP with Java - Java Introduction (Basics)
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPT on Performance Review to get promotions
Model Code of Practice - Construction Work - 21102022 .pdf

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