hw3sol - Advanced Analysis of Algorithms - Homework III...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Advanced Analysis of Algorithms - Homework III (Solutions) K. Subramani LCSEE, West Virginia University, Morgantown, WV { ksmani@csee.wvu.edu } 1 Problems 1. Problem 24 . 1(5) on Page 592 of [CLRS01]. Solution: We initialize d [ v ] = 0 for each v ∈ V and then run the Bellman-Ford algorithm on this network, i.e., the relaxations are organized into n- 1 rounds and each edge is relaxed once in every round. As with the Single-Source shortest paths problem, if there exists a “relaxable” edge at the end of ( n- 1) rounds, we declare that G has a negative cost cycle. Note that in the presence of negative cost cycles, the shortest path problem is undefined. Lemma 1.1 Under the initialization scheme described above, d [ v ] represents the length of a path from some vertex u ∈ V to v . Proof: Use induction on the number of RELAX() operations. 2 Lemma 1.2 If G does not contain a negative cost cycle, then d [ v ] = δ * ( v ) , for all v ∈ V . Proof: Focus on a specific vertex v ∈ V ; let N v denote the set { u ∈ V : ( u,v ) ∈ E } , i.e., N v denotes the set of vertices with arcs into v . We define δ i ( u,v ) to be the length of the shortest path from u to v using at most i edges; further, δ * i ( v ) = min u ∈ V δ i ( v ) . Accordingly, δ * ( v ) = δ * n- 1 ( v ) , since in the absence of negative cost cycles, the shortest path from any vertex in G to v can consist of at most ( n- 1) edges. We next observe that the shortest path from a vertex t ∈ V , to v , using at most ( r + 1) edges consists of the shortest path from t to a vertex u ∈ N v , using at most r edges and the edge ( u,v ) . Accordingly, δ r +1 ( t,v ) = min u ∈ N v ( δ r ( t,u ) + w ( u,v ) . It immediately follows that δ * r +1 ( v ) = min u ∈ N u ( δ * r ( u ) + w ( u,v )) . Consider the main for loop of the Bellman-Ford algorithm; The following loop invariant is maintained, as we move from one round to the next: At the beginning of round i , d [ v ] ≤ δ * i- 1 ( v ) . We use induction on the loop index i . At the beginning of the first round, d [ v ] = 0 = δ ( v,v ) and since there v is the only vertex from which v is reachable, d [ v ] ≤ δ * ( v ) . Assume that the invariant holds for the first r rounds and consider the sequence of events in round ( r + 1) . We need to consider the following two cases: (i) δ * r +1 ( v ) = δ * r ( v )- In this case, the invariant clearly holds, since as per the inductive hypothesis, d [ v ] ≤ δ * r ( v ) . (ii) δ * r +1 ( v ) < δ * r ( v )- For each vertex u ∈ N v , d [ u ] ≤ δ * r ( u ) , as per the inductive hypothesis. Since all the edges in G are relaxed in the current round, d [ v ] = min u ∈ N v d [ u ] + w ( u,v ) ≤ min u ∈ N v δ * r ( u ) + w ( u,v ) , from the inductive hypothesis = δ * r +1 ( v ) 1 Thus, at the end of the ( n- 1) th round of the...
View Full Document

Page1 / 4

hw3sol - Advanced Analysis of Algorithms - Homework III...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online