SlideShare a Scribd company logo
1 of 32
Download to read offline
All-Pairs Shortest Path
         Theory and Algorithms


   Carlos Andres Theran Suarez
Program Mathematics and Scientific Computing
        University of Puerto Rico
            Carlos.theran@upr.edu

                October – 2011
             Mayaguez-Puerto Rico


                        Dr Marko Schütz
Introduction

• In this section we consider de problem of finding
  shortest path between all pair of vertices in a directed
  graph ������ = (������, ������).

     – With a weight function ������: ������ → ℝ
       ������ ������ = ������−������ ������(������������ , ������������+������ ) where ������ ∈ ������ ������������������ ������ ∈ ℕ.
                ������=������


     For this goal we are going to use the adjacency-matrix of a
     graph.
 •   The input: is a ������ ������ ������ ������������������������������������ ������������������������������������ ������ = ������������������ which is
     adjacency-matrix of a ������ = ������, ������ .
 •   The output: is the ������ ������ ������ matrix of SPL ������ ������, ������ , ∀������������ ∈ ������.
Recall

• Single-Source shortest paths.
   • Nonnegative edge weight.
   – Dijkstra’s algorithm: Running time Array ������ ������������
                           Running time Binary heap ������( ������ + ������ log ������)
                           Running time Fibonacci heap ������(������ + ������ log ������)


   • General.
   – Bellman-Ford: Running time ������ ������������


   • UDG.
   – Breadth for search: Running time ������ ������ + ������
What do you think?

Can we solve all-pair shortest paths by running a
single source-paths algorithms?
What do you think?

Can we solve all-pair shortest paths by running a
single source-paths algorithms?

All-pair shortest paths.
• Nonnegative edge weight
   Dijkstra’s algorithm: Running time Array ������ ������������
What do you think?

Can we solve all-pair shortest paths by running a
single source-paths algorithms?

All-pair shortest paths.
• Nonnegative edge weight
   Dijkstra’s algorithm: Running time Array ������ ������������
                         Running time Binary heap ������( ������������ + ������������ log ������)
What do you think?

Can we solve all-pair shortest paths by running a
single source-paths algorithms?

All-pair shortest paths.
• Nonnegative edge weight
   Dijkstra’s algorithm: Running time Array ������ ������������
                         Running time Binary heap ������( ������������ + ������������ log ������)
                         Running time Binary heap ������ ������������ + ������������ log ������
What do you think?

Can we solve all-pair shortest paths by running a
single source-paths algorithms?

All-pair shortest paths.
• Nonnegative edge weight
   Dijkstra’s algorithm: Running time Array ������ ������������
                         Running time Binary heap ������( ������������ + ������������ log ������)
                         Running time Binary heap ������ ������������ + ������������ log ������
• General.
   Bellman-Ford: Running time ������ ������������ ������
What do you think?

Can we solve all-pair shortest paths by running a
single source-paths algorithms?

All-pair shortest paths.
• Nonnegative edge weight
   Dijkstra’s algorithm: Running time Array ������ ������������
                         Running time Binary heap ������( ������������ + ������������ log ������)
                         Running time Binary heap ������ ������������ + ������������ log ������
• General.
   Bellman-Ford: Running time ������ ������������ ������
   In a dense graph ������ ������������
Predecessor Matrix

Let ������ = ������������������ the predecessor Matrix, where

         ������������������       ������������ ������ = ������ ������������ ������������������������������ ������������ ������������ ������������������������ ������������������������ ������ ������������ ������
������������������ =
           ������������������ ������������������������������������������������������������������ ������������ ������ ������������ ������������������������ ������. ������ ������������������������ ������.

Now we define the predecessor subgraph of G for ������ as
������������,������ = (������������,������ , ������������,������ ).


Where ������������,������ = ������ ∈ ������: ������������������ ≠ ������������������ ∪ ������
          ������������,������ =     ������������������ , ������ : ������ ∈ ������������,������ − {������}
Predecessor Matrix
Outline

1. Present a dynamic programming algorithms based on
   matrix multiplication to solve the problem.

2. Dynamic programming algorithms called Floyd-Warshall
   algorithms.

