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. MVC的处理过程

    MVC的处理过程,首先控制器接受用户的请求,并决定应该调用哪个模型来进行处理,然后模型用业务逻辑来处理用户的请求并返回数据,最后控制器用相应的视图格式化模型返回的数据,并通过表示层呈现给用户.

  2. MATLAB学习笔记(十一)——MATLAB图形用户界面设计

    (一)菜单设计 一.建立用户菜单 1.概况: 用户菜单一般含有一级菜单和二级菜单,乃至多级菜单.每一级菜单又包含多个菜单项.建立菜单可以使用uimenu函数. 2.uimenu函数调用: %建立一级菜 ...

  3. Session: 防止用户多次登陆

    在web开发时,有的系统要求同一个用户在同一时间只能登录一次,也就是如果一个用户已经登录了,在退出之前如果再次登录的话需要报错. 常见的处理方法是,在用户登录时,判断此用户是否已经在Applicati ...

  4. Java入门知识点:

    1.跨平台性主要原理是:在需要运行的java应用程序的操作系统上安装了一个对应操作系统对应版本的JVM(Java Virtual Machine)java虚拟机即可,由JVM来负责Java程序的在该系 ...

  5. js:语言精髓笔记12--动态语言特性(2)

    对于括号内: 通过赋值时发生的重写: (Object1 = function() {}).prototype.value = 100; var obj1 = new Object1; console. ...

  6. DP VK Cup 2012 Qualification Round D. Palindrome pairs

    题目地址:http://blog.csdn.net/shiyuankongbu/article/details/10004443 /* 题意:在i前面找回文子串,在i后面找回文子串相互配对,问有几对 ...

  7. Week,Month, Year 日期区间辅助类

    我们在做一些业务系统的时候,经常会用到一些获取时间段的情况.比如要统计某一周.某月.某年 这样一些时间区间内的一些业务数据.这时候我们就需要获取当前时间段内的一些起止日期.这里分享一个通用的日期辅助类 ...

  8. 【BZOJ】2330: [SCOI2011]糖果(差分约束+spfa)

    http://www.lydsy.com/JudgeOnline/problem.php?id=2330 差分约束运用了最短路中的三角形不等式,即d[v]<=d[u]+w(u, v),当然,最长 ...

  9. 实现自己的Linq to Sql

    之前写过一篇<统一的仓储接口>,为了方便使用不同的仓储.在我们的项目中使用的是EF4.0,但是这个版本的EF有一些性能问题没有解决,又不想升级到EF6,具体EF6有没有解决暂时不清楚.我们 ...

  10. 什么是SQL注入式攻击

    什么是SQL注入式攻击? 所谓SQL注入式攻击,就是攻击者把SQL命令插入到Web表单的输入域或页面请求的查询字符串,欺骗服务器执行恶意的SQL命令.在某些表单中,用户输入的内容直接用来构造(或者影响 ...