Greedy Programming

© All Rights Reserved

5 views

Greedy Programming

© All Rights Reserved

- Mechanism Design for Global Isotropy With Applications To
- sap2000-matlab oapi
- 21 Differential Cost Analysis
- Qcar-2003
- Optimization Methods
- Paper_1
- 6 Vol 17 No 1
- A Realtime Adaptive Trading System
- Khalek Ieee Tvt
- Set Up Objective Function for Optimization
- Aggregate Planning
- OR assignment
- SPE 84191 MS (Well Placement)
- Steel Weight Optimisation Midship Stiffner Plate Thickness
- 00671565(12)
- affisco2002
- Access Optimisation Tools in Underground Mine Design
- A C 9
- voe_main2.getVollText.pdf
- 12355 45 25 Optimal Tunning

You are on page 1of 35

Deliverables

Greedy Paradigm

Interval Scheduling

Huffman compression

Minimizing Lateness

Greedy paradigm

Primarily used in Optimization problems to find

the maximum or minimum value satisfying

given constraints.

a sequence of steps (piecewise) where each step

is considered a partial solution, which is

extended progressively to get complete solution.

Choice of steps

Choice of each step in greedy is based on following

It must be feasible

It must be irrevocable

5 Pillars of Greedy Technique

Proof of correctness is necessary and important.

1. A candidate set, from which a solution is created

2. A selection function, which chooses the best candidate to be

added to the solution

3. A feasibility function that is used to determine if a candidate

can be used to contribute to a solution

4. An objective function, which assigns a value to a solution, or

a partial solution, and

5. A solution function, which will indicate when we have

discovered a complete solution

General Greedy Algorithm

a[1:n]; sol ;

for i 1 to n do

x SELECT(a); //as per some optimization criteria

if FEASIBLE(sol, x) then solution UNION(sol, x);

return sol

feasibility criteria and Union integrates the element x in the

solution

Coin Change Problem

An amount and collection of coins to reach to that amount Objective is to

minimize the number of coins

Greedy theory says always return the largest coin

if coins are of denomination 32, 8, 1 it has the greedy choice property because

no amount over 32 can be made without omitting 32.

property because 40 can be made with two 20 coins but it returns 30,5,5 coins

Similarly if denominations are 1, 10, 21, 34, 70, 100, 350 140 Greedy: 100, 34,

1, 1, 1, 1, 1, 1 Optimal: 70, 70

Interval Scheduling Problem

Given set S = {a1, , an} of activities and activity start and

finish times, e.g.

i 1 2 3 4 5 6 7 8 9 10 11

si 1 3 0 5 3 5 6 8 8 2 12

fi 4 5 6 7 8 9 10 11 12 13 14

Activities are compatible if their time intervals do not

overlap, i.e., ai is compatible with aj is si fj or sj fi.

To find Subset of non overlapping intervals so that number

of intervals are maximum.

6/7/2012 8:57 PM Copyright @ gdeepak.Com 8

Earliest Start Time

Shortest interval First

Fewest Conflicts First

Interval Scheduling Algorithm

Interval that ends first and remove the intervals that

overlap with these and recurse.

Sort jobs by finish times so that f1 f2 ... fn.

A

for j = 1 to n

{

if (job j compatible with A)

A A {j}

}

return A

Efficient greedy algorithm

Once youve identified a reasonable greedy heuristic:

Prove that it always gives the correct answer

Develop an efficient solution

Is our greedy approach correct?

Stays ahead argument: show that no matter what other

solution someone provides you, the solution provided by

your algorithm always stays ahead, in that no other

choice could do better

Is our greedy approach correct?

Stays ahead argument

Let r1, r2, r3, , rk be the solution found by our approach

r1 r2 r3

rk

Let o1, o2, o3, , ok of another optimal solution

o1 o2 o3

ok

Show our approach stays ahead of any other solution

Stays ahead

r1 r2 r3

rk

o1 o2 o3

ok

Stays ahead

r1 r2 r3

rk

o1 o2 o3

ok

finish(r1) finish(o1)

Stays ahead

r2 r3

rk

o2 o3

ok

remaining 2k tasks

Optimal Merge Sort

Suppose there are 3 sorted lists L1, L2, and L3, of sizes 30, 20, and 10,

respectively, which need to be merged into a combined sorted list but

we can merge only two at a time.

We intend to find an optimal merge pattern which minimizes the total

number of comparisons.

Merge L1 & L2,: 30 + 20 = 50 comparisons , then merge the list & L3:

