7

Given a list of intervals with integral endpoints, we want to find out if we can choose one integer from each interval so that no two chosen numbers are adjacent. Can we do this in polynomial time?

My attempt is the following greedy strategy: Sort the intervals by the smaller left endpoint, breaking ties by the smaller right endpoint. Then, as long as possible, choose the leftmost feasible number from each interval.

However, this doesn't work: the first interval may be $[5,9]$ and the second interval $[6,6]$. Choosing $5$ from the first interval rules out choosing anything from the second interval. It would be better to choose $6$ from the second interval and $8$ from the first interval.

simmons
  • 131
  • 4

2 Answers2

3

This problem can be regarded as a scheduling problem.

Each interval corresponds to a job. For each interval $[L_i,R_i]$, Let $r_i = L_i$ be the release time, $d_i = R_i + 2$ be the deadline, and $p_i = 2$ be the job length. Then, single-machine no-preemption scheduling corresponds to a solution. Scheduling with non-integer start times can be converted to integer start times by taking the floor function, and the schedule remains feasible.

This problem has an $O(n \log n)$-time solution [1].

  • [1] Garey, Michael R., et al. "Scheduling unit–time tasks with arbitrary release times and deadlines." SIAM Journal on Computing (1981).
pcpthm
  • 2,962
  • 6
  • 16
1

I had an idea for a polynomial time algorithm, but here is a counter-example. I leave it visible for the sake of having an interesting input instance. I thought that the decisions didn't propagate too far, but that's clearly not true.

$I = \{ [1,8], [2,3], [3,5], [5,6] \}$. The solution is $\{2,4,6,8\}$.

Invalid solution

 1  2  3  4  5  6  7  8
[·                     ]
   [   ·]
      [      ·]
            [    ]

Valid solution

 1  2  3  4  5  6  7  8
[                     ·]
   [·   ]
      [   ·   ]
            [   ·]

I'm reminded of Hall's theorem here. You could say that for it to be a yes instance, every subset of intervals $S$ need to have $\text{span}(S) \geq 2|S| - 1$, and the intervals $S = \{ [2,3], [3,5], [5,6] \}$ have span $4 < 2\cdot 3 - 1 = 5$.

Ainsley H.
  • 17,823
  • 3
  • 43
  • 68