SlideShare a Scribd company logo
CONNECTED
COMPONENTS AND
SHORTEST PATH
Kaushik Koneru
kkoneru1@student.gsu.edu
Topics
1. Connected Components
1.1 Adjacency Matrix
1.2 Connectivity Matrix
1.3 Matrix of Connected Components
2. All-Pairs Shortest Path
Elements of Connected Components
Graph can be represented a G = (V, E)
V – 𝑣0, 𝑣1, 𝑣2 … … 𝑣 𝑛−1 = 𝑠𝑒𝑡 𝑜𝑓 𝑣𝑒𝑟𝑡𝑖𝑐𝑒𝑠 = 𝑛 𝑁𝑜𝑑𝑒𝑠
E - {𝐸0, 𝐸1, 𝐸2 … … 𝐸 𝑚−1} = 𝑠𝑒𝑡 𝑜𝑓 𝐸𝑑𝑔𝑒𝑠 = 𝑚 𝐸𝑑𝑔𝑒𝑠
Adjacency Matrix ( n x n )
𝑎𝑖𝑗 =
1 𝑖𝑓 𝑣𝑖 𝑎𝑛𝑑 𝑣𝑗 𝑎𝑟𝑒 𝑐𝑜𝑛𝑛𝑒𝑐𝑡𝑒𝑑
0 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
Connected components and shortest path
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
𝐶𝑖𝑗 =
1 𝑖𝑓𝑡ℎ𝑒𝑟𝑒 𝑖𝑠 𝑎 𝑝𝑎𝑡ℎ 𝑒𝑥𝑖𝑠𝑡 𝑏𝑒𝑡𝑤𝑒𝑒𝑛 𝑣𝑖 𝑎𝑛𝑑 𝑣𝑗
0 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
Input  Adjacency Matrix A
Adjacency Matrix (A) ----Boolean Matrix Multiplication  Connectivity Matrix (C)
Boolean Matrix Multiplication
1.) 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 are
Logical AND replaces Multiplication
Logical OR replaces Addition
Logical AND  0 and 0 = 0; 0 and 1 = 0; 1 and 0 = 0; 1 and 1 = 1
Logical 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 fromA (Adjacency Matrix)
– 𝑏𝑗𝑗 = 1 𝑤ℎ𝑒𝑟𝑒 0 < 𝑗 < 𝑛
– So,
• For all 0 ≤ 𝑗, 𝑘 ≤ 𝑛 − 1
– 𝑏𝑗𝑘 =
𝑎𝑗𝑘 𝑓𝑜𝑟 𝑎𝑙𝑙 𝑗 ! = 𝑘
1 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
⇒
1 𝑝𝑎𝑡ℎ 𝑓𝑟𝑜𝑚 𝑣𝑗 𝑡𝑜 𝑣 𝑘 𝑤𝑖𝑡ℎ 𝑙𝑒𝑛𝑔𝑡ℎ 𝑙𝑒𝑠𝑠 𝑡ℎ𝑎𝑛 2
0 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
0 1 0
1 0 1
0 1 0
→
1 1 0
1 1 1
0 1 1
A B
Steps to compute Connectivity Matrix
2. Calculate 𝐵2
𝑓𝑟𝑜𝑚 𝐵 using Boolean matrix multiplication
This represents paths of less than or equal to 2
So, 𝐵2
=
1 1 1
1 1 1
1 1 1
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 = 𝐵 𝑁−1
𝑏𝑗𝑘
2
=
1 𝑝𝑎𝑡ℎ 𝑓𝑟𝑜𝑚 𝑣𝑗 𝑡𝑜 𝑣 𝑘 𝑤𝑖𝑡ℎ 𝑙𝑒𝑛𝑔𝑡ℎ 𝑙𝑒𝑠𝑠 𝑡ℎ𝑎𝑛 3
0 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
C = 𝐵 𝑛−1
Better way to compute 𝐵 𝑛−1
• 𝐵 𝑛−1
can be easily calculated by multiplying
– 𝐵2
∗ 𝐵2
− 𝐵4
– 𝐵4
∗ 𝐵4
− 𝐵8
– Multiply log(𝑛 − 1) 𝑡𝑖𝑚𝑒𝑠 𝑎𝑛𝑑 𝑔𝑒𝑛𝑒𝑟𝑎𝑡𝑒𝑑 𝑜𝑛𝑒 𝑖𝑠 𝐶
– 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 𝐵4
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 log(𝑛 − 1)
– Therefore t(n) ~= 𝑂(log2
𝑛) with n^3 processors
– Cost C(n) = 𝑂(𝑛3
log2
𝑛)
Connected Components
• With Connectivity Graph ( C ) of G, we can construct D matrix such that
– djk =
𝑣 𝑘, 𝑝𝑟𝑜𝑣𝑖𝑑𝑒𝑑 𝑡ℎ𝑎𝑡 𝑐𝑗𝑘 = 1
0, 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
– 𝑑𝑗𝑘 contains name of all the vertices to which 𝑣𝑗 is connected.
• Connected Components are then found by assigning each vertex to a constant as follows
– 𝑣𝑗 𝑖𝑠 𝑎𝑠𝑠𝑖𝑔𝑛𝑒𝑑 𝑡𝑜 𝑎 𝑐𝑜𝑚𝑝𝑜𝑛𝑒𝑛𝑡 𝑙 𝑖𝑓 𝑙 𝑖𝑠 𝑡ℎ𝑒 𝑠𝑚𝑎𝑙𝑙𝑒𝑠𝑡 𝑖𝑛𝑑𝑒𝑥 𝑓𝑜𝑟 𝑤ℎ𝑖𝑐ℎ 𝑑𝑗𝑙 = ! 0
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) = 𝑂(log2 𝑛)
– P(n) = 𝑛3
– C(n) = cost = 𝑂(𝑛3
log2
𝑛 )
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...
– 𝑤𝑖𝑗 =
< 𝑣𝑎𝑙𝑖𝑑 𝑛𝑢𝑚𝑏𝑒𝑟 > 𝑖𝑓 𝑣𝑖 𝑎𝑛𝑑 𝑣𝑗 𝑎𝑟𝑒 𝑐𝑜𝑛𝑛𝑒𝑐𝑡𝑒𝑑
0 𝑜𝑟 ∞ 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
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
• 𝑑𝑖𝑗 = 𝑠ℎ𝑜𝑟𝑡𝑒𝑠𝑡 𝑑𝑖𝑠𝑡𝑎𝑛𝑐𝑒 𝑏𝑒𝑡𝑤𝑒𝑒𝑛 𝑣𝑖 𝑎𝑛𝑑 𝑣𝑗 inV
• Condition: no negative circle should present
• By using Matrix Multiplication model we can get the shortest distance from one
vertex to other vertex
𝑑𝑖𝑗
𝑘
= 𝑠ℎ𝑜𝑟𝑡𝑒𝑠𝑡 𝑙𝑒𝑛𝑔𝑡ℎ 𝑓𝑟𝑜𝑚 𝑣𝑖 𝑡𝑜 𝑣𝑗 𝑡ℎ𝑎𝑡 𝑔𝑜𝑒𝑠 𝑡ℎ𝑟𝑜𝑢𝑔ℎ 𝑎𝑡𝑚𝑜𝑠𝑡 𝑘 − 1 𝑣𝑒𝑟𝑡𝑖𝑐𝑒𝑠
so, 𝑑𝑖𝑗
1
= 𝑤𝑖𝑗
• To get Shortest distance between all the vertices we need to calculate 𝑑𝑖𝑗
𝑛−1
All-Pair Shortest Path Matrix
Multiplication
Difference between Matrix Multiplication and Boolean Matrix Multiplication are
Addition replaces Multiplication
Min replaces Addition
Calculating 𝑑𝑖𝑗
𝑘
• In order to compute 𝑑𝑖𝑗
𝑘
– 𝑑𝑖𝑗
𝑘
= min
𝑙
( 𝑑𝑖𝑙
𝑘
2
+ 𝑑𝑙𝑗
𝑘
2
)
Hypercube Shortest Paths
Analysis of Hypercube Shortest Paths
• Step 1 and 2.2 requires constant time
• There are log(𝑛 − 1) 𝑖𝑡𝑒𝑟𝑎𝑡𝑖𝑜𝑛𝑠 𝑜𝑓 2.1each of O(logn)
• So, 𝑡 𝑛 = 𝑂(log2
𝑛)
𝑝 𝑛 = 𝑛3
𝐶 𝑛 = 𝑂(𝑛3
log2
𝑛 )

