Reference no: EM132268218
Assignment -
Description - Suppose we are running a bed manufacturing company. There are several different types of bed of various dimensions (length and width) that we can produce. To decide which beds we should produce, we run a market survey asking people what dimensions they require in a bed (i.e. the minimum length and the minimum width they need). We say that a person is compatible with a bed type if its length is at least that person's length requirement, and its width is at least that person's width requirement. The compatibility of a bed type is the number of persons compatible with it. Our goal is to determine efficiently the compatibility of every bed type.
We now state the problem more formally. Suppose we have n bed types, and surveyed n persons. Let B = {b1, . . . , bn} be a set of n points in 2-dimensional space representing the dimensions of the bed types. We write bi = (bi(x), bi(y)) with bi(x) representing the length of bed type i and bi(y) its width. Similarly, we represent the requirements of the n persons with P = {p1, . . . , pn}, a set of n points in 2-dimensional space, and we also write pj = (pj(x), pj(y)) where pj(x) and pj(y) are person j's length and width requirements, respectively.
Point bi is compatible with point pj if and only if bi(x) ≥ pj(x) and bi(y) ≥ pj(y). The compatibility of bi is the number of points of P that it is compatible with and we write comp(bi) = k if it is compatible with k points of p. See Figure 1 for an illustration.

Figure 1: The solid circles represent points in B and the hollow circles represent points in P. The numbers represent the compatibility of each points in B.
Your task is to design an algorithm that computes the compatibility of every point in B.
Task 1: 1-dimensional case
We will start with the simpler 1-dimensional case, that is, P = {p1, . . . , pn} and B = {b1, . . . , bn} are points in 1-dimensional space (multiple points may have the same value). Your task is to design an O(n log n) time algorithm that computes the compatibility of each point in B with P.
(a) Description of how your algorithm works ("in plain English").
(b) Argue why your algorithm is correct.
(c) Prove an upper bound on the time complexity of your algorithm.
(d) Implement your algorithm (in Ed) (see the appendices for the data formats).
Task 2: 2-dimensional case
Consider the same problem in 2D, that is, let P = {p1, . . . , pn} and B = {b1, . . . , bn} be a set of points in 2-dimensional space, where each point pi is a 2-tuple pj = (pj(x), pj(y)) and bi = (bi(x), bi(y)). The task is to solve this problem using a divide-and-conquer approach. A divide and conquer algorithm works by recursively breaking down a problem into two (or more) sub-problems of the same or related type, until these become simple enough to be solved directly. The solutions to the sub-problems are then merged to give a solution to the original problem. For full marks on this question the algorithm is required to run in O(n log n) time.
We will start with the merge step.
(a) Merge step - Consider a vertical line L. Suppose the line splits P into two sets P1 = {p1, . . . , pl} and P2 = {q1, . . . , qn-l}, where P1 lies to the left of L and P2 lies to its right. Similarly, it also splits B into two sets B1 = {b1, . . . , bm} and B2 = {c1, . . . , cn-m}. We will also assume that the sets in P1 and P2, B1 and B2 are ordered from bottom to top (in case of a tie the points are ordered with respect to increasing x-coordinates). Assume that the problem has been solved for (P1, B1) and (P2, B2), respectively. That is, the compatibility of each points in B1 has been computed with respect to P1 and the compatibility of each point in B2 has been computed with respect to P2. Your task is to combine the two solutions into one solution for P = P1 ∪ P2 and B = B1 ∪ B2 in O(n) time. An example is shown in Fig. 2.
(i) Description of how your algorithm works ("in plain English").
(ii) Argue why your algorithm is correct.
(iii) Prove an upper bound on the time complexity of your algorithm.
(iv) Implement your algorithm (in Ed) (see the appendices for the data formats).

Figure 2: The point sets P1, B1 are separated from P2, B2 by a vertical line. The merge step merges the input data into the compatibility of all the points in B = B1 ∪ B2 with respect to points P = P1 ∪ P2.
(b) The final task is to use the merge step algorithm from (a) to construct a divide-and-conquer algorithm for the problem.
(i) Description of how your algorithm works ("in plain English").
(ii) Argue why your algorithm is correct.
(iii) Prove an upper bound on the time complexity of your (entire) algorithm.
(iv) Implement your algorithm (in Ed) (see the appendices for the data formats).
Attachment:- Assignment File.rar