0% found this document useful (0 votes)
38 views3 pages

Algorithm Design Problem Set 4 (Spring 2025)

The document outlines Algorithm Design Problem Set 4 for Spring 2025, consisting of 4 main problems worth 25 points each, with a due date of April 22, 2025. The problems cover topics such as dynamic programming, sequence alignment, interval scheduling, and optimization in resource management. Additionally, there are optional problems and examples provided to illustrate the challenges and expected algorithmic approaches for each problem.

Uploaded by

dave
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views3 pages

Algorithm Design Problem Set 4 (Spring 2025)

The document outlines Algorithm Design Problem Set 4 for Spring 2025, consisting of 4 main problems worth 25 points each, with a due date of April 22, 2025. The problems cover topics such as dynamic programming, sequence alignment, interval scheduling, and optimization in resource management. Additionally, there are optional problems and examples provided to illustrate the challenges and expected algorithmic approaches for each problem.

Uploaded by

dave
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Algorithm Design Problem Set 4 (2025 Spring)

4 problems, 25 points each


5 exercise problems (do NOT turn in)

Due Date: April 22, 2025

1. (25 points) Jack Sparrow and Hector Barbossa found a buried chest containing n
valuable artifacts, where n is even. They decided to divide what they found as
follows. First, they place the artifacts in a row; let vi > 0 be the value of the i-th
artifact from the left. Then, they take turns to select either the left-most or the
right-most remaining artifact. Jack Sparrow will move first.
(a) (15 points) Suppose that Hector Barbossa is simple minded and always takes
the rightmost remaining artifact. Design a dynamic programming algorithm to
compute the maximum total value Jack Sparrow can get, and reason about its
running time.
(b) (10 points) Design a dynamic programming algorithm to compute the maximum
total value Jack Sparrow can guarantee, no matter how Hector Barbossa plays, and
reason about its running time.
2. (25 points) Consider a sequence alignment problem over an alphabet of size k, Z =
{z1 , z2 , . . . , zk }, with given misalignment costs c (z, z ′ ) > 0 for any z ̸= z ′ ∈ Z, and
a given gap cost c(−) > 0. Assume that each of these parameters is a positive
integer. To align two strings, you need to give a sequence (ui , v i )ti=1 that, u1 . . . ut ,
v 1 . . . v t composes the two strings respectively after removing the dashes.
Suppose you are given two strings A = a1 a2 . . . am and B = b1 b2 . . . bn . Give an
O(mn) algorithm to find a minimum-cost alignment between A and B.

3. (25 points) Consider the following variant of interval scheduling, where each job
j is associated with not only a time interval, specified with the start time sj and
finish time fj , but also a value vj . We want to choose a subset of compatible jobs
whose sum of values is maximized. Design a dynamic programming algorithm for
this problem and reason about its running time.

4. (25 points) You are the manager of a cafe. Your cafe has a stock of X > 0 cups
of coffee, Y > 0 cups of tea, and Z > 0 cups of milk. There will be n customers
today, where customer i is willing to pay xi > 0 for ai > 0 cups of coffee along
with ci ≥ 0 cups of milk, or pay yi > 0 for bi > 0 cups of tea along with di ≥ 0
cups of milk, or pay zi > 0 if served both. Design an algorithm that computes the
maximum total income while adhering to the storage constraints. (all parameters
occurred are integers).
(a) (25 points) The running time of your algorithm should be O(nXY Z).
(b) (optional, 0 points) The running space of your algorithm should be O(XY Z).

5. (0 points) A fisherman catches a golden fish. It speaks like a real human being:
”Put me back, old man, into the ocean. I will pay you a right royal ransom, I will
give you whatever you ask me.”
The fisherman asks for an accurate prediction of the stock prices in the next n days
(for simplicity, assume that there is only one stock). The golden fish does just that,
and pi is the price on day i. As it goes back to the ocean, the golden fish remarks
that the magic will disappear and the predictions will no longer be accurate after
one buy and one sell. Now the fisherman wishes to find two days 1 ≤ i < j ≤ n such
that buying on day i and selling on day j maximizes the his gain, i.e., to maximize
pj
pi
.
(a) (25 points) Design an algorithm for the fisherman with running time strictly
faster than O (n2 ) time by the brute-force algorithm.
(b) (optional, 0 points) What if two buys and two sells are allowed before the magic
disappears? Could you design a polynomial-time algorithm for this variant?