More Related Content

PDF
Graph Analytics and Complexity Questions and answers
PDF
Fortran induction project. DGTSV DGESV
PDF
Divide and conquer
PDF
Analysis of CANADAIR CL-215 retractable landing gear.
PPT
Admission in india
PDF
Numerical Methods in Mechanical Engineering - Final Project
PPTX
Data Structure and Algorithms Merge Sort
PPT
Divide and Conquer
Graph Analytics and Complexity Questions and answers
Fortran induction project. DGTSV DGESV
Divide and conquer
Analysis of CANADAIR CL-215 retractable landing gear.
Admission in india
Numerical Methods in Mechanical Engineering - Final Project
Data Structure and Algorithms Merge Sort
Divide and Conquer

What's hot (20)

PPTX
Intensity Constraint Gradient-Based Image Reconstruction
PPTX
Module 2 Design Analysis and Algorithms
PPT
Top schools in gudgao
PPT
Mba admission in india
PDF
Longest Common Sequence Algorithm Analysis
PPTX
Evaluation of programs codes using machine learning
PDF
Numerical Solution for Two Dimensional Laplace Equation with Dirichlet Bounda...
PPT
Synthesis of linear quantum stochastic systems via quantum feedback networks
PPT
5.2 divide and conquer
PPT
Divide and conquer
DOCX
Very brief highlights on some key details tosssqrd
PPT
Presentation on binary search, quick sort, merge sort and problems
PDF
Adaptive filtersfinal
PPT
Mergesort
PPT
Algorithm: Quick-Sort
PPTX
My presentation minimum spanning tree
PPT
Intro to MATLAB and K-mean algorithm
PPT
Enhance The K Means Algorithm On Spatial Dataset
PPTX
Divide and conquer - Quick sort
PPT
KRUSKAL'S algorithm from chaitra
Intensity Constraint Gradient-Based Image Reconstruction
Module 2 Design Analysis and Algorithms
Top schools in gudgao
Mba admission in india
Longest Common Sequence Algorithm Analysis
Evaluation of programs codes using machine learning
Numerical Solution for Two Dimensional Laplace Equation with Dirichlet Bounda...
Synthesis of linear quantum stochastic systems via quantum feedback networks
5.2 divide and conquer
Divide and conquer
Very brief highlights on some key details tosssqrd
Presentation on binary search, quick sort, merge sort and problems
Adaptive filtersfinal
Mergesort
Algorithm: Quick-Sort
My presentation minimum spanning tree
Intro to MATLAB and K-mean algorithm
Enhance The K Means Algorithm On Spatial Dataset
Divide and conquer - Quick sort
KRUSKAL'S algorithm from chaitra
Ad

