Presentation is loading. Please wait.

Presentation is loading. Please wait.

MCS 312: NP Completeness and Approximation algorthms

Similar presentations


Presentation on theme: "MCS 312: NP Completeness and Approximation algorthms"— Presentation transcript:

1 MCS 312: NP Completeness and Approximation algorthms
Instructor Neelima Gupta

2 Table of Contents FPTAS for the Knapsack Problem Reference: Vazirani.

3 Definition Given a set {a1, a an} of n objects with profit p(ai) and size s(ai). And, a knapsack with capacity B. Find a collection of objects fitting into the knapsack that maximizes the profit.

4 Pseudo Polynomial Algorithms

5 Pseudo Polynomial for KS
Let P = max { p(ai) } Let S(i, p) denotes a subset of {a1, a ai} with profit exactly equal to p that minimizes the size. Let A(i,p) denotes the size of S(i, p). A(i,p) = infinity if no such set exists. A(1,p) is easy to compute (in fact known directly) for every p in {1 … nP} A(i+1,p) = min{ A(i, p), size (ai+1, p – p(ai+1) } if p(ai) < p = A(i, p) otherwise

6 Example n = 4 B = 5 Elements (size, profit):
(2,3), (3,4), (4,5), (5,6) Thanks to : Neha Katyal (17, MCS '11), Shikha Walia (27, MCS'11)

7 (2,3), (3,4), (4,5), (5,6) W i 1 2 3 4 Thanks to : Neha Katyal (17, MCS '11), Shikha Walia (27, MCS'11)

8 As w<w1 ; m[1,1] = m[1-1,1] = m[0,1]
(2,3), (3,4), (4,5), (5,6) As w<w1 ; m[1,1] = m[1-1,1] = m[0,1] W i 1 2 3 4 inf 2 Thanks to : Neha Katyal (17, MCS '11), Shikha Walia (27, MCS'11)

9 As w<w2 ; m[2,1] = m[2-1,1] = m[1,1]
(2,3), (3,4), (4,5), (5,6) As w<w2 ; m[2,1] = m[2-1,1] = m[1,1] W i 1 2 3 4 Thanks to : Neha Katyal (17, MCS '11), Shikha Walia (27, MCS'11)

10 As w<w3 ; m[3,1] = m[3-1,1] = m[2,1]
(2,3), (3,4), (4,5), (5,6) As w<w3 ; m[3,1] = m[3-1,1] = m[2,1] W i 1 2 3 4 Thanks to : Neha Katyal (17, MCS '11), Shikha Walia (27, MCS'11)

11 As w<w4 ; m[4,1] = m[4-1,1] = m[3,1]
(2,3), (3,4), (4,5), (5,6) As w<w4 ; m[4,1] = m[4-1,1] = m[3,1] W i 1 2 3 4 Thanks to : Neha Katyal (17, MCS '11), Shikha Walia (27, MCS'11)

12 As w>=w1 ; m[1,2] = max{m[1-1,2] , m[1-1,2-2]+3} =max{ 0,0+3}
(2,3), (3,4), (4,5), (5,6) As w>=w1 ; m[1,2] = max{m[1-1,2] , m[1-1,2-2]+3} =max{ 0,0+3} W i 1 2 3 4 3 Thanks to : Neha Katyal (17, MCS '11), Shikha Walia (27, MCS'11)

13 As w<w2 ; m[2,2] = m[2-1,2] = m[1,2]
(2,3), (3,4), (4,5), (5,6) As w<w2 ; m[2,2] = m[2-1,2] = m[1,2] W i 1 2 3 4 3 Thanks to : Neha Katyal (17, MCS '11), Shikha Walia (27, MCS'11)

14 As w<w3 ; m[3,2] = m[3-1,2] = m[2,2]
(2,3), (3,4), (4,5), (5,6) As w<w3 ; m[3,2] = m[3-1,2] = m[2,2] W i 1 2 3 4 3 Thanks to : Neha Katyal (17, MCS '11), Shikha Walia (27, MCS'11)

15 As w<w4 ; m[4,2] = m[4-1,2] = m[3,2]
(2,3), (3,4), (4,5), (5,6) As w<w4 ; m[4,2] = m[4-1,2] = m[3,2] W i 1 2 3 4 3 Thanks to : Neha Katyal (17, MCS '11), Shikha Walia (27, MCS'11)

16 As w>=w1 ; m[1,3] = max{m[1-1,3] , m[1-1,3-2]+3} =max{ 0,0+3}
(2,3), (3,4), (4,5), (5,6) As w>=w1 ; m[1,3] = max{m[1-1,3] , m[1-1,3-2]+3} =max{ 0,0+3} W i 1 2 3 4 3 Thanks to : Neha Katyal (17, MCS '11), Shikha Walia (27, MCS'11)

17 As w>=w2 ; m[2,3] = max{m[2-1,3] , m[2-1,3-3]+4} =max{ 3,0+4}
(2,3), (3,4), (4,5), (5,6) As w>=w2 ; m[2,3] = max{m[2-1,3] , m[2-1,3-3]+4} =max{ 3,0+4} W i 1 2 3 4 3 4 Thanks to : Neha Katyal (17, MCS '11), Shikha Walia (27, MCS'11)

18 As w<w3 ; m[3,3] = m[3-1,3] = m[2,3]
(2,3), (3,4), (4,5), (5,6) As w<w3 ; m[3,3] = m[3-1,3] = m[2,3] W i 1 2 3 4 3 4 Thanks to : Neha Katyal (17, MCS '11), Shikha Walia (27, MCS'11)

19 As w<w4 ; m[4,3] = m[4-1,3] = m[3,3]
(2,3), (3,4), (4,5), (5,6) As w<w4 ; m[4,3] = m[4-1,3] = m[3,3] W i 1 2 3 4 3 4 Thanks to : Neha Katyal (17, MCS '11), Shikha Walia (27, MCS'11)

20 As w>=w1 ; m[1,4] = max{m[1-1,4] , m[1-1,4-2]+3} =max{ 0,0+3}
(2,3), (3,4), (4,5), (5,6) As w>=w1 ; m[1,4] = max{m[1-1,4] , m[1-1,4-2]+3} =max{ 0,0+3} W i 1 2 3 4 3 4 Thanks to : Neha Katyal (17, MCS '11), Shikha Walia (27, MCS'11)

21 As w>=w2 ; m[2,4] = max{m[2-1,4] , m[2-1,4-3]+4} =max{ 3,0+4}
(2,3), (3,4), (4,5), (5,6) As w>=w2 ; m[2,4] = max{m[2-1,4] , m[2-1,4-3]+4} =max{ 3,0+4} W i 1 2 3 4 3 4 Thanks to : Neha Katyal (17, MCS '11), Shikha Walia (27, MCS'11)

22 As w>=w3 ; m[3,4] = max{m[3-1,4] , m[3-1,4-4]+5} =max{ 4,0+5}
(2,3), (3,4), (4,5), (5,6) As w>=w3 ; m[3,4] = max{m[3-1,4] , m[3-1,4-4]+5} =max{ 4,0+5} W i 1 2 3 4 3 4 5 Thanks to : Neha Katyal (17, MCS '11), Shikha Walia (27, MCS'11)

23 As w<w4 ; m[4,4] = m[4-1,4] = m[3,4]
(2,3), (3,4), (4,5), (5,6) As w<w4 ; m[4,4] = m[4-1,4] = m[3,4] W i 1 2 3 4 3 4 5 Thanks to : Neha Katyal (17, MCS '11), Shikha Walia (27, MCS'11)

24 As w>=w1 ; m[1,5] = max{m[1-1,5] , m[1-1,5-2]+3} =max{ 0,0+3}
(2,3), (3,4), (4,5), (5,6) As w>=w1 ; m[1,5] = max{m[1-1,5] , m[1-1,5-2]+3} =max{ 0,0+3} W i 1 2 3 4 3 4 5 Thanks to : Neha Katyal (17, MCS '11), Shikha Walia (27, MCS'11)

25 As w>=w2 ; m[2,5] = max{m[2-1,5] , m[2-1,5-3]+4} =max{ 3,3+4}
(2,3), (3,4), (4,5), (5,6) As w>=w2 ; m[2,5] = max{m[2-1,5] , m[2-1,5-3]+4} =max{ 3,3+4} W i 1 2 3 4 3 4 7 5 Thanks to : Neha Katyal (17, MCS '11), Shikha Walia (27, MCS'11)

26 As w>=w3 ; m[3,5] = max{m[3-1,5] , m[3-1,5-4]+5} =max{ 7,0+5}
(2,3), (3,4), (4,5), (5,6) As w>=w3 ; m[3,5] = max{m[3-1,5] , m[3-1,5-4]+5} =max{ 7,0+5} W i 1 2 3 4 3 4 7 5 Thanks to : Neha Katyal (17, MCS '11), Shikha Walia (27, MCS'11)

27 As w>=w4 ; m[4,5] = max{m[4-1,5] , m[4-1,5-5]+6} =max{ 7,0+6}
(2,3), (3,4), (4,5), (5,6) As w>=w4 ; m[4,5] = max{m[4-1,5] , m[4-1,5-5]+6} =max{ 7,0+6} W i 1 2 3 4 3 4 7 5 Thanks to : Neha Katyal (17, MCS '11), Shikha Walia (27, MCS'11)

28 (2,3), (3,4), (4,5), (5,6) W i 1 2 3 4 3 4 7 5 Thanks to : Neha Katyal (17, MCS '11), Shikha Walia (27, MCS'11)

29 FPTAS Given \epsilon, let k = \epsilon P /n Let p’(a) = floor (p(a)/k)
Find an optimal solution, say S’, using DP with these profits. Output S’ Claim: p(S’) >= (1-\epsilon) OPT

30 kp’(a) <= p(a) p’(a) = floor (p(a)/k) >= p(a)/k - 1.
Thus, kp’(a) >= p(a) - k i.e. p(a) - kp’(a) <= k i.e. k p’(a) >= p(a) - k Let O be an optimal solution. The O is a solution for the problem with the new profits as well. Thus, p’(S’) >= p’(O) Thus, p(S) >= k p’(S’) >= kp’(O) >= p(O) – k|O| >= p(O) – kn = OPT - \epsilon P >= (1 - \epsilon) OPT (as OPT <= P)

31 Running Time O(n^2 P’) = O(n^2 floor(P/k)) = O(n^2 floor(n/\epsilon))
Which is polynomial in n and \epsilon.

32 Thank You! Consolidated by: Sumedha Upadhyaya( 42), Prachi Nagpal(41) (MCS '09)


Download ppt "MCS 312: NP Completeness and Approximation algorthms"

Similar presentations


Ads by Google