ESO 207A Programming Assignment 2: Due On 09/02/2019: 1 Dominating Set in 2-D
ESO 207A Programming Assignment 2: Due On 09/02/2019: 1 Dominating Set in 2-D
2 Problem
Given a set S of n points in a 2-D plane, write a C program to compute Dom(S). Observe that a trivial algorithm
can be designed which has O(n2 ) time complexity. Your task is to use divide and conquer and design an algorithm
with O(n. log n) time complexity.
3 Details
Save all input points in an array A[.] at locations 0 to n − 1 and return the set Dom(S) in array B[.] in consecutive
locations, starting from 0. For simplicity, assume that all points have integer coordinates.
Initially store all points in a 2-D array P oint. If the i-th point is (xi , yi ), then P oint[0, i] = xi and P oint[1, i] =
yi . So index i uniquely identifies the point.
Array A and B are integer arrays and they only store the indices of the points. That is, if A[j] = i, then it is
referring to the point (P oint[0, i], P oints[1, i]). Same is true for B.
Hint1: Devise a subroutine Dom(i, j), i ≤ j, which computes the Dom({A[i], . . . , A[j]) and returns it in array
B in the consecutive locations starting from B[i].
Hint2: Initially sort the points in A in increasing order of their x-values.
4 I/O Format
• The first line of the input consists of an integer n denoting the number of points in set S.
• Next n lines will contain n points with each line containing two integers separated by a single space. First
number being the x-coordinate and the second the y-coordinate.
• The output must have integer m, the number of points in Dom(S), in the first line. Subsequently m lines
must have x and y coordinates of one point each, separated by a single space. The points must be sorted in
increasing order of x-values of the points.
Sample Input:
4
3 2
1 2 |
2 3
2 1
Corresponding Output:
1
2
2 3
3 2
Constraints:
1 ≤ n ≤ 105
0 ≤ x ≤ 105
0 ≤ y ≤ 105