3. Unlike the others algorithms, Johnson's algorithms used
   adjacency-list representation of a graph.
Shortest path and matrix multiplication

1. The structure of shortest path.
Let suppose that we have a shortest path ������ form vertix ������ to
vertex ������, and suppose that ������ have at most ������ < ∞ edge.

• If ������ = ������ then ������ have weight 0.

• If ������ ≠ ������ then ������ ↝������′ ������ → ������, where ������′ has at most ������ − ������ edge,
  by lemma 24.1 ������′ is a shortest path from ������ ������������ ������.
  So ������ ������, ������ = ������ ������, ������ + ������������������ .
Shortest path and matrix multiplication (cont.)

2. A recursive solution.
Let ������������������ (������) be the minimum weight of any path from vertex ������ to vertex
������ that contains at most ������ edge.
           (������)     ������ ������������ ������ = ������
• ������������������          =
                    ∞ ������������ ������ ≠ ������


• ������������������ (������) = min(������������������      ������−������
                                        , min ������������������ (������−������) + ������������������ )
                                       1≤������≤������
                                  (������−������)
                   = min ������������������            + ������������������
                      1≤������≤������


 ������ ������, ������ = ������������������ (������−������) = ������������������ (������) = ������������������ (������+������) = ⋯
Shortest path and matrix multiplication (cont.)

3. Computing shortest-path weight bottom up
Input ������ = (������������������ ).                We compute ������������ , ������������ , … , ������������−������ .
             ������������ = (������������������ (������) ) ������������������������������ ������ = ������, ������, … , ������ − ������.
Shortest path and matrix multiplication (cont.)

• Now we can see the relation to the matrix multiplication.
Let ������ = ������ ∗ ������ the matrix product of ������������������. For ������, ������ = ������, … , ������.
We have ������������������ = ������ ������������������ ∗ ������������������ .
                   ������=������


If we set; ������(������−������) → ������                 ������ → ������
           ������������ → ������                      ������������������ → +
           +→∗

                                          ������������������ ← ������������������ + ������������������ ∗ ������������������
Shortest path and matrix multiplication (cont.)




Computing the sequence of ������ − ������ matrix
                     ������(������) = ������(������) ∗ ������ = ������
                    ������(������) = ������(������) ∗ ������ = ������������
                                   ⋮
               ������(������−������) = ������(������−������) ∗ ������ = ������������−������
Shortest path and matrix multiplication (cont.)




• Improving the running time.

Our goal, is to compute ������������−������ matrices, let go to see that we
can compute ������������−������ with only log( ������ − ������) matrix product.
Shortest path and matrix multiplication (cont.)




������(������) = ������
������(������) = ������(������) = ������ ∗ ������
������(������) = ������(������) = ������������ ∗ ������������
������(������) = ������(������) = ������������ ∗ ������������
⋮
      log ������−������ )         log ������−������ )        log ������−������ −������        log ������−������ −������
