我正在研究Kleinberg的“算法设计”中的一个问题,特别是问题4.15。我目前没有参加与此相关的课程 - 在新课程开始之前,我正在解决问题,看看我是否能够做到这一点。问题如下:
The manager of a large student union on campus comes to you with the
following problem. She’s in charge of a group of n students, each of whom
is scheduled to work one shift during the week. There are different jobs
associated with these shifts (tending the main desk, helping with package
delivery, rebooting cranky information kiosks, etc.), but.we can view each
shift as a single contiguous interval of time. There can be multiple shifts
going on at once.
She’s trying to choose a subset of these n students to form a super-
vising committee that she can meet with once a week. She considers such
a committee to be complete if, for every student not on the committee,
that student’s shift overlaps (at least partially) the shift of some student
who is on the committee. In this way, each student’s performance can be
observed by at least one person who’s serving on the committee.
Give an efficient algorithm that takes the schedule of n shifts and
produces a complete supervising committee containing as few students
as possible.
Example. Suppose n = 3, and the shifts are
Monday 4 p.M.-Monday 8 P.M.,
Monday 6 p.M.-Monday 10 P.M.,
Monday 9 P.M.-Monday 1I P.M..
Then the smallest complete supervising committee would consist of just
the second student, since the second shift overlaps both the first and the
third.
我的尝试(我在解决方案手册中找不到这个问题,所以我在这里问):
Construct a graph G with vertices S1, S2, ..., Sn for each student.
Let there be an edge between Si and Sj iff students i and j have an overlapping
shift. Let C represent the set of students in the supervising committee.
[O(n + 2m) to build an adjacency list, where m is the number of shifts?
Since we have to add at least each student to the adjacency list, and add an
additional m entries for each shift, with two entries added per shift since
our graph is undirected.]
Sort the vertices by degree into a list S [O(n log n)].
While S[0] has degree > 0:
(1) Add Si to C. [O(1)]
(2) Delete Si and all of the nodes that it was connected to, update the
adjacency list.
(3) Update S so that it is once again sorted.
Add any remaining vertices of degree 0 to C.
我不确定如何量化(2)和(3)的运行时间。由于任何节点的程度都以n为界,似乎(2)以O(n)为界。但是(1)中删除的节点的程度也会影响while
循环内部执行的迭代次数,所以我怀疑可以说出整个while
循环的上限。 - “任何删除序列都将涉及在线性时间内删除最多n个节点并在线性时间内最多占用n个节点,导致{{1}的O(n log n)的上限}循环,因此整个算法。“
答案 0 :(得分:1)
您不希望将此转换为常规图形问题,因为它只是NP难度vertex cover问题。但是,特别是在interval graphs上,实际上有一个线性时间贪婪算法,如this paper中所述(实际上这是一个更普遍的问题,但在这里工作正常)。从快速阅读它,这是它如何适用于您的问题:
n
。k = 1
,代表最不在委员会中的订单中的学生。 k
开始,找到顺序中第一个学生,其班次不与学生k
的班次相交。假设这是学生i
。将学生i-1
添加到委员会,并将k
更新为委员会未涵盖的最早的新学生。(这感觉是正确的,但就像我说我只有一个快速阅读,所以请说如果我错过了什么)