Introduction to Algorithms (Single-Source Shortest Paths Problem)

Motivation

The shortest way to drive from A to B Google maps “get directions”

Formulation: Problem on a weighted graph G(V, E), W: E → R

Two Algorithms: Dijkstra O(V log V + E) assumes non-negative edge weights; Bellman-Ford O(VE) is a general algorithm;

Model as a weighted graph G(V, E), W: E → R

  • V = vertices (street intersections)
  • E = edges (street, roads); directed edges (one way roads)
  • W(U, V ) = weight of edge from u to v (distance, toll)

path p = <v_{0}, v_{1}, . . . v_{k}>

        (v_{i} , v_{i+1}) \epsilon E for \, 0 \leq i < k

        \omega (p) = \sum_{i=0}^{k-1} \omega (v_{i}, v_{i+1})

  • find p with minimum weight

Weighted Graph

Shortest path weight from u to v as

\delta (u, v) = \left \{_{\infty }^{min\left \{ \omega (p) \right \}\, if\, \exists\, any \, such \, path}

Single Source Shortest Paths:

Given G = (V, E), w, and a source vertex S find δ(S, V ) [and the best path] from S to each v ∈ V.

Data structures:

        d[v] = value inside circle

        d[v] decreases as we find better paths to v

        Π[v] = predecessor on best path to v, Π[s] = NIL

Negative-Weight Edges

  • Natural in some applications (e.g., logarithms used for weights)
  • Some algorithms disallow negative weight edges (e.g., Dijkstra)
  • If you have negative weight edges, you might also have negative weight cycles =⇒ may make certain shortest paths undefined!

The General structure of S.P. Algorithms (no negative cycles)

Initialize:         for v ∈ V: 
                        d[v] ← ∞
                        Π[v] ← NIL
                    d[S] ← 0

Main:               repeat
                    select edge (u, v)
"Relax" edge (u, v)     if d[v] > d[u] + w(u, v):
                            d[v] ← d[u] + w(u, v)
                            Π[v] ← u
                    until all edges have d[v] ≤ d[u] + w(u, v)

Optimal Substructure

Theorem: Subpaths of shortest paths are shortest paths

Triangle Inequality:

Theorem: For all u, v, x ∈ X, we have δ (u, v) ≤ δ (u, x) + δ (x, v)​​​​​​​

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值