note08-1x2

# note08-1x2 - Single Source Shortest Path (SSSP) Problem...

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

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

View Full Document

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.

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 Dijkstra’s Algorithm Main Data structures: G : Adjacency List Representation....
View Full Document

## This note was uploaded on 02/27/2012 for the course CSE 431/531 taught by Professor Xinhe during the Fall '11 term at SUNY Buffalo.

### Page1 / 16

note08-1x2 - Single Source Shortest Path (SSSP) Problem...

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

View Full Document
Ask a homework question - tutors are online