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

This
** preview**
has intentionally

**sections.**

*blurred***to view the full version.**

*Sign up*This
** preview**
has intentionally

**sections.**

*blurred***to view the full version.**

*Sign up*
**Unformatted text preview: **Single Source Shortest Path (SSSP) Problem Single Source Shortest Path Problem Input: A directed graph G = ( V , E ) ; an edge weight function w : E R , and a start vertex s V . Find: for each vertex u V , ( s , u ) = the length of the shortest path from s to u , and the shortest s u path. There are several different versions: G can be directed or undirected . All edge weights are 1. All edge weights are positive . Edge weights can be positive or negative , but there are no cycles with negative total weight . c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 2 / 36 SSSP Problem Note 1: There are natural applications where edge weights can be negative. Note 2: If G has a cycle C with negative total weight, then we can just go around C to decrease the ( s , * ) indefinitely . Then the problem is not well defined. We will need an algorithm to detect such condition. For the case when w ( e ) = 1 for all edges, we have shown that the problem can be solved by BFS in ( n + m ) time. We next discuss algorithms for more general cases. c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 3 / 36 SSSP Problem: Positive Edge Weight We consider the case where G is directed and w ( e ) for all e E . If G is undirected, the algorithm is almost identical. General Description: Each vertex u V has a variable d [ u ] , which is an upper bound of ( s , u ) . During the execution, we keep a set S V . For each u S , d [ u ] = ( s , u ) has been computed. Initially S contains s only and d [ s ] = ( s , s ) = . The vertices in V- S are stored in a priority queue Q . d [ u ] is the key value for Q . In each iteration, the vertex in Q with min d [ u ] value is included into S . For vertex v Q where u v E , d [ v ] is updated. When Q is empty, the algorithm stops. c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 4 / 36 Priority Queue To implement the algorithm, we need a data structure. Priority Queue A Priority Queue is a data structure Q . It consists of a set of items . Each item has a key . The data structure supports the following operations. Insert( Q , x ): insert an item x into Q . Extract-Min( Q ): remove and return the item with minimum key value. Min( Q ): return the item with minimum key value. Decrease-Key( Q , x , k ): decrease the key value of an item x to k . By using a Heap data structure, priority queue can be implemented so that: Min( Q ) takes O ( 1 ) time. All other three operations take O ( log n ) time ( n is the number of items in Q .) c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 5 / 36 Dijkstras Algorithm Main Data structures: G : Adjacency List Representation....

View
Full
Document