{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

hw7sol - CS 473 Homework 7 Solutions Spring 2010 1 You are...

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

CS 473 Homework 7 Solutions Spring 2010 1. You are given a map of Sunnydale National Park, drawn as an undirected graph, where vertices represent landmarks in the park, and edges represent trails between those landmarks. (Trails start and end at landmarks and do not cross.) You recognize one of the vertices as your current location; several vertices on the boundary of the map are labeled EXIT. A real number between 0 and 1 appears next to every vertex and edge, indicating the probability of encountering a vampire at the corresponding landmark or on the corresponding trail. Describe an efficient algorithm to find a path out of the park with the smallest expected number of vampires. Solution: The expected number of vampires on a path is just the sum of the vampire probabilities on the vertices and edges of the path. So this is just a shortest-path problem, except that both the vertices and edges have costs associated with them, and edges are undirected. We can reduce our escape problem to a textbook-standard shortest path problem in two stages. (There are several other ways to do this.) (a) Change every undirected edge in the input graph into two directed edges, each with the same cost. We can do this for free simply by declaring that the input adjacency list represents a directed graph, instead of an undirected graph. (b) Add the cost of every vertex to the costs of its incoming directed edges. This requires O ( E ) time. Now the total cost of any path from the start node s is just the cost of its edges, plus the cost of s (which we can ignore since its the same for every path). After the reduction, we are left with the problem of finding the shortest path from the start node s to any EXIT. Since all the edge costs are non-negative (in fact, between 0 and 2), Dijkstra’s algorithm computes the shortest path from s to every other vertex in O ( E log V ) time. We can then find the closest EXIT vertex by brute force in O ( V ) additional time. So the total running time of our algorithm is O ( E log V ) . Rubric: 6 points for graph reduction + 2 points for applying Dijkstra’s algorithm + 2 points for other details. This is not the only correct solution. 1

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

View Full Document
CS 473 Homework 7 Solutions Spring 2010 2. Suppose n different currencies are traded in your currency market. You are given the matrix R [ 1 .. n , 1 .. n ] of exchange rates between every pair of currencies; for each i and j , one unit of currency i can be traded for R [ i , j ] units of currency j . (Do not assume that R [ i , j ] · R [ j , i ] = 1 .) (a) Describe an algorithm that returns an array V [ 1 ..
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 5

hw7sol - CS 473 Homework 7 Solutions Spring 2010 1 You are...

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

View Full Document
Ask a homework question - tutors are online