{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Notes-592-ch24-L-05

# Notes-592-ch24-L-05 - SHEN'S CLASS NOTES Chapter 24 Single...

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

SHEN’S CLASS NOTES 1 Chapter 24 Single Source Shortest Paths As we have defined earlier, given a weighted graph G(V, E), directed or undirected, the weight of a path p = < v 0 , v 1 , v 2 , …, v k > is the sum of all edge weights on the path: w ( p ) = = k i 1 w ( v i -1 , v i ). We define the shortest path weight from u to v by δ ( u , v ) = otherwise } to from path a is | ) ( { v u p p w Min A path p ( u , v ) is a shortest path if w ( p ( u , v )) = δ ( u , v ). Definition 1 The single-source shortest-paths problem is to find a shortest path from a given source s V to each vertex v V. Definition 2 The single-pair shortest-paths problem is to find a shortest path p ( u , v ) for given vertices u and v . The single-pair shortest-paths problem seems easier than the single-source shortest-paths problem, but actually, no known algorithm exists that can solve the single-pair shortest-paths problem faster in worst case.

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

View Full Document
SHEN’S CLASS NOTES 2 Definition 3 The all-pair shortest-paths problem is to find a shortest path p ( u , v ) from every vertex u to every other vertex v . This chapter discusses the single-source shortest-paths problem only. We will discuss the Bellman-Ford algorithm and the Dijkstra’s algorithm. Both algorithms follow a greedy approach. Both algorithms maintain an attribute d [ v ] for every vertex which is an upper bound on the weight of a shortest path from source s to vertex v . So, d [ v ] is called a shortest path estimate. Initially, d [ v ] is set to for every vertex except s , and d [ s ] = 0. Then the algorithms improve the estimates step by step until the shortest paths are obtained. For each vertex v , both algorithms also use a pointer π ( v ) to point to the predecessor from which d [ v ] is obtained. This pointer is called v ’s father pointer. Initially, π ( v ) = nil. The following piece of code is the initialization used by both algorithms. Initialize-Single-Source (G, s ) 1 for each vertex v V[G] 2 do { d [ v ] 3 π ( v ) nil 4 } 5 d [ s ] 0
SHEN’S CLASS NOTES 3 Relaxation Relaxation is a simple operation used by both algorithms to improve the shortest path estimates. The piece of code for this operation is as follows. Relax( u , v , w ) 1 if d [ v ] > d [ u ] + w ( u , v ) 2 then { d [ v ] d [ u ] + w ( u , v ) 3 π ( v ) u 4 } The essence of Relax( u , v , w ) is that if vertex v can get a shorter path through vertex u , then replace the d [ v ] by the shorter one which is d [ u ] + w ( u , v ), and change the father pointer accordingly. 24.1 The Bellman-Ford Algorithm The pseudo code for the Bellman-Ford algorithm is presented below. It is very easy to follow. After the initialization, the algorithm runs ( n -1) stages. At each stage, it just relaxed each and every edge, one by one. If the graph is undirected, then edge ( u , v ) is relaxed twice, one for each direction. After the ( n -1) stages, the algorithm needs to check every edge to see if any

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 13

Notes-592-ch24-L-05 - SHEN'S CLASS NOTES Chapter 24 Single...

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

View Full Document
Ask a homework question - tutors are online