Find the smallest subset of overlapping intervals

陌路散爱 提交于 2019-12-24 17:02:39

问题


Consider a question to find a minimum dominating set of an interval graph. In the context of interval scheduling, it is converted to the question below:

There are multiple intervals which may or may overlap with each other. Find a minimum subset of the intervals, so that for every interval that is not included in the subset, it will find at least 1 interval in the subset that will overlap with it.

There is an agreed greedy solution available from various sources on the Internet, such as one solution from Cornell: http://www.cs.cornell.edu/Courses/cs4820/2011sp/handouts/samplesolutions.pdf

We work to fill up a set C which makes up the committee (subset of intervals). We use a set M to hold ’covered’ intervals for bookkeeping.

  1. Sort the intervals by finish time with earliest finish time first.
  2. Take the interval i in S with earliest finish time.
  3. Construct set O = {s ∈ S|s intersects i}
  4. Take o ∈ O with the latest finish time and add o to C, add all the intervals that intersect with o to M
  5. repeat 2-4 until all intervals are covered.

This is similar to a voted up answer provided by interjay in 2012 on SO: Find the smallest set of overlapping jobs

But I have noticed a counterexample that proves the above solution does not produce the minimum subset:

Consider intervals: [0,2], [1,4], [3,10], [5, 6], [7,8], [9, 10].

A minimum subset should have 2 intervals: [3, 10] plus either [0, 2] or [1, 4].

But the above solution will return a subset of 4 intervals: [1,4], [5,6], [7,8] and [9,10]. The longest interval [3,10] was prematurely rejected at step 4.

Is there a better greedy solution than the ones posted above? Thanks!


回答1:


The algorithm you quoted is incorrect because the set S never changes, so in step 2 the same interval will always be picked and you will enter an infinite loop. If you change step 2 to "Take the interval i in S-M with earliest finish time.", it will be correct.

My answer which you linked is correct however. Both it and the corrected algorithm above will give the set {[1,4], [3,10]} for your example.

The mistake you're making may be that in step 3 above (or step 2 in my linked answer) you're looking only at sets which are in S-M (called A in my answer). But you should look at all intervals that intersect i, even if they are already in M.



来源:https://stackoverflow.com/questions/26170904/find-the-smallest-subset-of-overlapping-intervals

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!