We present an improved solution to the Weighted Job Scheduling (WJS) problem. While the classical dynamic programming (DP) solution for $n$ jobs runs in $O(n \log(n))$ time due to comparison-based sorting and per-job binary search, we eliminate the binary search bottleneck. In its place, we introduce a novel multi-phase preprocessing technique called \emph{Global Predecessor Indexing (GPI)}, which computes the latest non-overlapping job (i.e., the predecessor) for all jobs via a two-pointer linear-time pass after sorting. This yields a time complexity of $O(S(n) + n)$ where $S(n)$ is the time to sort all jobs. GPI enables direct use in the classical DP recurrence. When combined with linear-time sorting, GPI yields a complete $O(n)$ solution. Even with comparison-based sorting, GPI significantly outperforms the classical solution in practice by avoiding repeated binary searches in favor of the more cache-efficient extra sort and two-pointer pass.
翻译:我们提出了一种针对加权作业调度问题的改进解决方案。虽然针对 $n$ 个作业的经典动态规划解决方案由于基于比较的排序和每个作业的二分查找而具有 $O(n \log(n))$ 的时间复杂度,但我们消除了二分查找这一瓶颈。取而代之,我们引入了一种新颖的多阶段预处理技术,称为 \emph{全局前驱索引}。该技术在排序后,通过一次双指针线性时间遍历,为所有作业计算其最新的非重叠作业。这实现了 $O(S(n) + n)$ 的时间复杂度,其中 $S(n)$ 是对所有作业进行排序所需的时间。GPI 使得经典动态规划递推式可以直接使用。当与线性时间排序结合时,GPI 产生了一个完整的 $O(n)$ 解决方案。即使在基于比较的排序下,GPI 在实践中也显著优于经典解决方案,因为它避免了重复的二分查找,转而采用缓存效率更高的额外排序和双指针遍历。