22
CONNECTED COMPONENTS AND SHORTEST PATH Kaushik Koneru [email protected]

Connected components and shortest path

Embed Size (px)

Citation preview

Page 1: Connected components and shortest path

CONNECTED COMPONENTS AND SHORTEST PATHKaushik [email protected]

Page 2: Connected components and shortest path

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

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
Page 5: Connected components and shortest path
Page 6: Connected components and shortest path

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

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

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

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

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

Hypercube Connectivity

Page 12: Connected components and shortest path

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

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

Hypercube Connected Components

Page 15: Connected components and shortest path

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

Example

Page 17: Connected components and shortest path

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

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

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

Calculating • In order to compute

– =

Page 21: Connected components and shortest path

Hypercube Shortest Paths

Page 22: Connected components and shortest path

Analysis of Hypercube Shortest Paths• Step 1 and 2.2 requires constant time • There are each of O(logn)

• So,