Graph Algorithms Shortest path problems. Graph Algorithms Shortest path problems.
Connected components and shortest path
-
Upload
kaushik-koneru -
Category
Education
-
view
200 -
download
0
Transcript of Connected components and shortest path
![Page 1: Connected components and shortest path](https://reader035.fdocuments.in/reader035/viewer/2022062900/58f3731f1a28ab955f8b45b3/html5/thumbnails/1.jpg)
CONNECTED COMPONENTS AND SHORTEST PATHKaushik [email protected]
![Page 2: Connected components and shortest path](https://reader035.fdocuments.in/reader035/viewer/2022062900/58f3731f1a28ab955f8b45b3/html5/thumbnails/2.jpg)
Topics1. Connected Components
1.1 Adjacency Matrix1.2 Connectivity Matrix1.3 Matrix of Connected Components
2. All-Pairs Shortest Path
![Page 3: Connected components and shortest path](https://reader035.fdocuments.in/reader035/viewer/2022062900/58f3731f1a28ab955f8b45b3/html5/thumbnails/3.jpg)
Elements of Connected ComponentsGraph can be represented a G = (V, E)
V – E -
Adjacency Matrix ( n x n )
![Page 4: Connected components and shortest path](https://reader035.fdocuments.in/reader035/viewer/2022062900/58f3731f1a28ab955f8b45b3/html5/thumbnails/4.jpg)
![Page 5: Connected components and shortest path](https://reader035.fdocuments.in/reader035/viewer/2022062900/58f3731f1a28ab955f8b45b3/html5/thumbnails/5.jpg)
![Page 6: Connected components and shortest path](https://reader035.fdocuments.in/reader035/viewer/2022062900/58f3731f1a28ab955f8b45b3/html5/thumbnails/6.jpg)
Computing the Connectivity Matrix
Connectivity Matrix: It represents a n x n Matrix C of a graph G with n vertices. Such that
Input Adjacency Matrix A
Adjacency Matrix (A) ----Boolean Matrix Multiplication Connectivity Matrix (C)
![Page 7: Connected components and shortest path](https://reader035.fdocuments.in/reader035/viewer/2022062900/58f3731f1a28ab955f8b45b3/html5/thumbnails/7.jpg)
Boolean Matrix Multiplication1.) Every Entry in Boolean Matrix is binary either 0 or 1
2.) Boolean Operations are Logical AND & Logical OR
Difference between Matrix Multiplication and Boolean Matrix Multiplication areLogical AND replaces Multiplication
Logical OR replaces Addition
Logical AND 0 and 0 = 0; 0 and 1 = 0; 1 and 0 = 0; 1 and 1 = 1Logical OR 0 and 0 = 0; 0 and 1 = 1; 1 and 0 = 1; 1 and 1 = 1
![Page 8: Connected components and shortest path](https://reader035.fdocuments.in/reader035/viewer/2022062900/58f3731f1a28ab955f8b45b3/html5/thumbnails/8.jpg)
Steps to compute Connectivity Matrix
1. Generate Matrix B from A (Adjacency Matrix)
– So,• For all
A B
![Page 9: Connected components and shortest path](https://reader035.fdocuments.in/reader035/viewer/2022062900/58f3731f1a28ab955f8b45b3/html5/thumbnails/9.jpg)
Steps to compute Connectivity Matrix
2. Calculate using Boolean matrix multiplicationThis represents paths of less than or equal to 2
So, =
such that
So, Similarly gives connectivity of graph with less than or equal to length n. In a graph G with n vertices it cannot have length with more than n – 1. So,
C =
𝑏 𝑗𝑘2 ={1𝑝𝑎𝑡 h 𝑓𝑟𝑜𝑚𝑣 𝑗 𝑡𝑜𝑣𝑘𝑤𝑖𝑡 h 𝑙𝑒𝑛𝑔𝑡 h 𝑙𝑒𝑠𝑠𝑡 h𝑎𝑛3
0 𝑜𝑡h𝑒𝑟𝑤𝑖𝑠𝑒
C =
![Page 10: Connected components and shortest path](https://reader035.fdocuments.in/reader035/viewer/2022062900/58f3731f1a28ab955f8b45b3/html5/thumbnails/10.jpg)
Better way to compute • can be easily calculated by multiplying
– Multiply
– If n-1 is not a power of 2 then C = • Where M is smallest power of 2 larger than n-1
Example: For n = 4 to get C we need to calculate
![Page 11: Connected components and shortest path](https://reader035.fdocuments.in/reader035/viewer/2022062900/58f3731f1a28ab955f8b45b3/html5/thumbnails/11.jpg)
Hypercube Connectivity
![Page 12: Connected components and shortest path](https://reader035.fdocuments.in/reader035/viewer/2022062900/58f3731f1a28ab955f8b45b3/html5/thumbnails/12.jpg)
Hypercube Connectivity Analysis• Step 1, 2 and 3.2 are of constant time.• Step 3.1 required O(logn) time. This is iterated for
– Therefore t(n) ~= with n^3 processors – Cost C(n) =
![Page 13: Connected components and shortest path](https://reader035.fdocuments.in/reader035/viewer/2022062900/58f3731f1a28ab955f8b45b3/html5/thumbnails/13.jpg)
Connected Components• With Connectivity Graph ( C ) of G, we can construct D matrix such that
– contains name of all the vertices to which is connected.
• Connected Components are then found by assigning each vertex to a constant as follows
![Page 14: Connected components and shortest path](https://reader035.fdocuments.in/reader035/viewer/2022062900/58f3731f1a28ab955f8b45b3/html5/thumbnails/14.jpg)
Hypercube Connected Components
![Page 15: Connected components and shortest path](https://reader035.fdocuments.in/reader035/viewer/2022062900/58f3731f1a28ab955f8b45b3/html5/thumbnails/15.jpg)
Analysis of Hypercube connected components
• Step 1 Required O(log^2 n) time• Step 2 and 3.2 takes constant time• Overall running time
– T(n) = – P(n) = – C(n) = cost =
![Page 16: Connected components and shortest path](https://reader035.fdocuments.in/reader035/viewer/2022062900/58f3731f1a28ab955f8b45b3/html5/thumbnails/16.jpg)
Example
![Page 17: Connected components and shortest path](https://reader035.fdocuments.in/reader035/viewer/2022062900/58f3731f1a28ab955f8b45b3/html5/thumbnails/17.jpg)
All-Pair Shortest Path• Weighted Graph
– Weight is applied on each of the edges of the graph.– Weight can be cost, time, reliability or probability...
![Page 18: Connected components and shortest path](https://reader035.fdocuments.in/reader035/viewer/2022062900/58f3731f1a28ab955f8b45b3/html5/thumbnails/18.jpg)
All-Pair Shortest Problem• All-Pair Shortest Problem is to calculate the shortest distance between any vertex to
any vertex and representing in a matrix D• in V• Condition: no negative circle should present
• By using Matrix Multiplication model we can get the shortest distance from one vertex to other vertex
so, • To get Shortest distance between all the vertices we need to calculate
![Page 19: Connected components and shortest path](https://reader035.fdocuments.in/reader035/viewer/2022062900/58f3731f1a28ab955f8b45b3/html5/thumbnails/19.jpg)
All-Pair Shortest Path Matrix Multiplication
Difference between Matrix Multiplication and Boolean Matrix Multiplication areAddition replaces Multiplication
Min replaces Addition
![Page 20: Connected components and shortest path](https://reader035.fdocuments.in/reader035/viewer/2022062900/58f3731f1a28ab955f8b45b3/html5/thumbnails/20.jpg)
Calculating • In order to compute
– =
![Page 21: Connected components and shortest path](https://reader035.fdocuments.in/reader035/viewer/2022062900/58f3731f1a28ab955f8b45b3/html5/thumbnails/21.jpg)
Hypercube Shortest Paths
![Page 22: Connected components and shortest path](https://reader035.fdocuments.in/reader035/viewer/2022062900/58f3731f1a28ab955f8b45b3/html5/thumbnails/22.jpg)
Analysis of Hypercube Shortest Paths• Step 1 and 2.2 requires constant time • There are each of O(logn)
• So,