Algorithm 可变调度算法

Algorithm 可变调度算法,algorithm,language-agnostic,scheduling,time-complexity,pseudocode,Algorithm,Language Agnostic,Scheduling,Time Complexity,Pseudocode,我正在研究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 wo

我正在研究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.
我的尝试(我在解决方案手册中找不到这个问题,所以我在这里提问):


我不确定如何量化(2)和(3)的运行时。因为任何节点的度都是以n为界的,所以(2)似乎是以O(n)为界的。但是在(1)中删除的节点的程度也会影响
while
循环内部执行的迭代次数,因此我怀疑有可能对整个
while
循环的上界说些什么——这是“任何删除序列都将涉及在线性时间内删除最多n个节点,并在线性时间内重新调用最多n个节点,从而导致
while
循环的上界为O(n log n),从而导致整个算法的上界。“

你不想把它转化为一个一般的图问题,因为它只是一个NP难问题。然而,特别是在上,实际上有一个线性时间贪婪算法,如中所述(这实际上是针对一个更一般的问题,但在这里效果很好)。通过快速阅读,以下是它如何应用于您的问题:

  • 按照轮班结束的时间对学生进行排序,从早到晚。将它们编号为1到
    n
  • 初始化计数器
    k=1
    ,该计数器代表排序中不在委员会中的最早学生
  • k
    开始,按照其班次与学生
    k
    班次相交的顺序查找第一个学生。假设这是学生
    i
    。将学生
    i-1
    添加到委员会,并将
    k
    更新为委员会未涵盖的最早新学生
  • 重复上一步,直到涵盖所有学生

(这感觉是对的,但就像我说的,我只是快速阅读了一下,所以如果我遗漏了什么,请说)

这听起来更像书中列出的调度算法。如果我理解正确的话,你基本上是在说:“虽然有一些学生在委员会中没有人值班:1)将在当前“群体”中最后完成的学生添加到委员会中,并移除该群体。”对吗?“群体”感觉有误导性,因为输入可能一点也不笨拙,你必须以特定的顺序考虑学生,但是是的。这篇论文描述的方式是“不要把一个学生加入委员会,除非超过他们会保证有人没有被发现”。学生有一个排序是至关重要的,这是它与一般顶点覆盖问题的区别。相反,如何处理:在排序中最早的学生而不是委员会(第i个)中,选择导师作为其班次与大多数班次重叠的学生,这些班次也与第i个学生重叠。这不是更为理想,同时也同样有效吗?
    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.