Docsity

ECS 122A: Algorithm Design and Analysis - Homework 2 - Prof. Charles U. Martel, Assignments of Computer Science

Toggle sidebar
bg1
ECS 122A: Algorithm Design and Analysis Homework 2
UC Davis: Charles Martel, Susan Margulies Due Monday, April 28, 2008, 4 PM
Problem Set 2
Homework Info Homeworks are due by 4 PM on the due date. They are to be turned in at the
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).
1 Shortest Path, KT: 4.4 (25 pts)
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.
2 Maximum Reliability, KT: 4.4 (30 pts)
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 (u1, u2, . . . , uk) is (1−f(u1, u2))(1−f(u2, u3)) · · · (1−
f(uk−1, uk)). Such a value is called the reliability of the path (u1, . . . , uk).
Describe and analyze an algorithm that given G, the probability function f, and two vertices
s, t ∈V, find the path from sto tof maximum reliability.
Hint: Think about ways in which maximizing a product can be made equivalent to maximizing a
sum.
pf3

Partial preview of the text

Download ECS 122A: Algorithm Design and Analysis - Homework 2 - Prof. Charles U. Martel and more Assignments Computer Science in PDF only on Docsity!

ECS 122A: Algorithm Design and Analysis Homework 2 UC Davis: Charles Martel, Susan Margulies Due Monday, April 28, 2008, 4 PM

Problem Set 2

Homework Info Homeworks are due by 4 PM on the due date. They are to be turned in at the

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).

1 Shortest Path, KT: 4.4 (25 pts)

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.

2 Maximum Reliability, KT: 4.4 (30 pts)

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

3 Greedy Algorithms, KT: 4.1 (25 pts)

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.

4 Minimum Spanning Trees, KT: 4.5 (25 pts)

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