������(������             = ������(������             = ������������               ∗ ������������
Shortest path and matrix multiplication (cont.)
The Floyd-Warshall algorithm
The algorithm consider a intermediate vertices of a shortest
path.
1. The structure of a shortest path.
Intermediate vertex ������ =< ������������ , ������������ , … , ������������ > in a any vertex of ������
other than ������������ or ������������ , so it can be the set ������������ , … , ������������−������ .
Let assume that the vertex of ������ are ������ = ������, ������, … , ������ and a
subset ������, ������, … , ������ for some ������.

• If ������ ∉ ������������������ of path ������, then all the vertices intermediate ������
  are in the set ������, ������, … , ������ − ������ . Thus, a shortest path from
  vertex ������ to vertex ������ with all intermediate vertices in the set
   ������, ������, … , ������ − ������ is also a shortest path form ������ to ������ with all
  ������������������ in the set ������, ������, … , ������ .
The Floyd-Warshall algorithm (cont)

• If ������ ∈ ������������������ of path ������, we break ������ down into ������ ↝������������ ������ ↝������������ ������.
  ������������ is a shortest path from ������ to ������, so ������ ∉ ������������������ of ������������ , thus ������������ is
  a shortest path form ������ to ������ with all ������������ in the set
   ������, ������, … , ������ − ������ . Similarly ������������ is a shortest path form ������ to ������
  with all ������������ in the set ������, ������, … , ������ − ������ .
The Floyd-Warshall algorithm (cont)

3. A recursive solution.


                                      ������������������                  ������������ ������ = ������
          (������)
 ������������������          =                ������−������              ������−������              ������−������
                     min ������������������           , ������������������           + ������������������           ������������ ������ ≥ ������


Since for every path, all intermediate vertices are in the set
 ������, ������, … , ������ , matriz ������(������) = (������������������ (������) ) gives the final answer:
������������������ (������) = ������ ������, ������ .
The Floyd-Warshall algorithm (cont)

• input: A ������ ������ ������ matrix ������
• output: A ������ ������ ������ matrix ������(������) of shortest path weight.


• ������������������ (������) = min ������������������   ������−������
                                     , ������������������   ������−������
                                                        + ������������������   ������−������
The Floyd-Warshall algorithm (cont)
The Floyd-Warshall algorithm (cont)
4. Constructing a Shortest path
We compute the predecessor matrix ������ just as the Floyd-warshall algorithm
compute the matrices ������(������) .
so ������ = ������(������) = (������������������ (������) ).

Recursive formulation.

                                               ������−������              ������−������              ������−������
                   ������������������ (������)   ������������ ������������������           ≤ ������������������           + ������������������
������������������ (������) =                                  ������−������              ������−������              ������−������
                   ������������������ (������) ������������ ������������������             > ������������������           + ������������������


         (������)
                    ������������������          ������������ ������ = ������ ������������ ������������������ = ∞.
������������������          =
                  ������               ������������ ������ ≠ ������ ������������������ ������������������ < ∞.
Johnson's algorithm for sparse graphs.


• It is asymtoticaly better than repeated squaring of matrices
  or the Floyd-Warshall algoritm.

• It use a subroutine both Dijkstra’s algorithm and Bellman-
  Ford algorithm.

• Johnson's algorithm use the technique of reweighting.
Johnson's algorithm for sparse graphs (cont.).

Reweighting
If ������ has a negative weight edge but no negative weight cycle,
we compute a new set of nonnegative edge weight ������ that
allow as to use Dijkstra’s algorithm.

The new set of edge must satisfy two condition.
1. ������(������) is a shortest path form ������ ������ ������ ⇔ ������(������) is a shortest
   path form ������ ������ ������ .
2. For all edges (������, ������), the new weight ������(������, ������) is
   nonnegative.
Johnson's algorithm for sparse graphs (cont.).



• Lemma
Give a weighted, directed graph ������ = (������, ������) with weight
funtion ������: ������ → ℝ be any funtion mapping vertices to real
numbers. For each edge (������, ������) ∈ ������, define.

              ������ ������, ������ = ������ ������, ������ + ������ ������ − ������ ������ .
Johnson's algorithm for sparse graphs (cont.).
• Producing no negative weight by reweighting
Johnson's algorithm for sparse graphs (cont.).
Johnson's algorithm for sparse graphs (cont.).

More Related Content

What's hot

What's hot (20)

Greedy algorithm
Greedy algorithmGreedy algorithm
Greedy algorithm
 
Simplex Method
Simplex MethodSimplex Method
Simplex Method
 
Dijkstra’s algorithm
Dijkstra’s algorithmDijkstra’s algorithm
Dijkstra’s algorithm
 
Dynamic Programming Matrix Chain Multiplication
Dynamic Programming Matrix Chain MultiplicationDynamic Programming Matrix Chain Multiplication
Dynamic Programming Matrix Chain Multiplication
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
03.Scan Conversion.ppt
03.Scan Conversion.ppt03.Scan Conversion.ppt
03.Scan Conversion.ppt
 
Modelos de redes completo
Modelos de redes   completoModelos de redes   completo
Modelos de redes completo
 
1.9. minimization of dfa
1.9. minimization of dfa1.9. minimization of dfa
1.9. minimization of dfa
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Unit 7 dynamic programming
Unit 7   dynamic programmingUnit 7   dynamic programming
Unit 7 dynamic programming
 
Bellman ford algorithm
Bellman ford algorithmBellman ford algorithm
Bellman ford algorithm
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
Dynamic pgmming
Dynamic pgmmingDynamic pgmming
Dynamic pgmming
 
Optimal Solution by MODI Method
Optimal Solution by MODI MethodOptimal Solution by MODI Method
Optimal Solution by MODI Method
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
Dijkstra's Algorithm
Dijkstra's AlgorithmDijkstra's Algorithm
Dijkstra's Algorithm
 
simplex method
simplex methodsimplex method
simplex method
 
Operation Research (Simplex Method)
Operation Research (Simplex Method)Operation Research (Simplex Method)
Operation Research (Simplex Method)
 
Theory of Computation "Chapter 1, introduction"
Theory of Computation "Chapter 1, introduction"Theory of Computation "Chapter 1, introduction"
Theory of Computation "Chapter 1, introduction"
 
El problema de la mochila
El problema de la mochilaEl problema de la mochila
El problema de la mochila
 

Similar to My presentation all shortestpath

04 greedyalgorithmsii 2x2
04 greedyalgorithmsii 2x204 greedyalgorithmsii 2x2
04 greedyalgorithmsii 2x2MuradAmn
 
Single source stortest path bellman ford and dijkstra
Single source stortest path bellman ford and dijkstraSingle source stortest path bellman ford and dijkstra
Single source stortest path bellman ford and dijkstraRoshan Tailor
 
Algorithm Design and Complexity - Course 10
Algorithm Design and Complexity - Course 10Algorithm Design and Complexity - Course 10
Algorithm Design and Complexity - Course 10Traian Rebedea
 
unit-4-dynamic programming
unit-4-dynamic programmingunit-4-dynamic programming
unit-4-dynamic programminghodcsencet
 
snarks <3 hash functions
snarks <3 hash functionssnarks <3 hash functions
snarks <3 hash functionsRebekah Mercer
 
CPSC125 ch6 sec3
CPSC125 ch6 sec3CPSC125 ch6 sec3
CPSC125 ch6 sec3David Wood
 
AAC ch 3 Advance strategies (Dynamic Programming).pptx
AAC ch 3 Advance strategies (Dynamic Programming).pptxAAC ch 3 Advance strategies (Dynamic Programming).pptx
AAC ch 3 Advance strategies (Dynamic Programming).pptxHarshitSingh334328
 
chapter1 (1).ppt
chapter1 (1).pptchapter1 (1).ppt
chapter1 (1).pptNateHigger
 
Introduction to the AKS Primality Test
Introduction to the AKS Primality TestIntroduction to the AKS Primality Test
Introduction to the AKS Primality TestPranshu Bhatnagar
 
Applied Algorithms and Structures week999
Applied Algorithms and Structures week999Applied Algorithms and Structures week999
Applied Algorithms and Structures week999fashiontrendzz20
 

Similar to My presentation all shortestpath (20)

04 greedyalgorithmsii 2x2
04 greedyalgorithmsii 2x204 greedyalgorithmsii 2x2
04 greedyalgorithmsii 2x2
 
Single source stortest path bellman ford and dijkstra
Single source stortest path bellman ford and dijkstraSingle source stortest path bellman ford and dijkstra
Single source stortest path bellman ford and dijkstra
 
(148065320) dijistra algo
(148065320) dijistra algo(148065320) dijistra algo
(148065320) dijistra algo
 
1535 graph algorithms
1535 graph algorithms1535 graph algorithms
1535 graph algorithms
 
Chap10 slides
Chap10 slidesChap10 slides
Chap10 slides
 
Algorithm Design and Complexity - Course 10
Algorithm Design and Complexity - Course 10Algorithm Design and Complexity - Course 10
Algorithm Design and Complexity - Course 10
 
unit-4-dynamic programming
unit-4-dynamic programmingunit-4-dynamic programming
unit-4-dynamic programming
 
Algorithms Lab PPT
Algorithms Lab PPTAlgorithms Lab PPT
Algorithms Lab PPT
 
snarks <3 hash functions
snarks <3 hash functionssnarks <3 hash functions
snarks <3 hash functions
 
Unit 3
Unit 3Unit 3
Unit 3
 
Unit 3
Unit 3Unit 3
Unit 3
 
CPSC125 ch6 sec3
CPSC125 ch6 sec3CPSC125 ch6 sec3
CPSC125 ch6 sec3
 
Cpsc125 ch6sec3
Cpsc125 ch6sec3Cpsc125 ch6sec3
Cpsc125 ch6sec3
 
AAC ch 3 Advance strategies (Dynamic Programming).pptx
AAC ch 3 Advance strategies (Dynamic Programming).pptxAAC ch 3 Advance strategies (Dynamic Programming).pptx
AAC ch 3 Advance strategies (Dynamic Programming).pptx
 
The Floyd–Warshall algorithm
The Floyd–Warshall algorithmThe Floyd–Warshall algorithm
The Floyd–Warshall algorithm
 
chapter1 (1).ppt
chapter1 (1).pptchapter1 (1).ppt
chapter1 (1).ppt
 
chapter1.ppt
chapter1.pptchapter1.ppt
chapter1.ppt
 
Introduction to the AKS Primality Test
Introduction to the AKS Primality TestIntroduction to the AKS Primality Test
Introduction to the AKS Primality Test
 
Applied Algorithms and Structures week999
Applied Algorithms and Structures week999Applied Algorithms and Structures week999
Applied Algorithms and Structures week999
 
DAA_Presentation - Copy.pptx
DAA_Presentation - Copy.pptxDAA_Presentation - Copy.pptx
DAA_Presentation - Copy.pptx
 

Recently uploaded

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 

Recently uploaded (20)

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 

My presentation all shortestpath

  • 1. All-Pairs Shortest Path Theory and Algorithms Carlos Andres Theran Suarez Program Mathematics and Scientific Computing University of Puerto Rico Carlos.theran@upr.edu October – 2011 Mayaguez-Puerto Rico Dr Marko Schütz
  • 2. Introduction • In this section we consider de problem of finding shortest path between all pair of vertices in a directed graph ������ = (������, ������). – With a weight function ������: ������ → ℝ ������ ������ = ������−������ ������(������������ , ������������+������ ) where ������ ∈ ������ ������������������ ������ ∈ ℕ. ������=������ For this goal we are going to use the adjacency-matrix of a graph. • The input: is a ������ ������ ������ ������������������������������������ ������������������������������������ ������ = ������������������ which is adjacency-matrix of a ������ = ������, ������ . • The output: is the ������ ������ ������ matrix of SPL ������ ������, ������ , ∀������������ ∈ ������.
  • 3. Recall • Single-Source shortest paths. • Nonnegative edge weight. – Dijkstra’s algorithm: Running time Array ������ ������������ Running time Binary heap ������( ������ + ������ log ������) Running time Fibonacci heap ������(������ + ������ log ������) • General. – Bellman-Ford: Running time ������ ������������ • UDG. – Breadth for search: Running time ������ ������ + ������
  • 4. What do you think? Can we solve all-pair shortest paths by running a single source-paths algorithms?
  • 5. What do you think? Can we solve all-pair shortest paths by running a single source-paths algorithms? All-pair shortest paths. • Nonnegative edge weight Dijkstra’s algorithm: Running time Array ������ ������������
  • 6. What do you think? Can we solve all-pair shortest paths by running a single source-paths algorithms? All-pair shortest paths. • Nonnegative edge weight Dijkstra’s algorithm: Running time Array ������ ������������ Running time Binary heap ������( ������������ + ������������ log ������)
  • 7. What do you think? Can we solve all-pair shortest paths by running a single source-paths algorithms? All-pair shortest paths. • Nonnegative edge weight Dijkstra’s algorithm: Running time Array ������ ������������ Running time Binary heap ������( ������������ + ������������ log ������) Running time Binary heap ������ ������������ + ������������ log ������
  • 8. What do you think? Can we solve all-pair shortest paths by running a single source-paths algorithms? All-pair shortest paths. • Nonnegative edge weight Dijkstra’s algorithm: Running time Array ������ ������������ Running time Binary heap ������( ������������ + ������������ log ������) Running time Binary heap ������ ������������ + ������������ log ������ • General. Bellman-Ford: Running time ������ ������������ ������
  • 9. What do you think? Can we solve all-pair shortest paths by running a single source-paths algorithms? All-pair shortest paths. • Nonnegative edge weight Dijkstra’s algorithm: Running time Array ������ ������������ Running time Binary heap ������( ������������ + ������������ log ������) Running time Binary heap ������ ������������ + ������������ log ������ • General. Bellman-Ford: Running time ������ ������������ ������ In a dense graph ������ ������������
  • 10. Predecessor Matrix Let ������ = ������������������ the predecessor Matrix, where ������������������ ������������ ������ = ������ ������������ ������������������������������ ������������ ������������ ������������������������ ������������������������ ������ ������������ ������ ������������������ = ������������������ ������������������������������������������������������������������ ������������ ������ ������������ ������������������������ ������. ������ ������������������������ ������. Now we define the predecessor subgraph of G for ������ as ������������,������ = (������������,������ , ������������,������ ). Where ������������,������ = ������ ∈ ������: ������������������ ≠ ������������������ ∪ ������ ������������,������ = ������������������ , ������ : ������ ∈ ������������,������ − {������}
  • 12. Outline 1. Present a dynamic programming algorithms based on matrix multiplication to solve the problem. 2. Dynamic programming algorithms called Floyd-Warshall algorithms. 3. Unlike the others algorithms, Johnson's algorithms used adjacency-list representation of a graph.
  • 13. Shortest path and matrix multiplication 1. The structure of shortest path. Let suppose that we have a shortest path ������ form vertix ������ to vertex ������, and suppose that ������ have at most ������ < ∞ edge. • If ������ = ������ then ������ have weight 0. • If ������ ≠ ������ then ������ ↝������′ ������ → ������, where ������′ has at most ������ − ������ edge, by lemma 24.1 ������′ is a shortest path from ������ ������������ ������. So ������ ������, ������ = ������ ������, ������ + ������������������ .
  • 14. Shortest path and matrix multiplication (cont.) 2. A recursive solution. Let ������������������ (������) be the minimum weight of any path from vertex ������ to vertex ������ that contains at most ������ edge. (������) ������ ������������ ������ = ������ • ������������������ = ∞ ������������ ������ ≠ ������ • ������������������ (������) = min(������������������ ������−������ , min ������������������ (������−������) + ������������������ ) 1≤������≤������ (������−������) = min ������������������ + ������������������ 1≤������≤������ ������ ������, ������ = ������������������ (������−������) = ������������������ (������) = ������������������ (������+������) = ⋯
  • 15. Shortest path and matrix multiplication (cont.) 3. Computing shortest-path weight bottom up Input ������ = (������������������ ). We compute ������������ , ������������ , … , ������������−������ . ������������ = (������������������ (������) ) ������������������������������ ������ = ������, ������, … , ������ − ������.
  • 16. Shortest path and matrix multiplication (cont.) • Now we can see the relation to the matrix multiplication. Let ������ = ������ ∗ ������ the matrix product of ������������������. For ������, ������ = ������, … , ������. We have ������������������ = ������ ������������������ ∗ ������������������ . ������=������ If we set; ������(������−������) → ������ ������ → ������ ������������ → ������ ������������������ → + +→∗ ������������������ ← ������������������ + ������������������ ∗ ������������������
  • 17. Shortest path and matrix multiplication (cont.) Computing the sequence of ������ − ������ matrix ������(������) = ������(������) ∗ ������ = ������ ������(������) = ������(������) ∗ ������ = ������������ ⋮ ������(������−������) = ������(������−������) ∗ ������ = ������������−������
  • 18. Shortest path and matrix multiplication (cont.) • Improving the running time. Our goal, is to compute ������������−������ matrices, let go to see that we can compute ������������−������ with only log( ������ − ������) matrix product.
  • 19. Shortest path and matrix multiplication (cont.) ������(������) = ������ ������(������) = ������(������) = ������ ∗ ������ ������(������) = ������(������) = ������������ ∗ ������������ ������(������) = ������(������) = ������������ ∗ ������������ ⋮ log ������−������ ) log ������−������ ) log ������−������ −������ log ������−������ −������ ������(������ = ������(������ = ������������ ∗ ������������
  • 20. Shortest path and matrix multiplication (cont.)
  • 21. The Floyd-Warshall algorithm The algorithm consider a intermediate vertices of a shortest path. 1. The structure of a shortest path. Intermediate vertex ������ =< ������������ , ������������ , … , ������������ > in a any vertex of ������ other than ������������ or ������������ , so it can be the set ������������ , … , ������������−������ . Let assume that the vertex of ������ are ������ = ������, ������, … , ������ and a subset ������, ������, … , ������ for some ������. • If ������ ∉ ������������������ of path ������, then all the vertices intermediate ������ are in the set ������, ������, … , ������ − ������ . Thus, a shortest path from vertex ������ to vertex ������ with all intermediate vertices in the set ������, ������, … , ������ − ������ is also a shortest path form ������ to ������ with all ������������������ in the set ������, ������, … , ������ .
  • 22. The Floyd-Warshall algorithm (cont) • If ������ ∈ ������������������ of path ������, we break ������ down into ������ ↝������������ ������ ↝������������ ������. ������������ is a shortest path from ������ to ������, so ������ ∉ ������������������ of ������������ , thus ������������ is a shortest path form ������ to ������ with all ������������ in the set ������, ������, … , ������ − ������ . Similarly ������������ is a shortest path form ������ to ������ with all ������������ in the set ������, ������, … , ������ − ������ .
  • 23. The Floyd-Warshall algorithm (cont) 3. A recursive solution. ������������������ ������������ ������ = ������ (������) ������������������ = ������−������ ������−������ ������−������ min ������������������ , ������������������ + ������������������ ������������ ������ ≥ ������ Since for every path, all intermediate vertices are in the set ������, ������, … , ������ , matriz ������(������) = (������������������ (������) ) gives the final answer: ������������������ (������) = ������ ������, ������ .
  • 24. The Floyd-Warshall algorithm (cont) • input: A ������ ������ ������ matrix ������ • output: A ������ ������ ������ matrix ������(������) of shortest path weight. • ������������������ (������) = min ������������������ ������−������ , ������������������ ������−������ + ������������������ ������−������
  • 26. The Floyd-Warshall algorithm (cont) 4. Constructing a Shortest path We compute the predecessor matrix ������ just as the Floyd-warshall algorithm compute the matrices ������(������) . so ������ = ������(������) = (������������������ (������) ). Recursive formulation. ������−������ ������−������ ������−������ ������������������ (������) ������������ ������������������ ≤ ������������������ + ������������������ ������������������ (������) = ������−������ ������−������ ������−������ ������������������ (������) ������������ ������������������ > ������������������ + ������������������ (������) ������������������ ������������ ������ = ������ ������������ ������������������ = ∞. ������������������ = ������ ������������ ������ ≠ ������ ������������������ ������������������ < ∞.
  • 27. Johnson's algorithm for sparse graphs. • It is asymtoticaly better than repeated squaring of matrices or the Floyd-Warshall algoritm. • It use a subroutine both Dijkstra’s algorithm and Bellman- Ford algorithm. • Johnson's algorithm use the technique of reweighting.
  • 28. Johnson's algorithm for sparse graphs (cont.). Reweighting If ������ has a negative weight edge but no negative weight cycle, we compute a new set of nonnegative edge weight ������ that allow as to use Dijkstra’s algorithm. The new set of edge must satisfy two condition. 1. ������(������) is a shortest path form ������ ������ ������ ⇔ ������(������) is a shortest path form ������ ������ ������ . 2. For all edges (������, ������), the new weight ������(������, ������) is nonnegative.
  • 29. Johnson's algorithm for sparse graphs (cont.). • Lemma Give a weighted, directed graph ������ = (������, ������) with weight funtion ������: ������ → ℝ be any funtion mapping vertices to real numbers. For each edge (������, ������) ∈ ������, define. ������ ������, ������ = ������ ������, ������ + ������ ������ − ������ ������ .
  • 30. Johnson's algorithm for sparse graphs (cont.). • Producing no negative weight by reweighting
  • 31. Johnson's algorithm for sparse graphs (cont.).
  • 32. Johnson's algorithm for sparse graphs (cont.).