Shortest%20Path

Shortest%20Path - ,n Without lose of generality we assume...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
IEOR 160 Handout Shortest Path Algorithm Fall 2009 Dijakstra’s Algorithm Given a directed graph G = { N,A } with N = { 1 , ··· ,n } and distances d ij ( 0), ( i,j ) A . Task : Find shortest path(s) on G from node 1 to node n (to all nodes 2 , ··· ,n ) Step 0: Set P := { 1 } ; l (1) := 0; l ( j ) := , j = 2 , ··· ,n ; i := 1 Step 1: If n P ( P = N ), STOP Step 2: For every j / P such that ( i,j ) A l ( j ) := min { l ( j ) , l ( i ) + d ij } If l ( j ) = l ( i ) + d ij , then b ( j ) := i . Step 3: Find k such that l ( k ) = min j/ P l ( j ) (Ties broke arbitrarily) If l ( j ) = ∞ ∀ j / P , STOP Step 4: P := P ∪ { k } , i := k , goto Step 1 An Shortest Path Algorithm for acyclic graph (dealing with negative weights) Given an acyclic directed graph G = { N,A } with N = { 1 , ··· ,n } and distances d ij , ( i,j ) A . Task : Find shortest path(s) from node 1 to node n (to all nodes 2 , ···
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ,n ). Without lose of generality, we assume that the indegree of node 1 is zero. Step 0: Set P := { 1 } ; l (1) := 0; i := 1; G := G Step 1: If n ∈ P ( P = N ), STOP G = { G after removing node i and all the arcs coming out of it } . Step 2: Find a node in G’ with indegree zero, denote it by i Step 3: l ( i ) := min k ∈ P | ( k,i ) ∈ A { l ( k ) + d ki } If l ( i ) = l ( ¯ k ) + d ¯ ki then b ( i ) := ¯ k If { k ∈ P | ( k,i ) ∈ A } = ∅ , then l ( i ) := ∞ , b ( i ) := 0 (there is no path from node 1 to node i ) Step 4: P := P ∪ { i } , goto Step 1 1...
View Full Document

This note was uploaded on 03/17/2011 for the course IEOR 160 taught by Professor Hochbaum during the Fall '07 term at Berkeley.

Ask a homework question - tutors are online