Shortest Path - PowerPoint PPT Presentation

About This Presentation
Title:

Shortest Path

Description:

Change Dijkstra's Algorithm (Slide 6) to compute the minimum distance from u to ... of 2.b (Page 323). Follow Dijkstra's Algorithm to compute the path from l ... – PowerPoint PPT presentation

Number of Views:1269
Avg rating:3.0/5.0
Slides: 10
Provided by: leh71
Category:

less

Transcript and Presenter's Notes

Title: Shortest Path


1
Shortest Path
Consider the following weighted undirected graph
20
22
20
10
16
9
7
6
18
2
8
24
4
5
6
66
10
20
Such that cost(5?v1) cost(v1? v2) cost (
?20) is minimum
2
How About Using the MST Algorithm?
20
22
20
10
16
9
7
6
18
2
8
24
4
5
6
66
10
20
  1. Compute the MST
  2. Take the path between the two nodes that goes
    through the MST

3
The Fringe
Given a Graph G (V,E) and T a subset of V, the
fringe of T, is defined as Fringe(T)
(w,x) in E w ? T and x ?V - T
4
Djikstra Algorithm Idea
  • We are computing a shortest path from node u to a
    node v
  • Start the algorithm with T u, construct
    Fringe(T)
  • At each iteration, select the (z,w) in Fringe(T)
    such that the path from u to w has the lowest
    cost
  • Stop when v is part of T (not of the fringe!)

5
Example
20
22
20
10
16
9
7
6
18
2
8
24
4
5
6
66
10
20
6
The Dijkstras Algorithm
// Input G (G,V), nodes u and v in V //output
Shortest path from u to v
T ? u F ? Fringe(u) ET ? While v is not
in the T do Choose (z,w) in F with the
shortest path (u, u1),
(u1,u2),, (un,z) (z,w) with (u, u1),
(u1,u2),, (un,z) in ET T ? T ? w
ET ? ET ? (z,w) for each (w,x)
(w,x) in E - ET do If no (w,x) in
F then F ? F ? (w,x) else

If the path u ? x going through (w,x) has less
weight than the path u?x going through
(w,x) then F ? ( F - (w,x)) ? (w,x)
7
Properties
Is Dijkstras Algorithm greedy?
Yes
Why Dijkstras Algorithm works?
8
Complexity
  • Actual complexity is O(Elog2 E)
  • It is easy to see that it is at most EV
    (i.e., E2)
  • the outer while is performed V times
  • the inner for is performed at most E times

9
Homework
  • 010
  • Write the pseudo-code for the algorithm inserting
    an element in a min-heap
  • Do the same for a Heap
  • Write the pseudo-code for isLeaf(i) (Slide 15 of
    class about Heaps)
  • Change Dijkstras Algorithm (Slide 6) to compute
    the minimum distance from u to every node in the
    graph
  • True or False the subgraph (T,ET) resulting from
    4 is an MST of the input graph
  • In the graph of 2.b (Page 323). Follow Dijkstras
    Algorithm to compute the path from c to l
  • 011
  • Write the pseudo-code for the algorithm deleting
    the element with the minimum priority value in a
    min-heap
  • Do the same but deleting the one with the highest
    priority for a Heap
  • Write the pseudo-code for Parent(i) (Slide 15 of
    class about Heaps)
  • Change Dijkstras Algorithm (Slide 6) to compute
    the minimum distance from u to every node in the
    graph
  • True or False the subgraph (T,ET) resulting from
    4 is a tree connecting all nodes of the input
    graph
  • In the graph of 2.b (Page 323). Follow Dijkstras
    Algorithm to compute the path from l to a
Write a Comment
User Comments (0)
About PowerShow.com