Introduction to Algorithms - PowerPoint PPT Presentation

Loading...

PPT – Introduction to Algorithms PowerPoint presentation | free to download - id: 685213-YmMzZ



Loading


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

Introduction to Algorithms

Description:

Introduction to Algorithms All-Pairs Shortest Paths My T. Thai _at_ UF Single-Source Shortest Paths Problem Input: A weighted, directed graph G = (V, E) Output: An n ... – PowerPoint PPT presentation

Number of Views:82
Avg rating:3.0/5.0
Slides: 25
Provided by: MYTRATHAI
Learn more at: http://www.cise.ufl.edu
Category:

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: Introduction to Algorithms


1
Introduction to Algorithms
  • All-Pairs Shortest Paths
  • My T. Thai _at_ UF

2
Single-Source Shortest Paths Problem
  • Input A weighted, directed graph G (V, E)
  • Output An n n matrix of shortest-path
    distances d. d(i, j) is the weight of a shortest
    path from i to j.

1 2 3 4 5
1 0 1 -3 2 -4
2 3 0 -4 1 -1
3 7 4 0 5 3
4 2 -1 -5 0 -2
5 8 5 1 6 0
3
  • Can use algorithms for Single-Source Shortest
    Paths
  • Run BELLMAN-FORD once from each vertex
  • Time
  • If there are no negative-weight edges, could run
    Dijkstras algorithm once from each vertex
  • Time

4
Outline
  • Shortest paths and matrix multiplication
  • Floyd-Warshall algorithm
  • Johnsons algorithm

5
Recursive solution
  • Optimal substructure subpaths of shortest paths
    are shortest paths
  • Recursive solution Let weight of shortest
    path from i to j that contains m edges.
  • Where wij

6
Computing the shortest-path weights bottom up
  • All simple shortest paths contain n - 1 edges
  • Compute from bottom up L(1), L(2), . . . ,
    L(n-1).
  • Compute L(i1) from
  • L(i) by extending one
  • more edge
  • Time

7
  • Time

8
Shortest paths and matrix multiplication
  • Extending shortest paths by one more edge likes
    matrix product L(i1) L(i).W
  • Compute L(1), L(2), L(4) . . . , L(r) with

Time
9
Example
10
Floyd-Warshall algorithm
  • For path p ltv1, v2, . . . , vlgt , v2 vl-1 are
    intermediate vertices from v1 to vl
  • Define shortest-path weight of any path
    from i to j with all intermediate vertices in
    1, 2, . . . , k
  • Consider a shortest path with all
    intermediate vertices in 1, 2, . . . , k
  • If k is not an intermediate vertex, all
    intermediate vertices in 1, 2, . . . , k -1
  • If k is an intermediate vertex

11
Floyd-Warshall algorithm
  • Recursive formula
  • Time

Note since we have at most n vertices, return
12
Constructing a shortest path
  • is the predecessor of vertex j on a
    shortest path from vertex i with all intermediate
    vertices in the set 1, 2, . . . , k

(Use vertex k)
13
Example
14
(No Transcript)
15
(No Transcript)
16
Johnsons algorithm
  • Reweighting edges to get non-negative weight
    edges
  • For all u, v ? V, p is a shortest path
    using w if and only if p is a shortest path
    using
  • For all (u, v) ? E,
  • Run Dijkstras algorithm once from each vertex

17
Reweighting
18
Proof of lemma 25.1
  • First, we prove
  • With cycle ,

19
Producing nonnegative weights
  • Construct
  • Since no edges enter s, has the same set
    of cycles as G
  • has a negative-weight cycle if and only if
    G does
  • Define
  • Claim
  • Proof Triangle inequality of shortest paths

20
Johnsons algorithm
  • Time

21
Example
22
(No Transcript)
23
Summary
  • Dynamic-programming algorithm based on matrix
    multiplication
  • Define sub-optimal solutions based on the length
    of paths
  • Use the technique of repeated squaring
  • Time
  • Floyd-Warshall algorithm
  • Define sub-optimal solutions based on the set of
    allowed intermediate vertices
  • Time

24
  • Johnsons algorithm
  • Reweight edges to non-negative weight edges
  • Run Dijkstras algorithm once from each vertex
  • Time
  • Faster than Floyd-Warshall algorithm when the
    graph is dense E o(V2)
About PowerShow.com