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 ...
随机推荐
- [译] UML中的关系之Dependency
在UML中,依赖关系表示Client依赖于另一个元素,叫做Supplier. 通常来说,依赖关系不需要特殊的名字. 依赖的类别 抽象 abstraction, derive, refine, trac ...
- hdu 3183 贪心
题意:给一个数字,删掉其中的若干位,使得最后的数字最小 就是每次删除数的时候都是删掉第一个比右边数大的数 利用双向链表模拟 #include<cstdio> #include<ios ...
- poj 1087 最大流
没啥好说的,慢慢建图 Sample Input 4 A B C D 5 laptop B phone C pager B clock B comb X 3 B X X A X D Sample Out ...
- C++的那些事:函数全解析
一.函数的结构 函数在C++中可能出现在三种地方,一是函数的定义,它包括了如上图的结构:二是函数的声明,它与函数的定义相比,没有了函数体部分:三则是函数的调用.当然,不同的函数定义可以还会稍有不同,比 ...
- K-集合 (JXNU第二次周赛1006)set/平衡树
K-集合 Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other) Total Submissi ...
- 【HTML5】video视频
当前,video 元素支持三种视频格式: 格式 IE Firefox Opera Chrome Safari Ogg No 3.5+ 10.5+ 5.0+ No MPEG 4 9.0+ No No 5 ...
- SU sufdmod2命令学习
- js:数据结构笔记12--排序算法(2)
高级排序算法:(处理大数据:百万以上) 希尔排序:是插入排序的优化版: 首先设置间隔数组,然后按照每个间隔,分别进行排序: 如第一个间隔为5,首先a[5]与a[0]进行插入排序;然后a[6]和a[0] ...
- ZOJ2539 Energy Minimization(最小割)
题目大概说,给一个n个格子的矩阵,每个格子都有一个数字pi.求这个函数的最小值: 其中xi的取值是0或1,v0.v1已知,j是和i在矩阵中上下左右相邻的位置且j>i. 这个式子有三个加数组成A+ ...
- POJ 1064 (二分)
题目链接: http://poj.org/problem?id=1064 题目大意:一堆棍子可以截取,问要求最后给出K根等长棍子,求每根棍子的最大长度.保留2位小数.如果小于0.01,则输出0.00 ...