Advanced Algorithms Assignment 1

You can find the assignment description here.

Exercise 1.

Exercise 1.1

We can observe that the Load Balancing problem with unsplittable jobs (which we know is NP-complete) is a strictly special case of this extended problem.
For example, we can consider an instance of the extended problem where the set of splittable jobs is empty. In this scenario, the input consists solely of unsplittable jobs, that is the original Load Balancing problem. Any algorithm that can solve the extended problem must also be able to solve this specific instance. Since finding the optimal makespan for an instance with only unsplittable jobs is NP-complete, the general problem containing both types must be at least as hard. Therefore, extended Load Balancing is NP-hard.
Let's prove that the problem also belongs to the class NP. To show this, we frame it as a decision problem: given a time threshold K, does a schedule exist such that Tโ‰คK? A proposed solution (certificate) is the full assignment of unsplittable jobs and the "flow" allocation for splittable jobs.
We can also verify the makespan T for each machine i by computing its total load Ti as the sum of unsplittable processing times and the allocated fractions of splittable jobs. Since all calculations (sums and checking Tโ‰คK) can be performed in polynomial time relative to the number of jobs n and machines m, the extended Load Balancing problem is in NP.
Since the problem is both NP-hard and in NP, the extended Load Balancing problem is NP-complete.

Exercise 1.2

We can extend the smarter greedy algorithm that first sorts and re-indexes the jobs such that t1โ‰ฅโ‹ฏโ‰ฅtn, and then applies the original greedy algorithm, to handle instances that may also contain splittable jobs.

First, we separate the jobs into unsplittable and splittable sets. Let the set of unsplittable jobs be U with processing times tjjโˆˆU and the set of splittable jobs be S with processing times skkโˆˆS. We then order the unsplittable jobs in descending order (t1โ‰ฅt2โ‰ฅโ‹ฏโ‰ฅt|U|) and assign each job greedily to the machine i with minimum current load Ti, exactly as in the original algorithm.

Let Tiunsplit denote the load of machine i after all unsplittable jobs, and let TU=maxiTiunsplit be the intermediate makespan.

Next, for the splittable jobs, we calculate the total splittable work WS=โˆ‘kโˆˆSsk. We then compute the total average load for the entire instance: Lavg=(โˆ‘iTiunsplit+WS)/m. The splittable work is then used to "fill" any machine i whose load Tiunsplit is less than Lavg, raising its load up to Lavg. If a machine j already has Tjunsplitโ‰ฅLavg, it receives no splittable work.

The final makespan T is therefore the maximum of the original highest unsplittable load and this average load.

T=max(TU,Lavg)

Now we have to prove that Tโ‰ค1.5Tโˆ—.

First, we know the guarantee for the unsplittable part: TUโ‰ค1.5โ‹…TUโˆ—, where TUโˆ— is the optimal makespan for an instance with only the jobs in U.

Tโˆ—โ‰ฅTUโˆ— (since the optimum for the full problem cannot be better than the optimum for a sub-problem) and Tโˆ—โ‰ฅLavg (since the optimum cannot be better than the perfect average).

We can simply check the two cases for our final makespan T:

  1. If T=TU the ratio holds, since the makespan is determined by an unsplittable load. We have T=TUโ‰ค1.5TUโˆ—โ‰ค1.5Tโˆ—.

  2. If T=Lavg, the makespan is determined by the average load. We have T=Lavgโ‰คTโˆ—. In this case, our solution is optimal.

In both cases the final makespan Tโ‰ค1.5โ‹…Tโˆ—, so the approximation ratio is maintained.

Exercise 2.

Exercise 2.1

We can observe that the function f(x,y)=โˆ‘i=1n(|xโˆ’xi|+|yโˆ’yi|) is separable. We can rewrite the function by grouping the x and y terms independently:

f(x,y)=(โˆ‘i=1nwi|xโˆ’xi|)+(โˆ‘i=1nwi|yโˆ’yi|)

Let fx(x) denote the x-dependent term and fy(y) denote the y-dependent term. To minimize the total function f(x,y)=fx(x)+fy(y), we can find the coordinate xโˆ— that minimizes fx(x) and the coordinate yโˆ— that minimizes fy(y) completely separately. This reduces the 2D problem to two independent 1D problems, that are basically the weighted median problem.

