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.
翻译:针对若干计算问题,我们展示了如何从一般情形的动态规划中简洁地推导出特殊情形下的经典贪心算法:区间调度(限于单位权重)、背包问题(限于单位价值)以及最短路径(限于非负边权)。从概念上,我们反复展开动态规划所基于的贝尔曼方程,并利用直观的单调性性质来确定在相应限制下哪些项能产生最优值。该方法为在本科算法课程中讲授这些贪心算法和/或论证其正确性提供了一种替代思路。在区间调度问题中,该方法阐明了从记忆化动态规划的"最早开始时间优先"到贪心算法的"最早结束时间优先"的排序转变。