Shortest path algorithms - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

Shortest path algorithms

Description:

The shortest path problem is to determine the path with the minimum path length from s to t. ... This algorithm is applicable to graphs with positive arc lengths. ... – PowerPoint PPT presentation

Number of Views:1405
Avg rating:3.0/5.0
Slides: 13
Provided by: ACE560
Category:

less

Transcript and Presenter's Notes

Title: Shortest path algorithms


1
Shortest path algorithms
  • Dijkstra (aka Shortest Path First (SPF))
  • Bellman-Ford (aka Ford-Fulkson)
  • Floyd-Warshall

2
Shortest path problem
  • For a directed graph G(N,A), each arc (x,y) has
    associated with it a number d(x,y) that
    represents the length (previously known as
    weight) of the arc.
  • The length of a path is defined as the sum of the
    lengths of the individual arcs comprising the
    path.
  • The shortest path problem is to determine the
    path with the minimum path length from s to t.

3
Dijkstra algorithm
  • This algorithm is applicable to graphs with
    positive arc lengths.
  • Given a source node, Dijkstra algorithm
    determines the shortest path to a specific node,
    or it can be run until the shortest paths to all
    nodes other than the source node has been found.
  • Let D(x) denote the the path length from node x
    to the source node.

4
Dijkstra algorithm (cont.)
  • The basic principle is illustrated as follows.
  • Denote those nodes to which the shortest path
    from the source has been found as permanent node,
    the other nodes tentative node. As the algorithm
    proceeds, each node is assigned either a
    tentative label or a permanent label
  • For those tentative nodes, the shortest path must
    be via some permanent node. Based on this
    principle, the shortest path from S to one of the
    tentative nodes can be determined.

shortest paths have been found for these nodes
shortest paths have NOT yet been found for these
nodes
D(y)
D(x)
y
x
d(y,x)
S
z
D(x)D(y)d(y,x) or d(s,x)
5
Dijkstra algorithm stated
  • Dijkstra algorithm can be stated as follows.
  • Step 0 The source node s is given a permanent
    label of (0,s) Assign tentative (t) labels (
    D(x)?, u(x) - ) to all nodes other than the
    source node where D(x) is the distance from
    source to this node over the (tentative) shortest
    path and u(x) is the upstream node in the
    shortest path. Let y denote the previous node
    that has been assigned a permanent label set
    ys.
  • Step 1 For each tentative node x, redefine d(x)
    as D(x) min D(x), D(y)d(y,x)
  • Step 2 Search over all the tentative labels and
    change the label of a node ( D(x), u(x) ) to
    permanent (p) if the D(x) is the smallest among
    all the tentative labels update u(x) as well.
  • Step 3 Set yx (update y) If the specific node
    has not yet been given a permanent label, go to
    step 2 otherwise stop (the shortest path from s
    to the specific node has been determined).

6
Dijkstra algorithm an example
3
A
B
2
Steps 2,3 Find p, y
2
4
7
S
T
3
2
3
D
C
Step 1 Update D(x)
7
Dijkstra algorithm an example (cont.)
Another example in flash movie
8
Bellman-Ford algorithm
  • Dijkstra algorithm cannot accommodate graphs with
    negative arc lengths.
  • Bellman-Ford algorithm includes some changes to
    Dijkstra algorithm.
  • In the i-th iteration, a set of nodes Y denotes
    the shortest paths with at most i arcs (known as
    the shortest ? i path).
  • In Step 1, compute ??D(x) minD(x),D(y)d(y,x)
    ?? for all nodes for y in Y.
  • Terminate the algorithm only after Step 1 fails
    to lower D(x) values of the nodes.

9
Bellman-Ford algorithm stated
  • Bellman-Ford algorithm can be stated as follows.
  • Step 0 The source node s is given a label of
    (0,s) Assign labels ( D(x)?, u(x) - ) to all
    nodes other than the source node where D(x) is
    the distance from source to this node over the
    shortest path and u(x) is the upstream node
    in the shortest path. Let Y be the set containing
    s.
  • Step 1 For each node x that are neighbor nodes
    (nodes that are adjacent to x) of a node in Y,
    redefine d(x) as D(x) min D(x), D(y)d(y,x)
    for y in Y.
  • Step 2 Stop if Step 1 does not lower the value
    of any D(X).
  • Step 3 Add x to the set Y. Go to Step 1.

10
Bellman-Ford algorithm an example
3
A
B
2
Steps 2,3 update Y
2
6
7
S
T
3
2
3
D
C
Step 1 Update D(x)
11
Bellman-Ford algorithm another example
Note that Bellman-Ford algorithm may fail if
there exits a cycle with negative total weights.
12
Floyd-Warshall algorithm
  • The Floyd-Warshall algorithm determines the
    shortest path between all pairs of nodes.
  • The arc distance can be negative.
  • The Floyd-Warshall algorithm iterates on the set
    of nodes that are allowed as intermediate nodes
    on the path.
Write a Comment
User Comments (0)
About PowerShow.com