views:

367

answers:

3

Suppose I have an interval (a,b), and a number of subintervals {(ai,bi)}i whose union is all of (a,b). Is there an efficient way to choose a minimal-cardinality subset of these subintervals which still covers (a,b)?

+1  A: 

Sounds like dynamic programming.

Here's an illustration of the algorithm (assume intervals are in a list sorted by ending time):

//works backwards from the end
int minCard(int current, int must_end_after)
{
    if (current < 0)
        return 0; //no more intervals needed
    if (intervals[current].end < must_end_after)
        return infinity; //doesn't cover (a,b)

    return min( 1 + minCard(current - 1, intervals[current].start),
                minCard(current - 1, must_end_after) );
           //include current interval or not?
}

But it should also involve caching (memoisation).

Artelius
`minCard()` is intended to get a minimal cardinality but the question asks for a subset with minimal cardinality.
J.F. Sebastian
It would just be an extension of this algorithm that also keeps track of which subset was used to form that optimum value.
Artelius
A: 

You mean so that the subintervals still overlap in such a way that (a,b) remains completely covered at all points?

Maybe splitting up the subintervals themselves into basic blocks associated with where they came from, so you can list options for each basic block interval accounting for other regions covered by the subinterval also. Then you can use a search based on each sub-subinterval and at least be sure no gaps are left.
Then would need to search.. efficiently.. that would be harder.

Could eliminate any collection of intervals that are entirely covered by another set of smaller number and work the problem after the preprocessing.
Wouldn't the minimal for the whole be minimal for at least one half? I'm not sure.

Found a link to a journal but couldn't read it. :(

This would be a hitting set problem and be NP_hard in general.
Couldn't read this either but looks like opposite kind of problem.
Couldn't read it but another link that mentions splitting intervals up.
Here is an available reference on Randomized Algorithms for GeometricOptimization Problems.
Page 35 of this pdf has a greedy algorithm.
Page 11 of Karp (1972) mentions hitting-set and is cited alot.
Google result. Researching was fun but I have to go now.

waynecolvin
+4  A: 

A greedy algorithm starting at a or b always gives the optimal solution.

Proof: consider the set Sa of all the subintervals covering a. Clearly, one of them has to belong to the optimal solution. If we replace it with a subinterval (amax,bmax) from Sa whose right endpoint bmax is maximal in Sa (reaches furthest to the right), the remaining uncovered interval (bmax,b) will be a subset of the remaining interval from the optimal solution, so it can be covered with no more subintervals than the analogous uncovered interval from the optimal solution. Therefore, a solution constructed from (amax,bmax) and the optimal solution for the remaining interval (bmax,b) will also be optimal.

So, just start at a and iteratively pick the interval reaching furthest right (and covering the end of previous interval), repeat until you hit b. I believe that picking the next interval can be done in log(n) if you store the intervals in an augmented interval tree.

Rafał Dowgird
Could you elaborate: "the remaining uncovered interval (bmax,b) will be a subset of the remaining interval from the optimal solution"?
J.F. Sebastian
I believe this solution works, and it's better than mine.
Artelius
@JFS: Suppose that the optimal solution starts with an interval (ai,bi) that covers (a,bi) and leaves (bi,b) uncovered. From the definition of (amax,bmax) we have that bmax>=bi, so (bmax,b) is a subset (subinterval) of (bi,b).
Rafał Dowgird
You're welcome :)
Rafał Dowgird