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.

  1. A function that checks whether chosen set of items provide a solution.
  2. A function that checks the feasibility of a set.
  3. The selection function tells which of the candidates is the most promising.
  4. 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).
    • ELSE IF set is still feasible THEN
      • add the current item.

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的更多相关文章

  1. Solution to LeetCode Problem Set

    Here is my collection of solutions to leetcode problems. Related code can be found in this repo: htt ...

  2. Optimal binary search trees

    问题 该问题的实际应用 Suppose that we are designing a program to translate text from English to French. For ea ...

  3. maker 2008年发表在genome Res

    http://gmod.org/wiki/MAKER_Tutorial 简单好用 identify repeats, to align ESTs and proteins to the genome, ...

  4. [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 ...

  5. ASP.NET操作WMI

    WMI Functions from ASP.NET   Introduction This article demonstrates how to use WMI in ASP.NET to cre ...

  6. Greedy is Good

    作者:supernova 出处:http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=greedyAlg Joh ...

  7. CABaRet: Leveraging Recommendation Systems for Mobile Edge Caching

    CABaRet:利用推荐系统进行移动边缘缓存 本文为SIGCOMM 2018 Workshop (Mobile Edge Communications, MECOMM)论文. 笔者翻译了该论文.由于时 ...

  8. 【CV知识学习】early stop、regularation、fine-tuning and some other trick to be known

    深度学习有不少的trick,而且这些trick有时还挺管用的,所以,了解一些trick还是必要的.上篇说的normalization.initialization就是trick的一种,下面再总结一下自 ...

  9. Siimple DP (Dynamic Programing)

    HDU 2084:https://vjudge.net/problem/HDU-2084 Problem Describe : When it comes to the DP algorithm, a ...

随机推荐

  1. 三种方法实现js跨域访问

    转自:http://narutolby.iteye.com/blog/1464436 javascript跨域访问是web开发者经常遇到的问题,什么是跨域,一个域上加载的脚本获取或操作另一个域上的文档 ...

  2. 测试服务API的_苏飞开发助手_使用说明

    1 工具说明_json对象字符串拼接 2 工具说明_纯字符串拼接

  3. SURF算法与源码分析、上

    如果说SIFT算法中使用DOG对LOG进行了简化,提高了搜索特征点的速度,那么SURF算法则是对DoH的简化与近似.虽然SIFT算法已经被认为是最有效的,也是最常用的特征点提取的算法,但如果不借助于硬 ...

  4. 【bzoj1066】[SCOI2007]蜥蜴 网络最大流

    [bzoj1066][SCOI2007]蜥蜴 Description 在一个r行c列的网格地图中有一些高度不同的石柱,一些石柱上站着一些蜥蜴,你的任务是让尽量多的蜥蜴逃到边界外. 每行每列中相邻石柱的 ...

  5. (转载)数据库表设计-水电费缴费系统(oracle)

    水电缴费管理系统数据表设计 SQL建表脚本: 1 --建表 2 --管理人员表 admin 3 create table admin( 4 admin_id varchar2(3) not null, ...

  6. Eclipse中导入外部jar包

    首先在项目下创建一个文件夹,保存我们的jar包. 在项目名上右击,依次点击[New]-->[Floder],打开新建文件夹窗口   输入文件夹名称[lib],点击[ok].我们通常在lib文件夹 ...

  7. android自定义弹出框样式实现

    前言: 做项目时,感觉Android自带的弹出框样式比较丑,很多应用都是自己做的弹出框,这里也试着自己做了一个. 废话不说先上图片: 实现机制 1.先自定义一个弹出框的样式 2.自己实现CustomD ...

  8. JS一个根据时区输出时区时间的函数

    做项目遇到的坑爹问题,需要根据时区获取时区中轴线的时间.为此搜了好久网上都没什么JS的代码描述到这一方面,最后自己翻了下高中地理才写了个函数出来. 此图可以看出来,全球分为了0时区,东西1-11区,第 ...

  9. JAVA,JSP新建默认UTF-8

    要让一个 Java 源文件打开时编码格式为 UTF-8,需要做2件事情:1)设置Java 源文件的默认编码格式为UTF-8:2)设置workspace的编码格式为UTF-8. 相应设置如下: 设置 J ...

  10. json学习系列(7)JSONBuilder的用法

    JSONBuilder可以向文件中写入写入json字符串.如下面的例子: public class Test { public static void main(String args[]) thro ...