A description of knapsack algorithm. An explanation of the working of greedy algorithm

Attribution Non-Commercial (BY-NC)

18 views

A description of knapsack algorithm. An explanation of the working of greedy algorithm

Attribution Non-Commercial (BY-NC)

- Final Report
- daa 1mark questions and answers
- Optimization of Reservoir Operation Using Neuro-fuzzy Techniques
- ME_Electrical Power Systems
- hydro power efficiency enhancement
- smu mca -MC0079
- Unit Commitment
- Algorithms Design and Analysis Syllabus (1)
- Optimum Design Principles
- Effective Railway Planning Through Operations Research
- LP Two Variables More
- Operation Research Notes
- Readme
- Energy Optimization using Cloud Offloading Algorithm
- 16.+Dynamic+Programming-2.pdf
- (RKR_4)SimulatedAnnealing
- proj2
- FonteneauBelmudes Thesis
- Math
- Ms 41 Unit 7 Suplementary

You are on page 1of 11

Both types of algorithms are generally applied to optimization problems. Greedy algorithms tend to be faster. A greedy algorithm requires two preconditions:

Greedy choice property - making a greedy choice never precludes an optimal solution. Optimal substructure property an optimal solution to the problem contains optimal solutions to the subproblems.

If we have the second property then we can develop a DP algorithm. If we have neither property then we are in tough shape.

Knapsack Problem

We need to show that our first greedy choice g1 is included in some optimal solution O.

We need to show that O-{g1} is a solution to the problem left over after we make our first greedy choice.

Proof adapted from Vicki Choy's lecture notes at Viginia Tech: http://people.cs.vt.edu/~vchoi/4104/

Let O ={o , o , ... , o } I be the optimal solution of problem 1 2 j P. Let G ={g1 , g 2 , ... , g k } I be the greedy solution, where the items are ordered according to the greedy choices. We need to show that there exists some optimal solution O' that includes the choice g1. CASE 1: g1 is non-fractional.

if g1 is included in O, then we are done. if g1 is not included in O then we arbitrarily remove wg1 worth of stuff from O and replace it with g1 to produce O'. O' is a solution, and it is at least as good as O.

Proof Continued...

CASE 2: g1 is fractional. (this means K = f * wg1 where f is the fraction of g1 chosen. K is the weight limit.)

if O includes f * wg1 units of g1, then we are done. if O includes less than f of g1, then we remove f * wg1weight from O arbitrarily and replace it with f * wg1 units of g1 to construct O'.

We have shown that there is an optimal solution O' that selects g1. After g1 is chosen the weight limit becomes K'' = K wg1, the item set becomes I'' = I {g1}. Let P'' be the knapsack problem such that the weight limit is K'' and the item set is I''. We need to show that O'' = O' {g1} is an optimal solution to P''. Proof is by contradiction. Assume that O'' is not a solution to P''. Let Q be an optimal solution that is more valuable than O''. Let R =Q {g 1 } . The value of O' is equal to the value of O'' + g1. The value of R is greater than the value of O' = O'' + g1. Since O' was an optimal solution, this is a contradiction.

Let O be an optimal subset of all n items with weight limit K. We want to show that O contains a solution to all subinstances (by induction).

CASE 1: If O does not contain item n, then it is clearly an optimal subset of the first n-1 items. CASE 2: If O does contain item n, then O-{n} is a solution to the problem instance that includes the first n-1 items, and a weight limit K-wn.

Proof by contradiction, if O {n} is not a solution, then there must be some other subset Q with higher profit. By adding the nth item to Q, we have a subset of the first n items with higher profit than O, a contradiction.

First, why can't we have a greedy algorithm for this problem? Let's look back at the fractional proof. The reasoning on the previous slide leads us to the following recurrence for maximum profit P on the first i items with a weight limit of w:

CASE 1 CASE 2

P [ i ][ w ]=

max P [ i 1 ][ w ] , pi P [ i 1 ][ w wi ] if wi w P [ i 1 ][ w ] if wi w

Analysis

A Better Algorithm

The nth row requires at most one entry: P[n][W]. the n-1st row requires at most two entries P[n-1][W] and P[n-1][W-wn]. the n-2nd row requires at most four entries, two for each in the n-1st row. 1 + 2 + 22 + ... + 2n-1 = 2n -1

So regardless of weight limit, this algorithm gives a bound of 2 n . Incorporating the weight limit, we have O(min(nW, 2n)).