Viewers also liked (20)

PPT
Spanning trees
PPT
B trees and_b__trees
PPT
Divide and conquer
PPTX
Combinatorial Optimization
PPT
Graph theory
PDF
Shortest Path in Graph
PPT
Greedymethod
PPTX
Graph Traversal Algorithms - Depth First Search Traversal
PPT
Best for b trees
PPT
File organization 1
PPT
FILE STRUCTURE IN DBMS
PPT
B trees dbms
PPT
Chapter 11 - File System Implementation
PPT
Cpu Scheduling Galvin
PPTX
Divide and Conquer - Part 1
PDF
Graph theory
PPTX
Computer architecture and organization
PPT
11. Storage and File Structure in DBMS
Spanning trees
B trees and_b__trees
Divide and conquer
Combinatorial Optimization
Graph theory
Shortest Path in Graph
Greedymethod
Graph Traversal Algorithms - Depth First Search Traversal
Best for b trees
File organization 1
FILE STRUCTURE IN DBMS
B trees dbms
Chapter 11 - File System Implementation
Cpu Scheduling Galvin
Divide and Conquer - Part 1
Graph theory
Computer architecture and organization
11. Storage and File Structure in DBMS
Ad

Similar to Connected components and shortest path (20)

PPTX
Optimisation random graph presentation
PDF
Analysis and design of a half hypercube interconnection network topology
PPTX
DYNAMIC PROGRAMMING AND GREEDY TECHNIQUE
PPTX
Parallel algorithm in linear algebra
PPTX
Applied Algorithms and Structures week999
PDF
Cs6402 design and analysis of algorithms may june 2016 answer key
PDF
How to design a linear control system
PDF
Visualization of general defined space data
PDF
PPTX
Advanced Modularity Optimization Assignment Help
PDF
Backpropagation (DLAI D3L1 2017 UPC Deep Learning for Artificial Intelligence)
PDF
Intro. to computational Physics ch2.pdf
PDF
Fortran chapter 2.pdf
DOC
Unit 3 daa
PPTX
Dmitrii Tihonkih - The Iterative Closest Points Algorithm and Affine Transfo...
PDF
Litvinenko low-rank kriging +FFT poster
PPTX
Linear regression, costs & gradient descent
PPTX
Digital control systems (dcs) lecture 18-19-20
DOC
algorithm Unit 3
Optimisation random graph presentation
Analysis and design of a half hypercube interconnection network topology
DYNAMIC PROGRAMMING AND GREEDY TECHNIQUE
Parallel algorithm in linear algebra
Applied Algorithms and Structures week999
Cs6402 design and analysis of algorithms may june 2016 answer key
How to design a linear control system
Visualization of general defined space data
Advanced Modularity Optimization Assignment Help
Backpropagation (DLAI D3L1 2017 UPC Deep Learning for Artificial Intelligence)
Intro. to computational Physics ch2.pdf
Fortran chapter 2.pdf
Unit 3 daa
Dmitrii Tihonkih - The Iterative Closest Points Algorithm and Affine Transfo...
Litvinenko low-rank kriging +FFT poster
Linear regression, costs & gradient descent
Digital control systems (dcs) lecture 18-19-20
algorithm Unit 3

