

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


ECS 122A: Algorithm Design and Analysis Homework 2 UC Davis: Charles Martel, Susan Margulies Due Monday, April 28, 2008, 4 PM
marked box in K ¯
emper Hall, room 2131 (right side). No late homeworks will be accepted.
Much of what one learns in this course comes from trying to solve the homework problems, so work hard on them. Doing a conscientious job on the homeworks is the best preparation for the exams. We hope that you will ultimately solve the majority of the problems, but don’t be surprised if some of them stump you; some of the problems may be quite challenging.
Your solutions should be terse, correct, and legible. Understandability of the solution is as necessary as correctness. Expect to lose points if you provide a ”correct” solution with a not-so-good writeup. As with an English paper, you can’t expect to turn in a first draft: it takes refinement to describe something well. Typeset solutions are always appreciated.
If you can’t solve a problem, briefly indicate what you’ve tried and where the difficulty lies. Don’t try to pull one over on us.
If you think a problem was misgraded, please see the grader first. (The TA will be the grader for the homework).
Given as input a weighted, directed, acyclic graph where the edge weights can be positive or negative, design the following and provide an analysis of their running times:
a. An algorithm the finds the longest path in the graph.
b. An algorithm that finds the shortest path in the graph.
We are given a directed graph G = (V, E) describing a network, and, for each edge (u, v) ∈ E, we are given the probability f (u, v) that the link (u, v) may fail. These probabilities are independent; that is, the probability that no edge fails in the path (u 1 , u 2 ,... , uk) is (1−f (u 1 , u 2 ))(1−f (u 2 , u 3 )) · · · (1− f (uk− 1 , uk)). Such a value is called the reliability of the path (u 1 ,... , uk).
Describe and analyze an algorithm that given G, the probability function f , and two vertices s, t ∈ V , find the path from s to t of maximum reliability.
Hint: Think about ways in which maximizing a product can be made equivalent to maximizing a sum.
2 ECS 122A Handout 2: Problem Set 2
You are given a set of items { 1 , 2 ,... , n}. Each item has a weight wi, and a value vi. You are only strong enough to carry weight W , and you want the items you take with you to be worth as much as possible. You are allowed to take partial amounts of each item. For example, if you can only carry 20 pounds, and you see in front of you 20 silver pieces (each weighing 2 pounds, and each worth $1), 4 gold pieces (each weighing 5 pounds, and each worth $10), and a single 30 pound lump of platinum worth $100, it is better for you to shave off part of the platinum, and take exactly 20 pounds for a value of $66.67 dollars. Thus, if you take a fraction of an item, you get that fraction of the value, and that the goal is to find items, or fractions thereof, that have maximum total value.
Design an algorithm for finding the optimal solution, prove its correctness and analyze its running time.
Consider the following two algorithms for finding a minimum spanning tree. Prove that the al- gorithm is correct, or show an example of a graph where the algorithm fails. If the algorithm is correct, discuss an efficient implementation and analyze the running time.
a. Consider the following algorithm for the minimum spanning tree problem. Given G = (V, E) where V = { 1 ,... , n}, let V 1 ⊆ V be the first b|V |/ 2 c vertices and let V 2 ⊆ V be the remaining d|V |/ 2 e vertices; recursively compute the minimum spanning tree of G 1 = (V 1 , E 1 ) and G 2 = (V 2 , E 2 ) where E 1 is the set of edges that are incident only on vertices of V 1 (similarly for E 2 ), then connect the two trees using the edge of smallest weight among the edges incident on a vertex in V 1 and a vertex in V 2. If |V | = 1 return the empty spanning tree, else split the graph as described.
b. Consider the following algorithm: sort the edges, and then delete the heaviest edge if graph remains connected, then consider the next heaviest, etc. The algorithm is more formally described as:
ALGORITHM: mst-alt INPUT: An weighted, undirected graph G OUTPUT: A minimum spanning tree for G
1 Sort the edges of G in non-increasing order of weight. 2 T ← E 3 for all e ∈ E in non-increasing order of weight do 4 if T − {e} is connected then 5 T ← T − {e} 6 end if 7 end for 8 return T