Connected components and shortest path

Post on 16-Apr-2017

196 views 0 download

transcript

CONNECTED COMPONENTS AND SHORTEST PATHKaushik Konerukkoneru1@student.gsu.edu

Topics1. Connected Components

1.1 Adjacency Matrix1.2 Connectivity Matrix1.3 Matrix of Connected Components

2. All-Pairs Shortest Path

Elements of Connected ComponentsGraph can be represented a G = (V, E)

V – E -

Adjacency Matrix ( n x n )

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)

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

Steps to compute Connectivity Matrix

1. Generate Matrix B from A (Adjacency Matrix)

– So,• For all

A B

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 =

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

Hypercube Connectivity

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) =

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

Hypercube Connected Components

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 =

Example

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...

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

All-Pair Shortest Path Matrix Multiplication

Difference between Matrix Multiplication and Boolean Matrix Multiplication areAddition replaces Multiplication

Min replaces Addition

Calculating • In order to compute

– =

Hypercube Shortest Paths

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

• So,