1 / 59
文档名称:

算法与程序设计 贪心算法.ppt

格式:ppt   大小:493KB   页数:59页
下载后只包含 1 个 PPT 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

算法与程序设计 贪心算法.ppt

上传人:xiang1982071 2018/1/21 文件大小:493 KB

下载得到文件列表

算法与程序设计 贪心算法.ppt

相关文档

文档介绍

文档介绍:Greedy algorithm’s paradigm
Algorithm is greedy if
it builds up a solution in small steps
it chooses a decision at each step myopically to optimize some underlying criterion
Analyzing optimal greedy algorithms by showing that:
in every step it is not worse than any other algorithm, or
every algorithm can be gradually transformed to thegreedy one without hurting its quality
1
Interval scheduling
Input: set of intervals on the line, represented by pairs of points (ends of intervals). In another word, the ith interval, starts at time si and finish at fi.
Output: finding the largest set of intervals such that none two of them overlap. Or the maximum number of intervals that without overlap.
Greedy algorithm:
Select intervals one after another using some rule
2
Rule 1
Select the interval which starts earliest (but not overlapping the already chosen intervals)
Underestimated solution!
Algorithm #1
OPT #4
3
Rule 2
Select the interval which is shortest (but not overlapping the already chosen intervals)
Underestimated solution!
Algorithm #1
OPT #2
4
Rule 3
Select the interval with the fewest conflicts with other remaining intervals (but still not overlapping the already chosen intervals)
Underestimated solution!
Algorithm #3
OPT #4
5
Rule 4
Select the interval which ends first (but still not overlapping the already chosen intervals)
Quite a nature idea: we ensure that our resource e free as soon as possible while still satisfying one request
Hurray! Exact solution!
6
f1 smallest
Algorithm #3
7
Analysis - exact solution
Algorithm gives non-overlapping intervals:
obvious, since we always choose an interval which does not overlap the previously chosen intervals
The solution is exact:
Let A be the set of intervals obtained by the algorithm,
and OPT be the largest set of pairwise non-overlapping intervals.
We show that A must be as large as OPT
8
Analysis – exact solution cont.
Let and be sorted. By definition of OPT we have k ≤ m
Fact: for e