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 ...
随机推荐
- phpcms v9 如何实现用户登录
因为有时候我们需要自己实现用户登录,比如我们用phpcms做一个微信Oauth2.0授权,授权之后直接登录,这过程中不需要用户输入账户和密码.所以我们就要搞清楚,phpcmsv9它是怎么实现用户登录的 ...
- C#学习笔记(七)——定义类
一.C#中类的定义 1.类的定义 class Myclass { } 默认情况下是类是内部的,即外部的项目是不可以访问这个类,相当于加internal来修饰.但实际上是不需要加入的. 如果要指定类是公 ...
- java中异步多线程超时导致的服务异常
在项目中为了提高大并发量时的性能稳定性,经常会使用到线程池来做多线程异步操作,多线程有2种,一种是实现runnable接口,这种没有返回值,一种是实现Callable接口,这种有返回值. 当其中一个线 ...
- js:数据结构笔记5--链表
数组: 其他语言的数组缺陷:添加/删除数组麻烦: js数组的缺点:被实现为对象,效率低: 如果要实现随机访问,数组还是更好的选择: 链表: 结构图: 基本代码: function Node (elem ...
- [LintCode] Word Break
Given a string s and a dictionary of words dict, determine if s can be break into a space-separated ...
- 简单几何(直线与圆的交点) ZOJ Collision 3728
题目传送门 题意:有两个一大一小的同心圆,圆心在原点,大圆外有一小圆,其圆心有一个速度(vx, vy),如果碰到了小圆会反弹,问该圆在大圆内运动的时间 分析:将圆外的小圆看成一个点,判断该直线与同心圆 ...
- 递推DP URAL 1353 Milliard Vasya's Function
题目传送门 /* 题意:1~1e9的数字里,各个位数数字相加和为s的个数 递推DP:dp[i][j] 表示i位数字,当前数字和为j的个数 状态转移方程:dp[i][j] += dp[i-1][j-k] ...
- DFS/BFS Codeforces Round #301 (Div. 2) C. Ice Cave
题目传送门 /* 题意:告诉起点终点,踩一次, '.'变成'X',再踩一次,冰块破碎,问是否能使终点冰破碎 DFS:如题解所说,分三种情况:1. 如果两点重合,只要往外走一步再走回来就行了:2. 若两 ...
- Task加入取消功能
参考:http://www.cnblogs.com/scy251147/archive/2013/01/04/2843875.html static void TaskWithCancellati ...
- POJ3659 Cell Phone Network(树上最小支配集:树型DP)
题目求一棵树的最小支配数. 支配集,即把图的点分成两个集合,所有非支配集内的点都和支配集内的某一点相邻. 听说即使是二分图,最小支配集的求解也是还没多项式算法的.而树上求最小支配集树型DP就OK了. ...