50 + 10 = 60 comparisons total number of comparisons: 50 + 60 = 110.

list (size 30) then merge the list with L1: 30 + 30 = 60 total number of

comparisons: 30 + 60 = 90.

Merge sort example

Huffman Compression

File f has one million characters. If only a, b, c, d, e, f chars come in the file then the

total size of the file is 8 million bits

If we represent these with 000 001 010 011 101 111 then only 3 million bits

0 1 00 11 10 11 will give us less then 2 million bits

leaves of the binary tree will represent the bit strings

It will give us the prefix free code. use greedy for making the binary tree and then

assign 0 to every left node and 1 to every right node. The nodes with larger frequency

will be nearer to the root and with lesser frequency will be towards the leaves.

Huffman Example

Knapsack

Given n objects and a knapsack. Object i has weight wi and the

knapsack has a capacity M.

then a profit of pixi is earned. The objective is to obtain a filling of

the knapsack that maximizes the total profit earned.

should be M. The profits and weights are positive

Partial Knapsack-Greedy

0/1 knapsack

1st is optimal but greedy will give 2nd solution

Algorithm for partial knapsack

Input Set S of items with weight wi , benefit bi and total weight W

Output amount xi of each item i to maximize benefit with weight

W for each item i in S

xi=0

vi=bi/wi

w=0

while w<W

remove item i with highest vi

xi=min(wi, W-w)

w=w+min(wi, W-w)

Job deadlines

Single resource processes one job at a time.

Job j requires tj units of processing time and is due at time dj.

If j starts at time sj, it finishes at time fj = sj + tj.

Lateness: lj = max { 0, fj - dj }.

Goal: Schedule all jobs to minimize maximum lateness

L=max lj.

1 2 3 4 5 6

tj 3 2 1 4 3 2

dj 6 8 9 9 14 15

6/7/2012 8:57 PM Copyright @ gdeepak.Com 27

Minimizing lateness

Consider jobs in ascending order of processing time tj

1 2

tj 1 10

dj 100 10

Consider jobs in ascending order of slack dj - tj

1 2

tj 1 10

dj 2 10

Minimizing Lateness

T 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14

J 1 1 1 2 2 3 4 4 4 4 5 5 5 6 6

D 6 6 6 8 8 9 9 9 9 9L 14 14 14 15 15

Single Job-Single resource

There is no preemption and these have to be allocated

processor. Only one processor is available. Objective is to

minimize the sum of the finishing times

f1=t1

f2=t1+t2

fi=t1+t2++ti

:

fn=nt1+(n-1)t2++tn

So t1 should be smallest and so on

Questions, Suggestions and Comments

Question 1

Greedy Approach the shortest path is

A) 9

B) 23

C) 5

D) 17

Question 2

Greedy Technique is related to the theory of

A) Calculus

B) Probability

C) Matroid

D) Algebra

Question 3

For those problems where Greedy gives the optimal

solution, the complexity is better as compared to the

implementation of the same problem with Dynamic

Programming.

A) True

B) False

??

Given a question, Can you find whether greedy strategy

work in general is NP-Complete.

- Mechanism Design for Global Isotropy With Applications ToUploaded byHareesha N G
- sap2000-matlab oapiUploaded byyoki_triwahyudi
- 21 Differential Cost AnalysisUploaded byjoha
- Qcar-2003Uploaded byzefiris
- Optimization MethodsUploaded bycerebral28
- Paper_1Uploaded bySrilekhya Reddy
- 6 Vol 17 No 1Uploaded byJeya Ram
- A Realtime Adaptive Trading SystemUploaded byStéphane Bouclier
- Khalek Ieee TvtUploaded byRicky Suradiradja
- Set Up Objective Function for OptimizationUploaded bySapari Vel
- Aggregate PlanningUploaded byvinayakvishwakarma3429
- OR assignmentUploaded byJaspreetBajaj
- SPE 84191 MS (Well Placement)Uploaded byMuhammad Anis Alkaff
- Steel Weight Optimisation Midship Stiffner Plate ThicknessUploaded bymarco
- 00671565(12)Uploaded bybluemoon1172
- affisco2002Uploaded byBunty Evol
- Access Optimisation Tools in Underground Mine DesignUploaded byJhan Huayra Gabriel
- A C 9Uploaded byAnonymous N3LpAX
- voe_main2.getVollText.pdfUploaded byIngeniero Estructural
- 12355 45 25 Optimal TunningUploaded byapidkhh
- 529505Uploaded byGovindarajan Ramachandran
- 01 IntroductionUploaded byJaspreet
- UCUploaded bySambit Dash
- L8 Unit Commitment Lagrange RelaxationUploaded byMalik Shahzeb Ali
- Synthesis of Optimal Chemical Reactor NetworksUploaded bycassindrome
- Engleski-seminarski Iz SaobracajaUploaded byMarko
- DownloadUploaded byAndrei Barbu
- TTP30026W_-_LTE_RF_Optimization_Methods___Pr.pdfUploaded byRitesh Ranjan
- MINLPSolver TutorialUploaded byscribd-ml
- ABC_ANAL__Z___Y__NTEM_____LE_ENVANTER_SINIFLANDIRMASI_123539_-105376.pdfUploaded bySarello Assenav