We now describe the algorithm to find the optimal xโˆ—; the algorithm for yโˆ— is identical. First, we calculate the total weight W=โˆ‘i=1nwi. We then create a list of pairs (xi,wi) and sort this list in non-decreasing order based on the xi coordinates.

Next, we iterate through this sorted list, maintaining a cumulative weight sum S, initialized to zero. For each point (xk,wk) in the sorted list, we add its weight S=S+wk. The first coordinate xk for which this cumulative sum reaches or exceeds half the total weight (i.e., Sโ‰ฅW/2) is the weighted median. We set xโˆ—=xk and terminate the 1D search. The final optimal point is (xโˆ—,yโˆ—).

Correctness and time bound:
The correctness of separating the problem follows from the additive nature of the Manhattan distance.
The correctness of the algorithm relies on fx(x) being a convex function. Let's study the derivative to find the minimum.

We begin by expressing the derivative of the sum as the sum of the derivatives, noting that ddx|xโˆ’xi|=sgn(xโˆ’xi):

fxโ€ฒ(x)=โˆ‘i=1nwiโ‹…sgn(xโˆ’xi)

For any point x not equal to any xi, the function is differentiable. We divide the sum into two groups:

Substituting the signs:

fxโ€ฒ(x)=โˆ‘xi<xwiโ‹…(+1)+โˆ‘xi>xwiโ‹…(โˆ’1)fxโ€ฒ(x)=โˆ‘xi<xwiโˆ’โˆ‘xi>xwi

The function fx(x) is minimized at the point xโˆ— where the difference is zero, meaning the total weight "pulling" to the left equals the total weight "pulling" to the right. This transition occurs precisely at the weighted median xk because, by definition, xk is the first point where the cumulative weight S reaches W/2.

For the time bound, the algorithm is dominated by the sorting step. Let n be the number of points. Calculating W takes O(n) time. Sorting the n pairs takes O(nlogโกn) time. The final pass to find the median takes O(n) time. Since this procedure is run twice, the total time complexity is O(nlogโกn)+O(nlogโกn)=O(nlogโกn).

Actually, this bound can be improved to O(n) using a Weighted Quickselect algorithm. To guarantee this linear performance and avoid the O(n2) worst case, a non-unbalanced pivot is chosen in linear time using the Median of Medians algorithm as a pivot selection strategy. This reduces the total time complexity for the 2D problem to O(n)+O(n)=O(n), which is asymptotically optimal, although the two algorithms are not so easy to implement.

Exercise 2.2

Let:

Our goal is to prove that the Euclidean cost of our algorithm's solution is at most 2 times the Euclidean cost of the true optimal solution, that is, fe(pmโˆ—)โ‰ค2โ‹…fe(peโˆ—).

We must use two fundamental geometric inequalities that relate the Euclidean distance (de) and Manhattan distance (dm) between any two points:

  1. deโ‰คdm, or ฮ”x2+ฮ”y2โ‰คฮ”x+ฮ”y
  2. dmโ‰ค2โ‹…de, or ฮ”x+ฮ”yโ‰ค2โ‹…ฮ”x2+ฮ”y2

By the definition of fe, we have fe(pmโˆ—)=โˆ‘i=1nwiโ‹…de(pmโˆ—,pi). Applying inequality 1 (deโ‰คdm) to every term in the sum, this is less than or equal to โˆ‘i=1nwiโ‹…dm(pmโˆ—,pi), which is precisely the definition of fm(pmโˆ—). This gives us fe(pmโˆ—)โ‰คfm(pmโˆ—).

Next, we can use the key property of our algorithm, that is pmโˆ— is the point that minimizes fm. Therefore, fm(pmโˆ—) must be less than or equal to the Manhattan cost of any other point, including the true Euclidean optimal point peโˆ—. This is fm(pmโˆ—)โ‰คfm(peโˆ—).

Now, we apply inequality 2 (dmโ‰ค2โ‹…de) to every term in the sum fm(peโˆ—)=โˆ‘i=1nwiโ‹…dm(peโˆ—,pi). This yields โˆ‘i=1nwiโ‹…2โ‹…de(peโˆ—,pi). By factoring out the 2 constant, we get 2โ‹…โˆ‘i=1nwiโ‹…de(peโˆ—,pi), which is by definition equal to 2โ‹…fe(peโˆ—).