an optimal solution to the problem
http://www.personal.kent.edu/~rmuhamma/Algorithms/MyAlgorithms/Greedy/greedyIntro.htm

Greedy Introduction

Greedy algorithms are simple and straightforward. They are shortsighted in their approach in the sense that they take decisions on the basis of information at hand without worrying about the effect these decisions may have in the future. They are easy to invent, easy to implement and most of the time quite efficient. Many problems cannot be solved correctly by greedy approach. Greedy algorithms are used to solve optimization problems
Greedy Approach
Greedy Algorithm works by making the decision that seems most promising at any moment; it never reconsiders this decision, whatever situation may arise later.
As an example consider the problem of "Making Change".
Coins available are:
- dollars (100 cents)
- quarters (25 cents)
- dimes (10 cents)
- nickels (5 cents)
- pennies (1 cent)
Problem Make a change of a given amount using the smallest possible number of coins.
Informal Algorithm
- Start with nothing.
- at every stage without passing the given amount.
- add the largest to the coins already chosen.
Formal Algorithm
Make change for n units using the least possible number of coins.
MAKE-CHANGE (n)
C ← {100, 25,
10, 5, 1} // constant.
Sol ←
{};
// set that
will hold the solution set.
Sum ← 0 sum of
item in solution set
WHILE sum not = n
x =
largest item in set C such that sum + x ≤ n
IF
no such item THEN
RETURN "No Solution"
S ← S {value of
x}
sum ← sum + x
RETURN S
Example
Make a change for 2.89 (289 cents) here n =
2.89 and the solution contains 2 dollars, 3 quarters, 1 dime and 4
pennies. The algorithm is greedy because at every stage it chooses the
largest coin without worrying about the consequences. Moreover, it
never changes its mind in the sense that once a coin has been included
in the solution set, it remains there.
Characteristics
and Features of Problems solved by Greedy Algorithms
To construct the solution in an optimal way. Algorithm maintains
two sets. One contains chosen items and the other contains rejected
items.
The greedy algorithm consists of four (4) function.
- A function that checks whether chosen set of items provide a solution.
- A function that checks the feasibility of a set.
- The selection function tells which of the candidates is the most promising.
- An objective
function, which does not appear explicitly, gives the value of a solution.
Structure
Greedy Algorithm
- Initially the set of chosen items is empty i.e.,
solution set. - At each step
- item will be added in a solution set by using
selection function. - IF the set would no longer be feasible
- reject items under consideration (and is
never consider again).
- reject items under consideration (and is
- ELSE IF set is still feasible THEN
- add the current item.
- item will be added in a solution set by using
Definitions of
feasibility
A feasible set (of
candidates) is promising if it can be extended to produce not merely a
solution, but an optimal solution to the problem. In particular, the
empty set is always promising why? (because an optimal solution always
exists)
Unlike Dynamic Programming, which solves the
subproblems bottom-up, a greedy strategy usually progresses in a
top-down fashion, making one greedy choice after another, reducing each
problem to a smaller one.
Greedy-Choice
Property
The "greedy-choice property" and "optimal
substructure" are two ingredients in the problem that lend to a greedy
strategy.
Greedy-Choice
Property
It says that a globally optimal solution can be
arrived at by making a locally optimal choice.


an optimal solution to the problem的更多相关文章
- Solution to LeetCode Problem Set
Here is my collection of solutions to leetcode problems. Related code can be found in this repo: htt ...
- Optimal binary search trees
问题 该问题的实际应用 Suppose that we are designing a program to translate text from English to French. For ea ...
- maker 2008年发表在genome Res
http://gmod.org/wiki/MAKER_Tutorial 简单好用 identify repeats, to align ESTs and proteins to the genome, ...
- [zt]Which are the 10 algorithms every computer science student must implement at least once in life?
More important than algorithms(just problems #$!%), the techniques/concepts residing at the base of ...
- ASP.NET操作WMI
WMI Functions from ASP.NET Introduction This article demonstrates how to use WMI in ASP.NET to cre ...
- Greedy is Good
作者:supernova 出处:http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=greedyAlg Joh ...
- CABaRet: Leveraging Recommendation Systems for Mobile Edge Caching
CABaRet:利用推荐系统进行移动边缘缓存 本文为SIGCOMM 2018 Workshop (Mobile Edge Communications, MECOMM)论文. 笔者翻译了该论文.由于时 ...
- 【CV知识学习】early stop、regularation、fine-tuning and some other trick to be known
深度学习有不少的trick,而且这些trick有时还挺管用的,所以,了解一些trick还是必要的.上篇说的normalization.initialization就是trick的一种,下面再总结一下自 ...
- Siimple DP (Dynamic Programing)
HDU 2084:https://vjudge.net/problem/HDU-2084 Problem Describe : When it comes to the DP algorithm, a ...
随机推荐
- [译]SQL Server 之 索引基础
SQL Server中,索引以B-tree的结构组织数据.B-tree代表平衡树,但是SQL Server使用一种叫做B+的树. B+树不是总是保持严格的平衡的树. 首先,索引有两个主要的部件:一个页 ...
- 一个自动生成插入与更新SQL语句的小类
无需关注字段类型,只要传入字段名与值的集合,自动生成Ms sql server SQL语句.详见Test()方法 using System; namespace Fan.iData.SqlUtilit ...
- Selenium测试规划
开源工具经过近几年的发展,已经出现了一大批成熟的可应用到实际项目中的产品,其中,在WEB自动化测试领域,Selenium支持广泛的浏览器和脚本开发语言,高效的执行效率,获得广泛的应用. 本课程结合Se ...
- WPF/Silverlight HierarchicalDataTemplate 模版的使用(转)
上一篇 对Wpf/Silverlight Template 进行了总结,本篇继续上一篇,主要是介绍 HierarchicalDataTemplate 的使用方法.HierarchicalDataTem ...
- LightOJ1064 Throwing Dice(DP)
第一眼以为是概率DP,我还不会.不过看题目那么短就读读,其实这应该还不是概率DP,只是个水水的DP.. dp[n][s]表示掷n次骰子点数和为s的情况数 dp[0][0]=1 dp[i][j]=∑dp ...
- vi/vim键盘图-----又一张桌面背景好图
也许还是有很多人不能愿意用CLI的vi/Vim来写东西,不过,当你真的习惯了,它的高效性就是不可估量了.下面的这张图,一看就明白了,从此,学习变的不再艰难^_^ 补注: 图中没有关于查找和替换的,应该 ...
- CC150 - 11.3
Question: Given a sorted array of n integers that has been rotated an unknown number of times, write ...
- 【BZOJ】1877: [SDOI2009]晨跑(最小费用最大流)
http://www.lydsy.com/JudgeOnline/problem.php?id=1877 费用流做多了,此题就是一眼题. 拆点表示只能经过一次,容量为1,费用为0. 然后再连边即可,跑 ...
- sql中的视图
视图可分为:普通视图和索引视图视图的作用: 1.提高数据库的安全性,降低数据库被攻击的风险,使外界无法得知数据库的数据结构 2.使查询更方便,简化程序员的操作非只读视图可以增删改,但不建议.视图的试用 ...
- c#操作excel后关闭excel.exe的方法
关闭进程 C#和Asp.net下excel进程一被打开,有时就无法关闭, 尤其是website.对关闭该进程有过GC.release等方法,但这些方法并不是在所有情况下均适用. 于是提出了kil ...