- Image Captioning TRUploaded byakg299
- Bench Match FrameUploaded byakg299
- 17-Article Text-50-1-10-20180621Uploaded byakg299
- Age Declaration FormUploaded bysushil.singh.c
- g Cp CommandsUploaded byakg299
- Bossy PantsUploaded byakg299
- Ucs742 AssignmentUploaded byakg299
- Logistics E CommerceUploaded byPrateek Vyas
- PosterUploaded byakg299
- SlidesUploaded byakg299
- Report 2Uploaded byakg299
- Report 4Uploaded byakg299
- Report 3Uploaded byakg299
- Image Captioning TRUploaded byakg299
- Image CaptionTemplate ReportUploaded byakg299
- Image Caption Technical ReportUploaded byakg299
- Srs TemplateUploaded byakg299
- AMCAT Test SyllabusUploaded byHarsha Nihanth
- Linked List GfgUploaded byakg299
- Gfg Array Questions ImportantUploaded byakg299
- Array ClassificationUploaded byakg299
- Array Classification (Autosaved)Uploaded byakg299
- top interview questions.txtUploaded byakg299
- readme.txtUploaded byAyrton Wagner
- Business Operations Associate.pdfUploaded byakg299
- Technology Analyst.pdfUploaded byakg299
- ZS Campus Name 2018 Student DataUploaded byakg299
- Readme.docxUploaded byakg299
- Capstone GanttUploaded byakg299
- Class DiagramUploaded byakg299

- Temenos ConnectorUploaded byahmedm
- Adventist Hymns_ Index of Spanish SDA Hymns in EnglishUploaded bydluiscruz
- Nyaya [Internet Encyclopedia of Philosophy].pdfUploaded byshlke
- IBPS Mock 8Uploaded byakshay
- Comp ProjUploaded bySaksham Attri
- SIM900_ATC_V1.01.pdfUploaded bysuaradjus
- ch17-SLIDE-[2]Data Communications and Networking By Behrouz A.ForouzanUploaded byXP2009
- PuaUploaded byAlonso Cornejo
- Gen6-11Uploaded bymichele.siciliano4467
- 9- ELT-Vocabulary.pdfUploaded byIvan Giovanni Miter
- Storage Sync for VMware Product Guidev11Uploaded byMatoGruda
- 329298-002Uploaded bymlazar20009720
- Rosicrucian Digest, October 1955Uploaded bysauron385
- Balotario Suficiencia InglesUploaded byalfredo vilca segovia
- Chapter 7. Storage Components.pdfUploaded byĀħmēđ Zahdeh
- IJACSA_Volume3No12Uploaded byEditor IJACSA
- REAL_TO_INT.pdfUploaded byHans Navota
- simulinkUploaded bySumit Chakravarty
- classroom debate rubricUploaded byapi-263356428
- 07.BootstrappingUploaded byDonie Mahaputra
- 8 Computer ScienceUploaded byVeerendra Nath
- Final ReportUploaded byTuhin Garg
- MELJUN CORTES Rotate InstructionsUploaded byMELJUN CORTES, MBA,MPA
- langearly14 language stimulation techniquesUploaded byapi-337162869
- 8085 SlidesUploaded byRinky Sachdeva
- Javahelp 2 0 GuideUploaded byapi-3697260
- Zuma's Revenge! Setup LogUploaded byДрАгАн ПеЈчИћ
- clasa a5a to be.docxUploaded bycerasella
- Crusoe PDFUploaded byJogil Jose
- m Shell CommandsUploaded byBasant Paliwal

## Much more than documents.

Discover everything Scribd has to offer, including books and audiobooks from major publishers.

Cancel anytime.