CSE 780: Design and Analysis of Algorithms - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

CSE 780: Design and Analysis of Algorithms

Description:

All-pairs Shortest Paths. Use Bellman-Ford V ... O( log V VE) Can we do better for general graphs ... Optimal substructure property holds. Define subproblem: ... – PowerPoint PPT presentation

Number of Views:90
Avg rating:3.0/5.0
Slides: 13
Provided by: tri5133
Category:

less

Transcript and Presenter's Notes

Title: CSE 780: Design and Analysis of Algorithms


1
CSE 780 Design and Analysis of Algorithms
  • Lecture 20
  • All-pairs SPs
  • DP algorithm
  • Floyd-Warshall alg.

2
All-pairs Shortest Paths
  • Use Bellman-Ford V times
  • O ( E )
  • Non-negative weights
  • Use Dijkstras alg. V times
  • O( log V VE)
  • Can we do better for general graphs
  • i.e., weighted directed graph with possible
    negative weights

3
Terminologies
  • G (V, E) where V are numbered 1, 2, .. nV
  • Input , n ? n matrix
  • Output , n ? n matrix

4
Dynamic Programming Approach
  • Optimal substructure property holds
  • Define subproblem
  • minimum weight of any path from vertex i
    to j that contains at most m edges.
  • Recursive solution
  • Base case m 0

5
Recursive Solution cont.
  • Goal

6
Build DP-table
  • Compute in
    order

7
Pseudo-code cont.
Can we do better ?
  • Time complexity

8
Matrix Multiplication
  • Extend procedure
  • same as matrix multiplication (w/ a twist) !
  • L L W !

9
Faster Algorithm
10
Floyd-Warshall Algorithm
  • Yet another DP algorithm
  • Why was previous algorithm slow?
  • In the recursive solution, needs to spend O(n)
    time for each new entry
  • Floyd-Warshall algorithm
  • Use a different recursive solution O(1) time to
    compute each entry

11
Problem Definition
  • Subproblem definition
  • the weight of shortest path from
    vertex i to j where all intermediate vertices are
    from set 1, 2, , k.

12
Pseudo-code
Write a Comment
User Comments (0)
About PowerShow.com