MCS 312: NP Completeness and Approximation algorithms Instructor Neelima Gupta

Slides:



Advertisements
Similar presentations
Lecture 7 Paradigm #5 Greedy Algorithms
Advertisements

Algorithm Design Methods Spring 2007 CSE, POSTECH.
MCA 301: Design and Analysis of Algorithms
 Review: The Greedy Method
Knapsack Problem Section 7.6. Problem Suppose we have n items U={u 1,..u n }, that we would like to insert into a knapsack of size C. Each item u i has.
Algorithm Design Techniques: Greedy Algorithms. Introduction Algorithm Design Techniques –Design of algorithms –Algorithms commonly used to solve problems.
The Greedy Method1. 2 Outline and Reading The Greedy Method Technique (§5.1) Fractional Knapsack Problem (§5.1.1) Task Scheduling (§5.1.2) Minimum Spanning.
Chapter 5 Fundamental Algorithm Design Techniques.
Analysis of Algorithms
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 7: Greedy Algorithms
Merge Sort 4/15/2017 6:09 PM The Greedy Method The Greedy Method.
Greedy vs Dynamic Programming Approach
18 = = = = = = = =
0-1 Knapsack Problem A burglar breaks into a museum and finds “n” items Let v_i denote the value of ith item, and let w_i denote the weight of the ith.
CPSC 411, Fall 2008: Set 4 1 CPSC 411 Design and Analysis of Algorithms Set 4: Greedy Algorithms Prof. Jennifer Welch Fall 2008.
© 5/7/2002 V.S. Subrahmanian1 Knapsack Problem Notes V.S. Subrahmanian University of Maryland.
The Knapsack Problem The classic Knapsack problem is typically put forth as: A thief breaks into a store and wants to fill his knapsack with as much value.
KNAPSACK PROBLEM A dynamic approach. Knapsack Problem  Given a sack, able to hold K kg  Given a list of objects  Each has a weight and a value  Try.
Week 2: Greedy Algorithms
Lecture 7: Greedy Algorithms II
1 The Greedy Method CSC401 – Analysis of Algorithms Lecture Notes 10 The Greedy Method Objectives Introduce the Greedy Method Use the greedy method to.
The Knapsack Problem Input –Capacity K –n items with weights w i and values v i Goal –Output a set of items S such that the sum of weights of items in.
CPSC 411, Fall 2008: Set 4 1 CPSC 411 Design and Analysis of Algorithms Set 4: Greedy Algorithms Prof. Jennifer Welch Fall 2008.
David Luebke 1 8/23/2015 CS 332: Algorithms Greedy Algorithms.
IT 60101: Lecture #201 Foundation of Computing Systems Lecture 20 Classic Optimization Problems.
Approximation Algorithms for Knapsack Problems 1 Tsvi Kopelowitz Modified by Ariel Rosenfeld.
CSC 413/513: Intro to Algorithms Greedy Algorithms.
Algorithmics - Lecture 101 LECTURE 10: Greedy technique.
Introduction to Algorithms Chapter 16: Greedy Algorithms.
Honors Track: Competitive Programming & Problem Solving Optimization Problems Kevin Verbeek.
Topic 25 Dynamic Programming "Thus, I thought dynamic programming was a good name. It was something not even a Congressman could object to. So I used it.
The Greedy Method. The Greedy Method Technique The greedy method is a general algorithm design paradigm, built on the following elements: configurations:
CSC 201: Design and Analysis of Algorithms Greedy Algorithms.
Instructor Neelima Gupta Table of Contents Factor 2 algorithm for Bin Packing Factor 2 algorithm for Minimum Makespan Scheduling Reference:
Dynamic Programming.  Decomposes a problem into a series of sub- problems  Builds up correct solutions to larger and larger sub- problems  Examples.
Algorithm Design Methods 황승원 Fall 2011 CSE, POSTECH.
1 Algorithms CSCI 235, Fall 2015 Lecture 30 More Greedy Algorithms.
CS 3343: Analysis of Algorithms Lecture 19: Introduction to Greedy Algorithms.
Dynamic Programming … Continued 0-1 Knapsack Problem.
Spring 2008The Greedy Method1. Spring 2008The Greedy Method2 Outline and Reading The Greedy Method Technique (§5.1) Fractional Knapsack Problem (§5.1.1)
CS 361 – Chapter 10 “Greedy algorithms” It’s a strategy of solving some problems –Need to make a series of choices –Each choice is made to maximize current.
Dynamic Programming (optimization problem) CS3024 Lecture 10.
Divide and Conquer. Problem Solution 4 Example.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 18.
Greedy Algorithms Prof. Kharat P. V. Department of Information Technology.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 17.
Greedy Method 6/22/2018 6:57 PM Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015.
Algorithm Design Methods
Merge Sort 7/29/ :21 PM The Greedy Method The Greedy Method.
The Greedy Method and Text Compression
Topic 25 Dynamic Programming
Algorithm Design Methods
The Subset Sum Game Revisited
CS 3343: Analysis of Algorithms
Merge Sort 11/28/2018 2:18 AM The Greedy Method The Greedy Method.
The Greedy Method Spring 2007 The Greedy Method Merge Sort
Merge Sort 11/28/2018 2:21 AM The Greedy Method The Greedy Method.
Merge Sort 11/28/2018 8:16 AM The Greedy Method The Greedy Method.
Greedy Algorithm Enyue (Annie) Lu.
Exam 2 LZW not on syllabus. 73% / 75%.
Advanced Algorithms Analysis and Design
Merge Sort 1/17/2019 3:11 AM The Greedy Method The Greedy Method.
Greedy Algorithms: Maximizing Loot
Algorithm Design Methods
Lecture 6 Greedy Algorithms
Algorithm Design Methods
Merge Sort 5/2/2019 7:53 PM The Greedy Method The Greedy Method.
Algorithms CSCI 235, Spring 2019 Lecture 30 More Greedy Algorithms
Knapsack Problem A dynamic approach.
Algorithm Design Methods
Presentation transcript:

MCS 312: NP Completeness and Approximation algorithms Instructor Neelima Gupta

Table of Contents Generalizations of Subset Sum 0-1 Knapsack Bin Packing

The Knapsack Problem The classic Knapsack problem is: A thief breaks into a store and wants to fill his knapsack of capacity K with goods of as much value as possible. Decision version: Does there exist a collection of items that fits into his knapsack and whose total value is >= W?

The Knapsack Problem Input –Capacity K –n items with weights w i and values v i Output: a set of items S such that the sum of weights of items in S is at most K and the sum of values of items in S is maximized

Some Simplest Versions… Fractional Knapsack Problem: Can items be picked up partially? The thief’s knapsack can hold 100 gms and has to choose from: 30 gms of gold dust at Rs 1000 /gm 60 gms of silver dust at Rs 500/gm 30 gms of platinum dust at Rs 1500/gm Note: Optimal fills the Knapsack upto full capacity. Proof: Else the remaining capacity can be filled with some item, picking it partially if the need be.

Greedy Algorithm for fractional Knapsack 1.Sort the items in the increasing order of value/weight ratio (cost effectiveness). 2.If the next item cannot fit into the knapsack, break it and pick it partially just to fill the knapsack.

Fractional Knapsack has greedy choice property That is, if v1/w1 is maximum, then there exists an optimal solution that contains item x1 upto the extent of min{w1, W}. Proof: Suppose not. Let O be an optimal solution that does not contain x1. Let xt be the item with maximum weight wt in O. If wt > w1, replacing w1 amount of xt by w1 amount of x1, value of the solution will improve (since v1/w1 > vt/wt). Let S’ be a subset of items in O whose is > w1. Replacing w1 of this total weight by w1 of x1 will improve the value of the solution. If no such set S’ exists then (sum of all the sets in O =) W < = w1. Replace all the sets in O by W amount of x1 and the value of the solution will improve.

Other Simple versions Are all of the weights or total values identical? The thief breaks into a ring shop where all of the rings weight 10 gms. He can hold 25 gms; which should he take?

0-1 Knapsack An item can either be picked or left. It cannot be picked partially. For example gold coins, diamond rings, TV etc.

Greedy doesn’t work for 0-1 Knapsack Capacity 200 Items : X1 : v1/w1 = 12, weight : 50 X2 : v2/w2 = 10, weight : 55 X3 : v3/w3 = 8, weight : 10 X4 : v4/w4 = 6, weight : 100 Value of Greedy : 50 * *10 + 8* 10= 1230 Optimal : 8 * *10 + 8*10= 1430

Dynamic Programming Solution Let V(i,w) is the value of the set of items from the first i items that maximizes the value subject to the constraint that the sum of the values of the items in the set is <= w Value of the original problem corresponds to V(n, K)

Recurrence Relation V(i,w) = max (V(i-1,w-w i ) + v i, V(i-1, w)) –Fisrt term corresponds to the case when xi is included in the solution and –The second term corresponds to the case when xi is not included V(0,w) = 0 (no items to choose from) V(i,0) = 0 (no weight allowed)

Time Analysis O(nK) It is exponential in the input size.

Generalizations of Subset Sum The Subset Sum problem we have studied and shown that it is NPC is the following: Given a finite set S of natural numbers and a target t є N, does there exist a subset S’ of S whose elements sum up to t. Its generalization is: Gen1_SS: Given a finite set S ={x1 … xn} of n numbers, does there exist a subset S’ of S that whose sum is = K By Generalization it is NPC

Further generalization of Subset Sum Gen1_SS: Given a finite set S ={x1 … xn} of n numbers, does there exist a subset S’ of S that whose sum is = K. Gen2_SS: Given a finite set S ={x1 … xn} of n numbers, find a subset S’ of S that maximizes the sum with the constraint that the sum is <= K. Its decision version is: Given a finite set S ={x1 … xn} of n numbers, does there exist a subset S’ of S whose sum >= W with the constraint that the sum is <= K.

0-1 Knapsack is NP-Complete Gen2_SS: Given a finite set S ={x1 … xn} of n numbers, find a subset S’ of S that maximizes the sum with the constraint that the sum is <= K. The above subset sum problem is a particular case of 0-1 Knapsack by putting wi = vi = xi. i.e. 0-1 Knapsack is a generalization of the above subset sum problem. Hence, by generalization 0-1 Knapsack is NPC

Bin Packing Problem Given a set of items S = {x1…xn} each with some weight wi, pack maximum number of items into a collection of finite number of bins each with some capacity Bi using minimum number of bins. Knapsack problem is a particular case of Bin-packing when the number of bins is 1 and its capacity is K

Bin Packing is NPC By Generalization of Knapsack.