- Final ReportUploaded byShubham Sinha
- daa 1mark questions and answersUploaded bykoteswararaopittala
- Optimization of Reservoir Operation Using Neuro-fuzzy TechniquesUploaded byIAEME Publication
- ME_Electrical Power SystemsUploaded bykotkar1986
- hydro power efficiency enhancementUploaded bySuraj Dahal
- smu mca -MC0079Uploaded byShrikant Bhardwaj
- Unit CommitmentUploaded bysusmita000
- Algorithms Design and Analysis Syllabus (1)Uploaded bySapna Vats
- Optimum Design PrinciplesUploaded byJen Chavez
- Effective Railway Planning Through Operations ResearchUploaded byInternational Journal of Innovative Science and Research Technology
- LP Two Variables MoreUploaded byMohammad Nazmul Islam
- Operation Research NotesUploaded bysagar kadam
- ReadmeUploaded bysroy0567
- Energy Optimization using Cloud Offloading AlgorithmUploaded byATS
- 16.+Dynamic+Programming-2.pdfUploaded byIbrahim Hawari
- (RKR_4)SimulatedAnnealingUploaded byAmrYassin
- proj2Uploaded byapi-314080932
- FonteneauBelmudes ThesisUploaded byijkmvv
- MathUploaded byJuan Palacios
- Ms 41 Unit 7 SuplementaryUploaded bysudhir.kochhar3530
- DSA Assignment I006Uploaded bySanket Chavan
- TRANSPORT JOURNALUploaded byGoutham Ram
- Operation Research and StatisticsUploaded bytrample2
- Article2-From Circuit Theory to System TheoryUploaded byMiguel Andres Garcia Llanos
- OS-06 Introduction of Optimization Tools MarutiUploaded byankur
- Introduction of Analysis Design & AlgorithmUploaded bysb_sriit
- systems eng. & analysisUploaded byKhairunnisaSalsabila
- course.docxUploaded byBasavasai Sunkara
- CS332-15Uploaded byThanoj Kumar
- main projectUploaded byIndra Neel

- Self Study 1Uploaded byShivam Shukla
- Handling TCM on ARMUploaded byShivam Shukla
- Homeopathy Beyond Flat Earth Medicine by Timothy RUploaded byari_matrix
- Vodafone Payment Receipt o809591667Uploaded bytitusbs
- 2010_OBUploaded byShivam Shukla
- Embedded SystemUploaded byShivam Shukla
- Goodreads _ Books by B.v... of Notable Horoscopes)Uploaded byShivam Shukla
- Windows Update TroubleshootingUploaded byShivam Shukla
- ReadMeUploaded byShivam Shukla
- Assign II SolnUploaded byShivam Shukla
- Akshay Net Fi April 2014Uploaded byShivam Shukla
- Copy of Blaze 299Uploaded byShivam Shukla
- Introduction to Self StudyUploaded byShivam Shukla
- 2009_OB_OctUploaded byShivam Shukla
- Lab 3Uploaded byShivam Shukla
- The ID3 AlgorithmUploaded byShivam Shukla
- Case StudyUploaded byShivam Shukla
- Assign I SolnUploaded byShivam Shukla
- 6455_HIPUploaded byShivam Shukla
- SS2.1Uploaded byShivam Shukla
- Self Study 4Uploaded byShivam Shukla
- SolutionUploaded byShivam Shukla
- Self Study 3Uploaded byShivam Shukla
- An 461Uploaded byv1swaroop
- Optional AssignmentUploaded byShivam Shukla
- Eee Zg512 Ec-3r Second Sem 2013-2014Uploaded byShivam Shukla
- 8051 Learning boardUploaded byEmin Kültürel
- The 8051 Micro Controller and Embedded Systems CH4Uploaded byPriyanka Sadananda
- Assignment 1Uploaded byShivam Shukla

- Lecture1.pdfUploaded byNeil Carrasco
- Solving Optimization Problems Using the Matlab OptUploaded byFirman Pahrizal
- Pengiraan Masa Pnp Fb-081-4 (Update)Uploaded byGee Gbah Gurlz
- 15_is_0195_ps_petrel_2015_FINALUploaded byVi Dang
- Expo Control 2012Uploaded byCM35
- cUploaded byDhp Cia
- Servo MotorUploaded byLeo Lonardelli
- nonlinear system identification.pdfUploaded byMona Ali
- DSDMUploaded bytya_yark
- MCS-014 BLOCK 2Uploaded byAbhishek Veerkar
- 55 Warehouse Best PracticesUploaded byKimberly Antequera
- CMGT 555 ENTIRE COURSE.docxUploaded byJohn
- RupUploaded byRene Marcos Arroyo Mancilla
- UlabyTOCUploaded byDario Mancilla Vilches
- Facility Location in Supply Chain DesignUploaded byVictor Manuel Lambert Ochoa
- 1-s2.0-S2405896316309284-main(1).pdfUploaded byHuda Yudistira
- ISTQB-TMQUploaded byShitesh Sachan
- Signal and SystemsUploaded byjaspreet12321
- Guidelines for User Acceptance TestingUploaded bySunday Paul
- digital_129192-T 26785-Penerapan model-Lampiran.pdfUploaded byMuhaimin
- Role of a SAP Functional ConsultantUploaded byManikandarajaPathmaraj
- Small-Signal Stability, Control and Dynamic Performance of Power SystemsUploaded byfyahyaie
- Harri Haapasalo Lean ProductionUploaded byDaisy
- lec0_4pUploaded byAlex Kang
- ISO 9000 2000 Mapping With CMMi 1.2Uploaded byDavid Carter
- PHP And MySQL Project On Clinic Appointment SystemUploaded byFreeProjectz.com
- Non-Humanoid Creature Performance From Human ActingUploaded bygustavoboehs
- Abstract Mega PackUploaded bydaygo21
- Solve Optimal DispatchUploaded byMoris Enrique Molina Mesa
- MIS Question BankUploaded bySaurabh Pandey