Problem Set 2: Divide & Conquer: CS 3510: Design & Analysis of Algorithms
Problem Set 2: Divide & Conquer: CS 3510: Design & Analysis of Algorithms
• Please type your solutions using LATEX or any other software. Handwritten solutions will not
be accepted for this assignment.
• Your algorithms must be in plain English & mathematical expressions. Pseudo-code without
sufficient explanation will receive no credit.
• If we ask for an algorithm with a specific runtime, we will only accept answers with that
specific runtime, even if a faster solution exists. If we ask for an “efficient” algorithm, we
will not accept answers if a faster algorithm than the one provided exists.
• Unless a question explicitly states that no work is required to be shown, you must provide
an explanation or justification for your answer.
• Unless otherwise stated, all logarithms are to base two and all arrays are 1-indexed.
1.) Let A be an array of strictly increasing integers. We want to be able to find the index of the
number closest to its index. Specifically, we want to find i such that |A[i] − i| is minimized. If
there are multiple candidates, you only need to return one of them. Provide an efficient divide-
and-conquer algorithm to find such an i. See the note about 1-indexing on the first page
of the assignment.
As an example, let the array be A = [−10, −3, 0, 6, 9, 14, 15, 20]. The expected return value is
i = 4.
(a.) Describe your algorithm to a degree where someone could implement it if given your answer.
Please reference “Algorithm Design” in the Assignment Guidelines uploaded to
Canvas.
(b.) Argue why your algorithm is correct (given any input, why does your algorithm produce the
correct outputs). Please reference “Algorithm Analysis” in the Assignment Guide-
lines uploaded to Canvas.
(c.) Give the runtime of your algorithm and explain the reasoning.
For example, if J = [50, 100, 150, 200, 250, 300] and c = 3, the most balanced assignment would
be to give the first computer the tasks requiring [50, 100, 150] minutes, the second computer the
tasks requiring [200, 250] minutes, and the third computer the task requiring [300] minutes. This
results in workloads of 300, 450, and 300 minutes, respectively, and no assignment would reduce
the maximum workload below 450 minutes.
(a.) Describe your algorithm to a degree where someone could implement it if given your answer.
Please reference “Algorithm Design” in the Assignment Guidelines uploaded to
Canvas.
(b.) Argue why your algorithm is correct (given any input, why does your algorithm produce the
correct outputs). Please reference “Algorithm Analysis” in the Assignment Guide-
lines uploaded to Canvas.
(c.) Give the runtime of your algorithm and explain the reasoning.
P = [p0 , p1 , p2 , . . . , pn−1 ].
For every day you own the house, you have to pay a tax t on it, where t is a constant input.
The profit gained from purchasing the house on day i and selling the house on day j ≥ i is equal
to pj − pi − t · (j − i). Our goal is to find indices i and j ≥ i that maximize the profit with a
divide-and-conquer algorithm in O(n log n) time.
Note: you must always buy the house and sell the house (i.e. you must return an i and j in the
bounds of P ).
(a.) Describe your algorithm to a degree where someone could implement it if given your answer.
Please reference “Algorithm Design” in the Assignment Guidelines uploaded to
Canvas.
(b.) Argue why your algorithm is correct (given any input, why does your algorithm produce the
correct outputs). Please reference “Algorithm Analysis” in the Assignment Guide-
lines uploaded to Canvas.
(c.) Give the runtime of your algorithm and explain the reasoning.
There exists a single band of which more than half the attendees are fans. There are no guarantees
about the remaining attendees or the other bands.
Design an efficient divide and conquer algorithm to find the most popular band. You can either
have your algorithm return one fan of the band or all fans of the band.
(a.) Describe your algorithm to a degree where someone could implement it if given your answer.
Please reference “Algorithm Design” in the Assignment Guidelines uploaded to
Canvas.
(b.) Argue why your algorithm is correct (given any input, why does your algorithm produce the
correct outputs). Please reference “Algorithm Analysis” in the Assignment Guide-
lines uploaded to Canvas.
(c.) Give the runtime of your algorithm and explain the reasoning.