6. (0 points) Consider a set of jobs J1 , J2 , · · · , Jn . Each job Ji has a required process-


ing time pi and a deadline di , where pi and di are positive integers. The jobs are
sorted in a non-decreasing order of deadlines (i.e., d1 ≤ d2 ≤ · · · ≤ dn ). Scheduling
a job Ji = (pi , di ) requires assigning an interval [t, t + pi ) exclusively to Ji , where
0 ≤ t ≤ di − pi . Different jobs must be scheduled in non-overlapping intervals. For
example, J1 = (4, 5) and J2 = (5, 10) can be scheduled in [0, 4) and [4, 9), respec-
tively. Given a set of jobs, it might not be feasible to schedule all the jobs (e.g.,
J1 = (5, 6) and J2 = (5, 8) ); the objective is to schedule the maximum number of
jobs.
(a) Consider the following greedy algorithm. Denote ACCEPTED to be an empty
set initially. Starting from J1 , repeatedly pick the next job Ji , if scheduling Ji
immediately after all the jobs already in ACCEPTED can meet the deadline of Ji ,
add Ji into ACCEPTED and schedule it accordingly; otherwise, discard Ji . Give
an example to show that this algorithm fails to schedule the maximum number of
jobs.
(b) Show how to use dynamic programming to compute the maximum number of
jobs that can be scheduled together. The time complexity should depend on the
number of jobs and the value of the maximum deadline.

7. (0 points) Let A = {a1 , a2 , · · · , an } be a set of distinct integers, and let S = a1 +


a2 + · · · + an . Assume that the sum S is an even number. Give an algorithm to
check whether A can be divided into two subsets such that the sum of the numbers
in each subset is exactly equal to S2 . Analyze the time complexity of the algorithm.
Hint: You may want to consider a more general question asking whether there is a
subset of numbers from A that sums to a given target 0 ≤ T ≤ S.
let dp[sum][i] = the sum of a sequence

[1,2,4,3] greedy doesnt work because it will take 1,2 and then crash/give up while it shd’ve divided 1,4, and 2,3 into 2 sets
8. (0 points) Given n positive integers x1 , x2 , . . . , xn . Your task is to determine whether
it is possible to choose signs s1 , s2 , . . . , sn ∈ {+1, −1} such that:

s1 x1 + s2 x2 + · · · + sn xn = 0.

Suppose x1 + x2 + · · · + xn = X. Design an algorithm that runs in time polynomial


in n and X.
let dp[i] be the closes

Page 2
9. (0 points) The owners of an independently operated gas station are faced with a
following situation. They have a large underground tank in which they store gas;
the tank can hold up to L gallons at one time. Ordering gas is quite expensive,
so they want to order relatively rarely. For each order, they need to pay a fixed
price P for delivery in addition to the cost of the gas ordered. However, it costs c
to store a gallon of gas for an extra day, so ordering too much ahead increases the
storage cost.
They are planning to close for a week in the winter, and they want their tank to
be empty by the time they close. Luckily, based on years of experience, they have
accurate projections for how much gas they will need each day until this points in
time. Assume that there are n days left until they close, and they need gi gallons
of gas for each of the days i = 1, 2, . . . n. Assume that the tank is empty at the end
of day 0 . Give an algorithm to decide on which days they should place orders, and
how much to order so as to minimize their total cost.

ASSUME THAT THERE IS NO Gi that is larger than L other wise we cant fulfill the order

let dp[i] be the minimum cost that they need to pay up from day 1 until day i and the tank is empty at the end of day i

for each passing day they either buy gas or not buy gas from yesterday and pay up the cost c to store a gallon of gas for an extra day:

if they are buying gas: they pay P + price x gi

if they are buying from yesterday: they pay (price + c) x gi (we can do this only if gi-1 + gi <= L)

so we have 3 cases:

1. buy all gas from today with cost P + price x gi


2. prepare for this gas demand from yesterday with cost (price + c) x gi (only if gi-1 + gi <= L)
3. buy Z amount from yesterday and gi-z amount from today with cost (price + c) x Z + P + price x (gi-z) but we need to calculate the
optimal value of G here

Page 3

You might also like