08 - Bellman-Ford shortest path algorithm

08 - Bellman-Ford shortest path algorithm - n 1 for u ∈...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
2/18/08 - Bellman-Ford shortest path al. .. Shortest Paths with Negative Edge Lengths (Bellman-Ford) Example: Dijkstra can go wrong. Can you add a constant to every edge length and then run Dijkstra? 15-1 15
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
You can’t have negative cycles Examples C ij = log(exch rate for i -> j) DYNAMIC PROGRAMMING TABLE Example: 15-2
Background image of page 2
OPT[u,h] = cost of cheapest u -> t path using <= h hops. Length (#hops) Source 0 1 2 3 4 5 a -3 -3 -4 -6 -6 b 0 -2 -2 -2 c 3 3 3 3 3 d 4 3 3 2 0 e 2 0 0 0 0 t 0 0 0 0 0 Lemma: If a graph has no negative cycles, then s, t a simple path from s to t of minimum cost. Cor. If |V(G)| = n and G has no neg. cycles, then a cheapest s-t path of <= n-1 hops is cheapest among all s-t paths. BELLMAN-FORD ALG: For all u V(G), initialize OPT(u, 0) = { if u t 0 if u = t} 15-3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
for h = 1, 2, .
Background image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: .. , n - 1 for u ∈ V(G) OPT(u, h) = min{OPT(u,h-1) min{c uv + OPT(w, h-1)} w ∈ V(G) endfor endfor return OPT(s, n-1) Running time of B-F: O(n 3 ) n - 1 outer loop iterations n inner loop iterations O(n) work per iteration For weighted int. sched: 0 | t 1 <= t 2 <= t 3 <= t i ... <= t n | | | | OPT(i) | | OPT(i) = max-wt schedule that ±nishes at t i RNA structure: 2D dynamic programming table: OPT(i, k) = best solution on the RNA segment starting at i, ending at i+k. Edit Distance 2D table OPT(i,j) = Edit Distance from ±rst i characters of x to ±rst j characters of y. δ on every horiz/vert edge α ij on every diagonal edge from (i-1, j-1) to (i,j) 15-4...
View Full Document

{[ snackBarMessage ]}

Page1 / 4

08 - Bellman-Ford shortest path algorithm - n 1 for u ∈...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online