Shortest Path - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

Shortest Path

Description:

Shortest Path. Dijkstra's Algorithm. finds the shortest path from the start ... To find the shortest path from A to G, start from G and work backwards, using ... – PowerPoint PPT presentation

Number of Views:35
Avg rating:3.0/5.0
Slides: 18
Provided by: johns345
Category:
Tags: path | shortest

less

Transcript and Presenter's Notes

Title: Shortest Path


1
Shortest Path
2
Dijkstras Algorithmfinds the shortest path
from the start vertex to every other vertex in
the network. We will find the shortest path from
A to G
B
F
D
A
G
E
C
3
Dijkstras Algorithm
  • Label the start vertex with permanent label 0 and
    order label 1
  • Assign temporary labels to all the vertices that
    can be reached directly from the start
  • Select the vertex with the smallest temporary
    label and make its label permanent. Add the
    correct order label.
  • Put temporary labels on each vertex that can be
    reached directly from the vertex you have just
    made permanent. The temporary label must be equal
    to the sum of the permanent label and the direct
    distance from it. If there is an existing
    temporary label at a vertex, it should be
    replaced only if the new sum is smaller.
  • Select the vertex with the smallest temporary
    label and make its label permanent by boxing it.
  • Repeat until the finishing vertex has a permanent
    (boxed) label.
  • To find the shortest paths(s), trace back from
    the end vertex to the start vertex. Write the
    route forwards and state the length.

4
Dijkstras Algorithm
Label A as 0 and box this number
0
5
Dijkstras Algorithm
We update each vertex adjacent to A with a
working value for its distance from A and
indicate the route is from A
4A
7A
0
3A
6
Dijkstras Algorithm
4A
7A
0
Vertex C is closest to A so we give it a box this.
3A
7
Dijkstras Algorithm
We update each vertex adjacent to C with a
working value for its total distance from A, by
adding its distance from C to Cs permanent label
of 3.
6 lt 7 so replace the label here
6C
8C
8
Dijkstras Algorithm
The vertex with the smallest temporary label is
B, so box this.
9
Dijkstras Algorithm
We update each vertex adjacent to B with a
working value for its total distance from A, by
adding its distance from B to Bs permanent label
of 4.
8B
5 lt 6 so replace the label here
5B
10
Dijkstras Algorithm
The vertex with the smallest temporary label is
D, so box this.
11
Dijkstras Algorithm
We update each vertex adjacent to D with a
working value for its total distance from A, by
adding its distance from D to Ds permanent label
of 5.
7D
7 lt 8 so replace the label here
7 lt 8 so replace the label here
12D
7D
12
Dijkstras Algorithm
The vertices with the smallest temporary labels
are E and F, so choose one and box it.
13
Dijkstras Algorithm
We update each vertex adjacent to E with a
working value for its total distance from A, by
adding its distance from E to Es permanent label
of 7.
9E
9 lt 12 so replace the label here
14
Dijkstras Algorithm
The vertex with the smallest temporary label is
F, so make box this.
9E
15
Dijkstras Algorithm
We update each vertex adjacent to F with a
working value for its total distance from A, by
adding its distance from F to Fs permanent label
of 7.
9E
11 gt 9 so do not replace the t-label here
16
Dijkstras Algorithm
G is the final vertex to be boxed.
17
Dijkstras Algorithm
To find the shortest path from A to G, start from
G and work backwards, using the letters on in the
boxes.
The shortest path is ABDEG, with length 9.
Write a Comment
User Comments (0)
About PowerShow.com