We show for several computational problems how classical greedy algorithms for special cases can be derived in a simple way from dynamic programs for the general case: interval scheduling (restricted to unit weights), knapsack (restricted to unit values), and shortest paths (restricted to nonnegative edge lengths). Conceptually, we repeatedly expand the Bellman equations underlying the dynamic program and use straightforward monotonicity properties to figure out which terms yield the optimal value under the respective restrictions. The approach offers an alternative for developing these greedy algorithms in undergraduate algorithms courses and/or for arguing their correctness. In the setting of interval scheduling, it elucidates the change in order from earliest start time first for the memoized dynamic program to earliest finish time first for the greedy algorithm.
翻译:我们针对若干计算问题展示了如何从一般情况的动态规划简单推导出特殊情况的经典贪心算法:区间调度(限于单位权重)、背包问题(限于单位价值)和最短路径(限于非负边权)。从概念上,我们反复展开动态规划背后的贝尔曼方程,并利用直接的单调性性质来确定在相应限制条件下哪些项产生最优值。该方法为本科生算法课程中讲解这些贪心算法的构建和/或论证其正确性提供了另一种视角。在区间调度场景中,该方法阐明了从记忆化动态规划的"最早开始时间优先"到贪心算法的"最早结束时间优先"的排序转变。