Recently uploaded (20)

PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Basic Mud Logging Guide for educational purpose
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Computing-Curriculum for Schools in Ghana
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Institutional Correction lecture only . . .
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Cell Types and Its function , kingdom of life
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
Pharma ospi slides which help in ospi learning
PPTX
master seminar digital applications in india
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
Lesson notes of climatology university.
STATICS OF THE RIGID BODIES Hibbelers.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
Basic Mud Logging Guide for educational purpose
Microbial diseases, their pathogenesis and prophylaxis
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Computing-Curriculum for Schools in Ghana
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
human mycosis Human fungal infections are called human mycosis..pptx
Final Presentation General Medicine 03-08-2024.pptx
Institutional Correction lecture only . . .
O5-L3 Freight Transport Ops (International) V1.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Cell Types and Its function , kingdom of life
PPH.pptx obstetrics and gynecology in nursing
Pharma ospi slides which help in ospi learning
master seminar digital applications in india
Renaissance Architecture: A Journey from Faith to Humanism
Microbial disease of the cardiovascular and lymphatic systems
2.FourierTransform-ShortQuestionswithAnswers.pdf
Lesson notes of climatology university.

Connected components and shortest path

  • 1. CONNECTED COMPONENTS AND SHORTEST PATH Kaushik Koneru kkoneru1@student.gsu.edu
  • 2. Topics 1. Connected Components 1.1 Adjacency Matrix 1.2 Connectivity Matrix 1.3 Matrix of Connected Components 2. All-Pairs Shortest Path
  • 3. Elements of Connected Components Graph can be represented a G = (V, E) V – 𝑣0, 𝑣1, 𝑣2 … … 𝑣 𝑛−1 = 𝑠𝑒𝑡 𝑜𝑓 𝑣𝑒𝑟𝑡𝑖𝑐𝑒𝑠 = 𝑛 𝑁𝑜𝑑𝑒𝑠 E - {𝐸0, 𝐸1, 𝐸2 … … 𝐸 𝑚−1} = 𝑠𝑒𝑡 𝑜𝑓 𝐸𝑑𝑔𝑒𝑠 = 𝑚 𝐸𝑑𝑔𝑒𝑠 Adjacency Matrix ( n x n ) 𝑎𝑖𝑗 = 1 𝑖𝑓 𝑣𝑖 𝑎𝑛𝑑 𝑣𝑗 𝑎𝑟𝑒 𝑐𝑜𝑛𝑛𝑒𝑐𝑡𝑒𝑑 0 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
  • 6. Computing the Connectivity Matrix Connectivity Matrix: It represents a n x n Matrix C of a graph G with n vertices. Such that 𝐶𝑖𝑗 = 1 𝑖𝑓𝑡ℎ𝑒𝑟𝑒 𝑖𝑠 𝑎 𝑝𝑎𝑡ℎ 𝑒𝑥𝑖𝑠𝑡 𝑏𝑒𝑡𝑤𝑒𝑒𝑛 𝑣𝑖 𝑎𝑛𝑑 𝑣𝑗 0 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒 Input  Adjacency Matrix A Adjacency Matrix (A) ----Boolean Matrix Multiplication  Connectivity Matrix (C)
  • 7. Boolean Matrix Multiplication 1.) 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 are Logical AND replaces Multiplication Logical OR replaces Addition Logical AND  0 and 0 = 0; 0 and 1 = 0; 1 and 0 = 0; 1 and 1 = 1 Logical OR  0 and 0 = 0; 0 and 1 = 1; 1 and 0 = 1; 1 and 1 = 1
  • 8. Steps to compute Connectivity Matrix 1. Generate Matrix B fromA (Adjacency Matrix) – 𝑏𝑗𝑗 = 1 𝑤ℎ𝑒𝑟𝑒 0 < 𝑗 < 𝑛 – So, • For all 0 ≤ 𝑗, 𝑘 ≤ 𝑛 − 1 – 𝑏𝑗𝑘 = 𝑎𝑗𝑘 𝑓𝑜𝑟 𝑎𝑙𝑙 𝑗 ! = 𝑘 1 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒 ⇒ 1 𝑝𝑎𝑡ℎ 𝑓𝑟𝑜𝑚 𝑣𝑗 𝑡𝑜 𝑣 𝑘 𝑤𝑖𝑡ℎ 𝑙𝑒𝑛𝑔𝑡ℎ 𝑙𝑒𝑠𝑠 𝑡ℎ𝑎𝑛 2 0 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒 0 1 0 1 0 1 0 1 0 → 1 1 0 1 1 1 0 1 1 A B
  • 9. Steps to compute Connectivity Matrix 2. Calculate 𝐵2 𝑓𝑟𝑜𝑚 𝐵 using Boolean matrix multiplication This represents paths of less than or equal to 2 So, 𝐵2 = 1 1 1 1 1 1 1 1 1 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 = 𝐵 𝑁−1 𝑏𝑗𝑘 2 = 1 𝑝𝑎𝑡ℎ 𝑓𝑟𝑜𝑚 𝑣𝑗 𝑡𝑜 𝑣 𝑘 𝑤𝑖𝑡ℎ 𝑙𝑒𝑛𝑔𝑡ℎ 𝑙𝑒𝑠𝑠 𝑡ℎ𝑎𝑛 3 0 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒 C = 𝐵 𝑛−1
  • 10. Better way to compute 𝐵 𝑛−1 • 𝐵 𝑛−1 can be easily calculated by multiplying – 𝐵2 ∗ 𝐵2 − 𝐵4 – 𝐵4 ∗ 𝐵4 − 𝐵8 – Multiply log(𝑛 − 1) 𝑡𝑖𝑚𝑒𝑠 𝑎𝑛𝑑 𝑔𝑒𝑛𝑒𝑟𝑎𝑡𝑒𝑑 𝑜𝑛𝑒 𝑖𝑠 𝐶 – 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 𝐵4
  • 12. Hypercube Connectivity Analysis • Step 1, 2 and 3.2 are of constant time. • Step 3.1 required O(logn) time.This is iterated for log(𝑛 − 1) – Therefore t(n) ~= 𝑂(log2 𝑛) with n^3 processors – Cost C(n) = 𝑂(𝑛3 log2 𝑛)
  • 13. Connected Components • With Connectivity Graph ( C ) of G, we can construct D matrix such that – djk = 𝑣 𝑘, 𝑝𝑟𝑜𝑣𝑖𝑑𝑒𝑑 𝑡ℎ𝑎𝑡 𝑐𝑗𝑘 = 1 0, 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒 – 𝑑𝑗𝑘 contains name of all the vertices to which 𝑣𝑗 is connected. • Connected Components are then found by assigning each vertex to a constant as follows – 𝑣𝑗 𝑖𝑠 𝑎𝑠𝑠𝑖𝑔𝑛𝑒𝑑 𝑡𝑜 𝑎 𝑐𝑜𝑚𝑝𝑜𝑛𝑒𝑛𝑡 𝑙 𝑖𝑓 𝑙 𝑖𝑠 𝑡ℎ𝑒 𝑠𝑚𝑎𝑙𝑙𝑒𝑠𝑡 𝑖𝑛𝑑𝑒𝑥 𝑓𝑜𝑟 𝑤ℎ𝑖𝑐ℎ 𝑑𝑗𝑙 = ! 0
  • 15. 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) = 𝑂(log2 𝑛) – P(n) = 𝑛3 – C(n) = cost = 𝑂(𝑛3 log2 𝑛 )
  • 17. 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... – 𝑤𝑖𝑗 = < 𝑣𝑎𝑙𝑖𝑑 𝑛𝑢𝑚𝑏𝑒𝑟 > 𝑖𝑓 𝑣𝑖 𝑎𝑛𝑑 𝑣𝑗 𝑎𝑟𝑒 𝑐𝑜𝑛𝑛𝑒𝑐𝑡𝑒𝑑 0 𝑜𝑟 ∞ 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
  • 18. 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 • 𝑑𝑖𝑗 = 𝑠ℎ𝑜𝑟𝑡𝑒𝑠𝑡 𝑑𝑖𝑠𝑡𝑎𝑛𝑐𝑒 𝑏𝑒𝑡𝑤𝑒𝑒𝑛 𝑣𝑖 𝑎𝑛𝑑 𝑣𝑗 inV • Condition: no negative circle should present • By using Matrix Multiplication model we can get the shortest distance from one vertex to other vertex 𝑑𝑖𝑗 𝑘 = 𝑠ℎ𝑜𝑟𝑡𝑒𝑠𝑡 𝑙𝑒𝑛𝑔𝑡ℎ 𝑓𝑟𝑜𝑚 𝑣𝑖 𝑡𝑜 𝑣𝑗 𝑡ℎ𝑎𝑡 𝑔𝑜𝑒𝑠 𝑡ℎ𝑟𝑜𝑢𝑔ℎ 𝑎𝑡𝑚𝑜𝑠𝑡 𝑘 − 1 𝑣𝑒𝑟𝑡𝑖𝑐𝑒𝑠 so, 𝑑𝑖𝑗 1 = 𝑤𝑖𝑗 • To get Shortest distance between all the vertices we need to calculate 𝑑𝑖𝑗 𝑛−1
  • 19. All-Pair Shortest Path Matrix Multiplication Difference between Matrix Multiplication and Boolean Matrix Multiplication are Addition replaces Multiplication Min replaces Addition
  • 20. Calculating 𝑑𝑖𝑗 𝑘 • In order to compute 𝑑𝑖𝑗 𝑘 – 𝑑𝑖𝑗 𝑘 = min 𝑙 ( 𝑑𝑖𝑙 𝑘 2 + 𝑑𝑙𝑗 𝑘 2 )
  • 22. Analysis of Hypercube Shortest Paths • Step 1 and 2.2 requires constant time • There are log(𝑛 − 1) 𝑖𝑡𝑒𝑟𝑎𝑡𝑖𝑜𝑛𝑠 𝑜𝑓 2.1each of O(logn) • So, 𝑡 𝑛 = 𝑂(log2 𝑛) 𝑝 𝑛 = 𝑛3 𝐶 𝑛 = 𝑂(𝑛3 log2 𝑛 )