Upload
nhoel-rs
View
229
Download
0
Embed Size (px)
Citation preview
7/26/2019 Greedy Method Report NHOEL RESOS
1/20
Greedy Method
Reported by: NHOEL C. RESOS
7/26/2019 Greedy Method Report NHOEL RESOS
2/20
The Greedy MethodTechnique
The greedy methodis a general algorithmdesign paradigm, built on the following elements: confgurations: dierent choices, collections, or values
to nd
objective unction: a score assigned to congurations,which we want to either maximie or minimie
!t wor"s best when applied to problems with thegreedy-choiceproperty:
a globally#optimal solution can always be found by aseries of local improvements from a startingconguration$
The Greedy Method 2
7/26/2019 Greedy Method Report NHOEL RESOS
3/20
%hat is a greedy algorithm&
Greedy algorithm: 'an algorithm alwaysma"es the choice that loo"s best at themoment(
)uman beings use greedy algorithms alot
)ow to maximie your nal grade of thisclass&
)ow to become a rich man&
)ow does a casher minimie the number ofcoins to ma"e a change&
7/26/2019 Greedy Method Report NHOEL RESOS
4/20
%hat is a greedy algorithm&
To guarantee that a greedy algorithm iscorrect,
* things have to be proved:
Greedy-choice property: 'we canassemble a globally optimal solution byma"ing locally greedy+optimal choices$(
i$e$ The greedy choice is always part of certainoptimal solution
Optimal substructure: 'an optimal solutionto the problem contains within it optimalsolutions to subproblems$(
i$e$ global optimal solution is constructed fromlocal optimal solutions
7/26/2019 Greedy Method Report NHOEL RESOS
5/20
%hat is Greedy -lgorithm&
!n the hard words: - greedy algorithmisan algorithm that follows theproblem solving heuristics of ma"ing the
locally optimal choice at each stagewiththe hope of nding a global optimum$
+src: http://en$wi"ipedia$org/wi"i/Greedy0algorithm
1implify: 2hoose the best choice that3reachable4 at current state
7/26/2019 Greedy Method Report NHOEL RESOS
6/20
CHARACTERISTICS AND
FEATURES To construct the solution in an optimal way. Algorithm
aintains two sets!
"#ne contains chosen items an$"The other contains re%ecte$ items.
&ree$y algorithms ma'e good local choices in the hope that
They result in!
"An optimal solution.
"Feasi(le solutions.
6
7/26/2019 Greedy Method Report NHOEL RESOS
7/20
C#NTINUED)
The gree$y algorithm consists o* *our +,- *unction.
A *unction that chec's whether chosen set o* items proi$e a
solution. A *unction that chec's the *easi(ility o* a set.
The selection *unction tells which o* the items is the most
promising.
An o(%ectie *unction! which $oes not appear e/plicitly! giesthe alue o* a solution.
7
7/26/2019 Greedy Method Report NHOEL RESOS
8/20
#0TII1ATI#N 0R#23ES
An optimi4ation pro(lem5
&ien a pro(lem instance! a set o* constraintsan$ anobjective function.
Fin$ a feasiblesolution *or the gien instance *or which theo(%ectie *unction has an optimal alue.
Either ma/imum or minimum $epen$ing on the pro(lem (eingsole$.A *easi(le solution that $oes this is calle$ optimalsolution.
8
7/26/2019 Greedy Method Report NHOEL RESOS
9/20
Continue$)
Feasible5A *easi(le solution satis*ies the pro(lem6s constraints
Constraints5The constraintsspeci*y the limitations on the re7uire$solutions.
9
7/26/2019 Greedy Method Report NHOEL RESOS
10/20
1ample 5sage of Greedy
6or better explanation we use oldsimple problem: Travelling 1alesman7roblem:
7/26/2019 Greedy Method Report NHOEL RESOS
11/20
T17
The 7roblem is how to travel from city -and visit all city on the map, then bac" tocity - again$
The rules: you only visit each city once andyou can4t pass through any traversed path$
7/26/2019 Greedy Method Report NHOEL RESOS
12/20
1olution:
6ind the shortest path from city -+start toany other city$
8ecause the nearest city is 8, so we go to 8
8-
7/26/2019 Greedy Method Report NHOEL RESOS
13/20
6rom 8, we nd any other city but
-+because - has been visited that hasnearest path$ 1o we choose 2:
9eep tuning on
8-
2
7/26/2019 Greedy Method Report NHOEL RESOS
14/20
6rom 2, we loo" to nearest city again,
but don4t loo" for - and 8, becauseboth has been visited$ 1o we choose ;$
1oon end
8-
2 ;
7/26/2019 Greedy Method Report NHOEL RESOS
15/20
-t this node+;, we can4t go to any city,because all neighbor of ; has beenvisited$ %e go bac" to rst city+-$
-nd that was how to solve T17 problem$
8-
2 ;
7/26/2019 Greedy Method Report NHOEL RESOS
16/20
1ample 5sage of Greedy
7/26/2019 Greedy Method Report NHOEL RESOS
17/20
The knapsack problemor rucksack problemis a problem in combinatorial optimiation: Given a set of items,each with a weight and a value, determine the number of each item to include in a collection so that the total
weight is less than or equal to a given limit and the total value is as large as possible$ !t derives its name from theproblem faced by someone who is constrained by a xed#sie "napsac"and must ll it with the most valuableitems$The problem often arises in resource allocationwhere there are nancial constraints and is studied in elds suchas combinatorics, computer science, complexity theory, cryptography, applied mathematics, anddaily fantasy sports$The "napsac" problem has been studied for more than a century, with early wor"s dating as far bac" as ?$@
7/26/2019 Greedy Method Report NHOEL RESOS
18/20
-dvantage of Greedy
Greedy is easy to be implemented$ust search the best choice from thecurrent state that 3reachable4 +has
any paths or any connections$
!n simple case, greedy often give youthe best solution$
7/26/2019 Greedy Method Report NHOEL RESOS
19/20
;rawbac" of Greedy
!n large and complex case, greedydoesn4t always give you the bestsolution, because it4s Hust search and
ta"e the best choice that you canreach from the current state$
!t ta"es longer time than any other
algorithms for big case of problem
7/26/2019 Greedy Method Report NHOEL RESOS
20/20
0R#S AND C#NS
0R#S5 They are easier to implement! they re7uire much less computing resources! they are much *aster to e/ecute.
&ree$y algorithms are use$ to sole optimi4ation pro(lems
C#NS5 Their only $isa$antage (eing that they not always reach the
glo(al optimum solution8 on the other han$! een when the glo(al optimum solution isnot reache$! most o* the times the reache$ su("optimalsolution is a ery goo$ solution.
2-