A dynamic programming approach can be used for computing an optimal solution for IP if there is such. An optimal partition can be found amongst the set of endpoints as we have seen from theorem 1 in the previous section. We will refer to the elements in the set of endpoints as with qi < qi+1 for all .
We first describe the algorithm IP-opt informally. It starts with q1 and goes through to qn. For each qi it will hold the necessary information for an optimal partition for the span ending at qi, i.e. for the segment , with all intervals in R intersecting with the partial span being considered. The algorithm computes two items of information for each qi:
There is no optimal partition if - for any qi - there is no qj with j<i such that the number of intervals intersecting with the segment (qj,qi], i.e. , is less than the maximum load of X intervals. The loads involving the dummy point are defined as
The algorithm then looks as shown in figure 5.5.
The algorithm IP-opt for computing an optimal
partition for an instance of IP.
The run time complexity is O(n2) as the min-function is O(n).
Computing the values for the -function is O(n2) and can be
done beforehand. Similarly, computing the values for is
O(n).