Shortest Path Algorithm 2 - PowerPoint PPT Presentation

Loading...

PPT – Shortest Path Algorithm 2 PowerPoint presentation | free to download - id: 12d711-YTQ3Y



Loading


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

Shortest Path Algorithm 2

Description:

Optimal substructure property. All sub-paths of shortest paths are shortest paths. ... d(x, y) d*(y, v) optimal substructure d*(s, x) d(x, y) nonnegative lengths ... – PowerPoint PPT presentation

Number of Views:112
Avg rating:3.0/5.0
Slides: 41
Provided by: Lee144
Learn more at: http://www.cs.sjsu.edu
Category:

less

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

Title: Shortest Path Algorithm 2


1
Shortest Path Algorithm 2
  • Prof. Sin-Min Lee
  • Department of Computer Science

2
(No Transcript)
3
(No Transcript)
4
(No Transcript)
5
(No Transcript)
6
(No Transcript)
7
(No Transcript)
8
(No Transcript)
9
(No Transcript)
10
(No Transcript)
11
(No Transcript)
12
(No Transcript)
13
(No Transcript)
14
(No Transcript)
15
(No Transcript)
16
(No Transcript)
17
(No Transcript)
18
(No Transcript)
19
(No Transcript)
20
(No Transcript)
21
(No Transcript)
22
(No Transcript)
23
Greed Shortest Path
3
2
23
9
s
18
14
6
2
6
4
19
30
11
5
15
5
6
20
16
t
7
44
24
Directed Graph
  • Directed graph G (V, E) .
  • V set of vertices or nodes.
  • E ? V ? V set of edges or arcs.
  • n V, m E.
  • Directed path s - 2 - 3 - 5 - t.
  • simple
  • Directed cycle 5 - 4 - 3 - 5.

25
Networks
Network
Nodes
Arcs
Flow
communication
telephone exchanges, computers, satellites
cables, fiber optics, microwave relays
voice, video, packets
circuits
gates, registers, processors
wires
current
mechanical
joints
rods, beams, springs
heat, energy
hydraulic
reservoirs, pumping stations, lakes
pipelines
fluid, oil
financial
stocks, currency
transactions
money
transportation
airports, rail yards, street intersections
highways, railbeds, airway routes
freight, vehicles, passengers
26
Shortest Path Network
  • Shortest path network (V, E, s, t, c) .
  • Directed graph (V, E).
  • Source s ? V, sink t ? V.
  • Arc costs c(v, w).
  • Cost of path sum of arc costs in path.

Cost of path s - 2 - 3 - 5 - t 9 2
16 48.
3
2
23
9
s
18
14
6
2
6
4
30
19
11
5
15
5
6
20
16
t
7
44
27
Shortest Path
  • Shortest path problem. Shortest path network (V,
    E, s, t, c).
  • Find shortest directed path from s to t.
  • Assumptions.
  • Network contains directed path from s to every
    other node.
  • Network does not contain a negative cost cycle.
  • Application.
  • Online directions.

3
-6
-4
7
4
5
28
Shortest Path Existence
  • Existence. If some path from s to v contains a
    negative cost cycle, there does not exist a
    shortest path. Otherwise, there exists a shortest
    s-v that is simple.
  • ? If negative cycle, can produce arbitrarily
    negative path by traversing cycle enough
    times.
  • ? If no negative cycle, can remove cycles
    without increasing cost.

C
s
v
c(C) lt 0
29
Shortest Path Properties
  • Optimal substructure property. All sub-paths of
    shortest paths are shortest paths.
  • Let P1 be x-y sub-path of shortest s-v path P.
  • Let P2 be any x-y path.
  • c(P1) ? c(P2), otherwise P not shortest s-v
    path.
  • Triangle inequality.
  • Let d(v, w) be the length of the shortest path
    from v to w.
  • Then, d(v, w) ? d(v, x) d(x, w)

30
Dijkstra's Algorithm
  • Upon termination.
  • ?(v) distance of
  • shortest s-v path.
  • pred(v) gives shortest
  • path.

decrease-key
31
Dijkstra's Algorithm Proof of Correctness
y
P
x
s
  • Invariant. For each vertex v ? S, ?(v) d(s,
    v).
  • Proof by induction on S.
  • Base case S 0 is trivial.

v
S
32
  • Induction step
  • ?(v) is the length of the some path from s to v
  • if ?(v) is not the length of the shortest s-v
    path, then let P be a shortest s-v path
  • P must use an edge that leaves S, say (x, y)
  • suppose Dijkstra's algorithm adds vertex v to S
  • then ?(v) gt d(s, v) assumption
    d(s, x) d(x, y) d(y, v) optimal
    substructure ? d(s, x) d(x, y)
    nonnegative lengths
  • ?(x) d(x, y) inductive hypothesis ?
    ?(y) algorithm
  • so Dijkstra's algorithm would have selected y
    instead of v

33
Priority Queues and Heaps (CLR 20, 21)
Heaps
Operation
Binary
Binomial
Fibonacci
Relaxed
Linked List
make-heap
1
1
1
1
1
insert
log N
log N
1
1
1
find-min
1
log N
1
1
N
delete-min
log N
log N
log N
log N
N
union
N
log N
1
1
1
decrease-key
log N
log N
1
1
1
delete
log N
log N
log N
log N
N
is-empty
1
1
1
1
1
n (n) m(1) O(n2)
n (log n) m(1) O(m n log n)
Dijkstra 1 make-heap n insert n delete-min m
decrease-key
n (log n) m(log n) O(m log n)
34
Shortest Path Extensions
  • Variants of shortest path
  • Undirected graph.
  • O(m n) using Thorup's algorithm
  • Negative weights but no negative cycles.
  • O(mn) using Bellman-Ford
  • Unit weights.
  • O(m n) using breadth first search
  • Integer weights between 0 and constant C.
  • DAGs.
  • O(m n) using topological sort
  • All-pairs.
  • O(n3) using Floyd-Warshall

35
Shortest Path Extra Slides
36
Shortest Path Proving Optimality
  • How can we verify that a given solution is really
    optimal?

9
32
3
2
23
9
s
0
18
14
14
6
2
6
4
30
19
45
11
5
15
5
6
34
20
16
t
7
44
50
15
37
Shortest Path Proving Optimality
  • How can we verify that a given solution is really
    optimal?
  • Easy if all weights nonnegative, and there exists
    a zero cost path.

3
2
0
0
s
0
0
19
0
6
4
10
1
0
5
0
4
1
1
0
t
7
1
38
(No Transcript)
39
(No Transcript)
40
(No Transcript)
About PowerShow.com