ps8sol

ps8sol - Introduction to Algorithms Massachusetts Institute...

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

View Full Document Right Arrow Icon
Introduction to Algorithms November 20, 2006 Massachusetts Institute of Technology 6.046J/18.410J Professors Erik Demaine and Madhu Sudan Problem Set 8 Solutions Problem Set 8 Solutions Problem 8-1. Shortest paths in graphs with alternative distance measures Let G = ( V,E ) be a graph with a real weight w ( u,v ) assigned to each edge ( u,v ) E . Let p = v 1 v 2 → ··· → v k be a path in G . In class we defined the weight of p as w ( p ) = k - 1 X i =1 w ( v i ,v i +1 ) . Although this definition of path weight is natural, in some applications alternative definitions may be more appropriate. In this problem you will see several alternative definitions of path weight. Your goal is to design efficient algorithms for the single-source shortest-paths problem under each of these definitions. That is, in each of the three cases below, give an efficient algorithm to find the shortest-path weights from a given source node s to all other nodes in G . The running time of each algorithm should be bounded by a polynomial in | V | and | E | . (a) Let G = ( V,E ) be a directed graph and w : E R be a weight function. Assume that w takes only positive values. Define the weight of a path p = v 1 v 2 → ··· → v k in G to be the product of all edge weights along the path, i.e., w ( p ) = k - 1 Y i =1 w ( v i ,v i +1 ) . Solution: Consider a new weight function w 0 : E R , defined by w 0 ( u,v ) = lg w ( u,v ) . Note that w 0 is well defined since w ( u,v ) is always positive. Observe that for every path p = v 1 v 2 → ··· → v k in G we have w ( p ) = k - 1 Y i =1 w ( v i ,v i +1 ) = 2 k - 1 i =1 w 0 ( v i ,v i +1 ) = 2 w 0 ( p ) . For v V let d ( v ) denote the minimal weight of a path from the source to v with respect to the weight function w. Similarly let d 0 ( v ) denote the minimal weight of a path from the source to v with respect to the weight function w 0 . The identity above implies that d ( v ) = 2 d 0 ( v ) . It remains to note that d 0 ( v ) can be computed for all v V by a single invocation of a standard Bellman-Ford algorithm with the weight function w 0 on edges.
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Problem Set 8 Solutions (b) Consider a directed graph G = ( V,E ) where weights are assigned to vertices rather than edges. Let w : V R be such a weight function. Define the weight of a path p = v 1 v 2 → ··· → v k in G to be the sum of all node weights along the path, i.e., w ( p ) = k X i =1 w ( v i ) . Solution: Define a function w 0 : E R , by the following rule: w 0 ( u,v ) = w ( v ) . In other words, assign every edge the weight of its end node. It is easy to see that, for every path p = v 1 v 2 → ··· → v k in G , w ( p ) = w 0 ( p ) + w ( v 1 ) . Therefore a single invocation of a standard shortest paths algorithm that allows negative cycles (say, Bellman-Ford) with weights w 0 on edges solves the problem.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/20/2012 for the course CS 6.006 taught by Professor Erikdemaine during the Fall '08 term at MIT.

Page1 / 7

ps8sol - Introduction to Algorithms Massachusetts Institute...

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