Saint Louis University |
Computer Science 314
|
Dept. of Math & Computer Science |
You must adhere to the policies on academic integrity. In particular, there will be no collaboration allowed for any problems on this midterm, and you are forbidden from seeking answers to these problems from any outside sources.
The midterm will be graded by the instructor, so there is no need to separate problems into different packets or to hide your identity with a codename.
As is the case with homeworks, we will drop your own lowest score from the problems below and use the remaining problems for computing your exam grade.
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
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
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,
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 |
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 |
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.
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
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.
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.
Assume that we analogously define quantity
Q(j,k) for
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
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.
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).
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).
True or False: If an edge
For a specific graph, let A be a subset
of E that is included in some MST, and let
True or False: If all edge weights for a graph are distinct, then the minimum spanning tree is unique.
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.
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'.