SlideShare una empresa de Scribd logo
1 de 32
Descargar para leer sin conexión
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.).

Más contenido relacionado

La actualidad más candente

Introduction to Graph Theory
Introduction to Graph TheoryIntroduction to Graph Theory
Introduction to Graph TheoryYosuke Mizutani
 
Discrete Mathematical Structures - Fundamentals of Logic - Principle of duality
Discrete Mathematical Structures - Fundamentals of Logic - Principle of dualityDiscrete Mathematical Structures - Fundamentals of Logic - Principle of duality
Discrete Mathematical Structures - Fundamentals of Logic - Principle of dualityLakshmi R
 
Lecture 2 predicates quantifiers and rules of inference
Lecture 2 predicates quantifiers and rules of inferenceLecture 2 predicates quantifiers and rules of inference
Lecture 2 predicates quantifiers and rules of inferenceasimnawaz54
 
Algebraic Data Types for Data Oriented Programming - From Haskell and Scala t...
Algebraic Data Types forData Oriented Programming - From Haskell and Scala t...Algebraic Data Types forData Oriented Programming - From Haskell and Scala t...
Algebraic Data Types for Data Oriented Programming - From Haskell and Scala t...Philip Schwarz
 
Change of order in integration
Change of order in integrationChange of order in integration
Change of order in integrationShubham Sojitra
 
Unit26 shortest pathalgorithm
Unit26 shortest pathalgorithmUnit26 shortest pathalgorithm
Unit26 shortest pathalgorithmmeisamstar
 
Homogeneous Linear Differential Equations
 Homogeneous Linear Differential Equations Homogeneous Linear Differential Equations
Homogeneous Linear Differential EquationsAMINULISLAM439
 
FLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHONFLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHONvikram mahendra
 
Application of partial derivatives
Application of partial derivativesApplication of partial derivatives
Application of partial derivativesMaharshi Dave
 
The Functional Programmer's Toolkit (NDC London 2019)
The Functional Programmer's Toolkit (NDC London 2019)The Functional Programmer's Toolkit (NDC London 2019)
The Functional Programmer's Toolkit (NDC London 2019)Scott Wlaschin
 
File and directories in python
File and directories in pythonFile and directories in python
File and directories in pythonLifna C.S
 

La actualidad más candente (20)

Introduction to Graph Theory
Introduction to Graph TheoryIntroduction to Graph Theory
Introduction to Graph Theory
 
graph.ppt
graph.pptgraph.ppt
graph.ppt
 
Discrete Mathematical Structures - Fundamentals of Logic - Principle of duality
Discrete Mathematical Structures - Fundamentals of Logic - Principle of dualityDiscrete Mathematical Structures - Fundamentals of Logic - Principle of duality
Discrete Mathematical Structures - Fundamentals of Logic - Principle of duality
 
Lecture 2 predicates quantifiers and rules of inference
Lecture 2 predicates quantifiers and rules of inferenceLecture 2 predicates quantifiers and rules of inference
Lecture 2 predicates quantifiers and rules of inference
 
Algebraic Data Types for Data Oriented Programming - From Haskell and Scala t...
Algebraic Data Types forData Oriented Programming - From Haskell and Scala t...Algebraic Data Types forData Oriented Programming - From Haskell and Scala t...
Algebraic Data Types for Data Oriented Programming - From Haskell and Scala t...
 
MATCHING GRAPH THEORY
MATCHING GRAPH THEORYMATCHING GRAPH THEORY
MATCHING GRAPH THEORY
 
Change of order in integration
Change of order in integrationChange of order in integration
Change of order in integration
 
DM-unit-3.ppt
DM-unit-3.pptDM-unit-3.ppt
DM-unit-3.ppt
 
Unit26 shortest pathalgorithm
Unit26 shortest pathalgorithmUnit26 shortest pathalgorithm
Unit26 shortest pathalgorithm
 
Shortest path algorithms
Shortest path algorithmsShortest path algorithms
Shortest path algorithms
 
Data frame operations
Data frame operationsData frame operations
Data frame operations
 
Dijkstra
DijkstraDijkstra
Dijkstra
 
Homogeneous Linear Differential Equations
 Homogeneous Linear Differential Equations Homogeneous Linear Differential Equations
Homogeneous Linear Differential Equations
 
Applicative Functor
Applicative FunctorApplicative Functor
Applicative Functor
 
FLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHONFLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHON
 
Application of partial derivatives
Application of partial derivativesApplication of partial derivatives
Application of partial derivatives
 
dijkstra algo.ppt
dijkstra algo.pptdijkstra algo.ppt
dijkstra algo.ppt
 
The Functional Programmer's Toolkit (NDC London 2019)
The Functional Programmer's Toolkit (NDC London 2019)The Functional Programmer's Toolkit (NDC London 2019)
The Functional Programmer's Toolkit (NDC London 2019)
 
Graphs - Discrete Math
Graphs - Discrete MathGraphs - Discrete Math
Graphs - Discrete Math
 
File and directories in python
File and directories in pythonFile and directories in python
File and directories in python
 

Similar a My presentation all shortestpath

04 greedyalgorithmsii 2x2
04 greedyalgorithmsii 2x204 greedyalgorithmsii 2x2
04 greedyalgorithmsii 2x2MuradAmn
 
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
 
Single source shortes path in dag
Single source shortes path in dagSingle source shortes path in dag
Single source shortes path in dagKiran K
 

Similar a My presentation all shortestpath (20)

04 greedyalgorithmsii 2x2
04 greedyalgorithmsii 2x204 greedyalgorithmsii 2x2
04 greedyalgorithmsii 2x2
 
(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
 
Single source shortes path in dag
Single source shortes path in dagSingle source shortes path in dag
Single source shortes path in dag
 

Último

Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 

Último (20)

Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 

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