Docsity

ECS 222B: Algorithm Design and Analysis - Problem Set 1 - Prof. Charles U. Martel, Assignments of Computer Science

Toggle sidebar
bg1
ECS 222B: Algorithm Design and Analysis Handout 1
UC Davis — Charles Martel January 14, 2008
Problem Set 1—Due Wednesday, January 23, noon
H
¯omework Info Homeworks are due by noon on the due date. They are to be turned in to me,
electronically, in class, or put in my mailbox in the CS office. 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. I hope that
you will ultimate solve the majority of the problems, but don’t be surprised if some of them stump you;
the problems may be quite challenging. Note that what you turn is expected to be your own work, not a
solution you found online or got from a classmate.
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 and
fake it.
(20) Problem 1. In the beam production problem described in class you were given
i) nbeam lengths L1< . .. < Ln,
ii)the costs Fifor building a factory to produce beams of length Li,
iii) Di, the number of beams of length Lito be produced and
iv) Ci, the cost to produce one beam of length Li.
For each length Liwe could produce the Dibeams required either by producing a beam of
length Lior by using a larger beam that is cut down to size Li.
In class we described how to produce a graph such that the shortest path gave us a minimum
cost solution (in Θ(n2) time). Now consider using a dynamic programming formulation to
find an optimum solution directly. To do this, let A[k] denote the minimum cost to produce
beams of size L1, L2, . . . Lk(i.e. consider the original problem but only for the kshortest
beams). A[0] = 0.
a) Give an efficient dynamic programming formulation to compute A[k] for k= 1,2,. . . , n.
b) Justify the correctness of your formulation.
c) What is the running time of your solution?
(35) Problem 2. Consider the bottleneck path problem: Given a directed graph G, with edge
weights, and a start, destination pair of vertices s, t, find the path P from sto tsuch that the
smallest edge on P is as large as possible (for example, in communications networks the edge
weights indicate the bandwidth capacity of an edge, and the rate we can send information
through a path depends on the lowest bandwidth edge on the path).
a) Describe a simple modification of dijkstra’s algorithm that solves this problem.
b) Prove that when your algorithm selects a vertex vto scan (look at its outgoing edges),
d(v) has the value of the best bottleneck path from sto v.
pf2

Partial preview of the text

Download ECS 222B: Algorithm Design and Analysis - Problem Set 1 - Prof. Charles U. Martel and more Assignments Computer Science in PDF only on Docsity!

ECS 222B: Algorithm Design and Analysis Handout 1 UC Davis — Charles Martel January 14, 2008

Problem Set 1—Due Wednesday, January 23, noon

H

omework Info Homeworks are due by noon on the due date. They are to be turned in to me,

electronically, in class, or put in my mailbox in the CS office. 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. I hope that you will ultimate solve the majority of the problems, but don’t be surprised if some of them stump you; the problems may be quite challenging. Note that what you turn is expected to be your own work, not a solution you found online or got from a classmate.

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 and fake it.

(20) Problem 1. In the beam production problem described in class you were given i) n beam lengths L 1 <... < Ln, ii)the costs Fi for building a factory to produce beams of length Li, iii) Di , the number of beams of length Li to be produced and iv) Ci, the cost to produce one beam of length Li. For each length Li we could produce the Di beams required either by producing a beam of length Li or by using a larger beam that is cut down to size Li. In class we described how to produce a graph such that the shortest path gave us a minimum cost solution (in Θ(n^2 ) time). Now consider using a dynamic programming formulation to find an optimum solution directly. To do this, let A[k] denote the minimum cost to produce beams of size L 1 , L 2 ,... Lk (i.e. consider the original problem but only for the k shortest beams). A[0] = 0. a) Give an efficient dynamic programming formulation to compute A[k] for k = 1, 2 ,... , n. b) Justify the correctness of your formulation. c) What is the running time of your solution?

(35) Problem 2. Consider the bottleneck path problem: Given a directed graph G, with edge weights, and a start, destination pair of vertices s, t, find the path P from s to t such that the smallest edge on P is as large as possible (for example, in communications networks the edge weights indicate the bandwidth capacity of an edge, and the rate we can send information through a path depends on the lowest bandwidth edge on the path). a) Describe a simple modification of dijkstra’s algorithm that solves this problem. b) Prove that when your algorithm selects a vertex v to scan (look at its outgoing edges), d(v) has the value of the best bottleneck path from s to v.

2 ECS 222B Handout 1: Problem Set 1—Due Wednesday, January 23, noon

c) An alternate approach to finding bottleneck shortest paths uses Breadth First Search (BFS) and Binary search. Describe how to find bottleneck shortest paths in this way and analyze the running time of your algorithm (for a graph with n nodes and m arcs). d) Estimate which approach will be better (part c) method or the Dijkstra approach of part a)). You can specify features of the graph which might favor one approach or the other. e) Extra credit: The approach of part c) does each BFS starting from scratch. A more clever approach reuses work from prior BFS attempts and thus can speed up the algorithm. Improve your solution of part c) in this way. Give the run-time of your new algorithm (credit will only be given if you give a solution with a real speed-up)

(15) Problem 3. We considered the setting of difference equations where we are given n variables x 1 , x 2 ,... , xn, m constants b 1 , b 2 ,... , bm, and m difference equations each of the form xi −xj ≤ bk. We argued that we could solve this problem by creating a graph G with a vertex i associated with each variable xi, and adding an edge (j, i) of weight bk for each difference equation of the form xi − xj ≤ bk. In class we showed that there is no solution when G has a negative cycle. When G has no negative cycle we can find an assignment of values to the xi’s as follows: create a new graph G’ which is G with also a dummy node s and an edge of weight zero from s to each vertex in G. We then find the shortest path from s to each other vertex in G’. Let D(i) be the shortest distance from s to i in G’. Prove that assigning D(i) to xi for i = 1, 2 ,... , n satisfies the difference equations.

(20) Problem 4.

Consider bidirectional Dijkstra where we alternate between searches from s and t (but no reduced costs, just use the original ones). a) Given an example graph where the first vertex scanned in both searches is not on the shortest s, t path. b) Prove that when some vertex is scanned in both directions we have found the shortest path. Specifically, the minimum value ds(u) + dt(u) over all vertices u is the shortest path distance from s to t (where ds() dt() are the labels in the s and t searches at the point we first scan the same vertex in both).