Course Home | Assignments | Peer Assessment Procedures | Schedule & Lecture Notes

Saint Louis University

Computer Science 314
Algorithms

Michael Goldwasser

Fall 2014

Dept. of Math & Computer Science

Take-home Midterm

Due: 10:00am, Wednesday, 22 October, 2014

Policies:

Problems to be Submitted

  1. Work entirely on your own

    Assume that there are two very large sections of the same course, with n students in each, and that a common exam was given to students in both sections. The two instructors have graded their respective exams and have each provided you with a sorted array of the exam scores from their respective sections. For the sake of notation, let A[1] ≤ A[2] ≤ ... ≤ A[n] represent the array of scores from the first section and B[1] ≤ B[2] ≤ ... ≤ B[n] the array of scores from the second section.

    We are interested in statistics for the combined group of 2n students. In particular, our goal is to determine the median score for the group. Since there are an even number of students, this median score is the average of the scores of the student of rank n and the student of rank n+1.

    Provide an algorithm that computes this median in O(log n) worst-case time. For full credit you must:

  2. Work entirely on your own

    Recently, the FCC fined Marriott hotels for intentionally blocking their guests' personal Wi-Fi access so that they would be more likely to buy acccess to the hotel's own Wi-Fi network (which was not blocked). Ignoring the legal issues here, this brings up an interesting computational question.

    Assume that we model a hotel as a single long hallway, with the location of each guest's room identified by its distance dj from one end of that hallway. The hotel may deploy jammers that will block all communication (other than for the hotel's network) for devices within radius R of the location where the jammer is mounted in the hallway. Of course, the jammers are expensive, so they would like to block all customers communications while deploying as few jammers as possible.

    Give an algorithm that computes an optimal placement of jammers, assuming that your input is the list of n room locations, d1 ≤ d2 ≤ ... ≤ dn, ordered from one end of the hall to the other, and the radius R of the jammers. Give a clear explanation of your algorithm, a proof that it computes a solution with the minimum number of jammers, and an analysis of its running time.

  3. Work entirely on your own

    Sometimes a day of rest can be of great benefit to someone's productivity, while other times it might break a rhythm causing a loss of productivity. In this problem, we explore the mathematics of this issue.

    Let's assume that someone freelances doing some form of repetetive task (e.g., making cupcakes, testing software, copyediting pages of a book) and that they are paid a fixed amount per unit they complete. We assume that they have a certain amount of efficiency in the number of units per day they can complete, but that the efficiency may change depending on the number of days in a row they have worked since their most recent day of rest. To model an individual's efficiency pattern, we assume that productivity pj represents the integer number of units a particular person can complete on a day that is the jth day since the most recent rest. (We assume that a person is well rested before the very first day of our schedule, and thus has efficiency p1 that day.)

    Furthermore, we assume that market demand varies from day-to-day (although unaffected by the person's resting pattern), and that we can predict that on the kth overall day of a calendar period, there will be demand for up to dk units of work. Our challenge is to make a plan for a particular person as to which days to rest during an n-day calendar, assuming we are given the efficiency values p1 through pn, and demands d1 through dn.

    As a tangible example, consider the following problem instance:
    productivity
    (based on days since rest)
    j 1 2 3 4 5 6 7 8
    pj 15 20 15 12 10 8 8 5

    demand (for calendar day k)
    k 1 2 3 4 5 6 7 8
    dk 20 20 20 20 20 20 20 20
    For this instance, the optimal 8-day schedule will achieve 112 units of work, with the daily log being either [15, 20, 15, None, 15, 20, 15, 12] or [15, 20, 15, 12, None, 15, 20, 15]

    If we took the same productivity numbers but varied the demand as follows:
    productivity
    (based on days since rest)
    j 1 2 3 4 5 6 7 8
    pj 15 20 15 12 10 8 8 5

    demand (for calendar day k)
    k 1 2 3 4 5 6 7 8
    dk 20 5 10 20 3 10 3 18
    then we can achieve a profit of 73, with the daily work being [15, None, 10, 20, None, 10, 3, 15] or [15, None, 10, 20, 3, 10, None, 15]

    For those who wish additional examples, we provide a further collection of problem instances with optimal solutions.

    Describe an algorithm that can be used to efficiently compute the maximum profit and the set of resting days that can be used to achieve such profit. Make sure to give a reasonable explanation for the correctness of the algorithm and an analysis of its runtime efficiency.

  4. Work entirely on your own

    When discussing the knapsack problem in class (see Section 16.2), we discussed that a greedy algorithm can be used to solve the fractional version but not the 0-1 knapsack fraction. We also gave a sketch of how dynamic programming can be used to compute an optimal subset of items for the 0-1 knapsack problem using O(nW) time and O(nW) space. For completeness, here is a more formal presentation of that result which introduces some notations that we use in this problem.

    In practice, space is often a much more serious constraint than running time. That is, there are values of n and W for which we might be willing to accept O(nW) running time, but cannot possibly afford use of O(nW) space. For example with n = 10,000 and W = 1,000,000, we might actually be willing to live with 10 billion computations but are unlikely to effectively allocate an array with 10 billion entries.

    For this problem, we develop an algorithm that can compute an optimal subset of items for the 0-1 knapsack problem using O(nW) time and only O(n + W) space. If you are unable to solve any one part of this problem, you may assume that missing result when completing other parts of the problem.

    1. Argue that if we only need to compute the value, P(n,W), of the optimal solution, and not the subset of items that achieves that value, then the problem can be solved in O(nW) time and O(n + W) space.

    2. Assume that we analogously define quantity Q(j,k) for 0 ≤ j ≤ n and 0 ≤ k ≤ W to be the maximum value that can be achieved when using a subset of items {j+1, j+2, ..., n} having combined weight at most k. (Note well that we omit item j itself from the set of allowable items.) Provide a complete recursive definition for Q(j,k).

    3. Explain how to determine, using O(nW) time and O(n+W) space, an amount, k, of weight that could be devoted to items with indices in the range {1, 2, ..., n/2} in an optimal solution to some instance of the knapsack problem.

    4. Assuming the consequence of part (iii), describe a divide and conquer algorithm for identifying the actual subset of items that should be selected in an optimal solution to the 0-1 knapsack problem. You should also give a recurrence relation for the running time T(n,W) for solving a problem with n items and knapsack capacity W.

    5. Give a formal proof that the algorithm described in part (iv) runs in O(nW) time and O(n+W) space. The time analysis should be a formal inductive proof based upon the recurrence relation for T(n,W).

  5. Work entirely on your own

    For this problem, we explore definitions and properties regarding Minimum Spanning Trees. We ask each as a "True/False" question, but for full credit, you must justify your answer (typically with either a proof or a counterexample).

    1. True or False: If an edge (u,v) is contained in some minimum spanning tree, then there must exists some cut (S, V-S) for which (u,v) is a light edge.

    2. For a specific graph, let A be a subset of E that is included in some MST, and let (S, V-S) be a cut that respects A, and let (u,v) be a safe edge for A crossing the cut. True or False: (u,v) must be a light edge for the cut.

    3. True or False: If all edge weights for a graph are distinct, then the minimum spanning tree is unique.

    4. Define a "second-best spanning tree" as a spanning tree that has minimal cost for all spanning trees other than an MST. True or False: If all edge weights for a graph are distinct, then there is a unique second-best spanning tree.

    5. Assume a graph G has edge weights that are all positive and that tree T is an MST for the graph. Now consider a graph G' formed by taking the structure of G, yet replacing each edge weight we with a new weight we2. True or False: T is an MST for G'.


Michael Goldwasser ©2014
CSCI 314, Fall 2014
Last modified: Monday, 20 October 2014
Course Home | Assignments | Peer Assessment Procedures | Schedule & Lecture Notes