CS575: Design and Analysis of Algorithms
Homework -4B00443447
Venkata Sai Krishna Kishore Kalaga
1) W = 30, S = {(i1, 5, $50), (i2, 20, $140), (i3, 10, $60)} (Given)
Step-1:
Weight: 0 1 2 3 4 5 ………30
MaxProfit {}: 0 0 0 0 0 0 ……….0
Step-2:
Weight: 0 1 2 3 4 5 ………30
MaxProfit {}: 0 0 0 0 0 0 ……….0
MaxProfit {i1}: 0 0 0 0 0 50 ……….50
Step-3:
Weight: 0… 4 5…. 20… 22 25 ………30
MaxProfit {}: 0… 0 0 0 0 0 ……….0
MaxProfit {i1}: 0… 0 50 50 50 50 ……….50
MaxProfit {i2}: 0… 0 50 140 140 190 ……….190
B [2, 20] = max {B [1, 20], B [1, 20-20] +b2}
= 140
B [2, 25] = max {B [1, 25], B [1, 25-20] + b2}
= 190
Step-4:
Weight: 0… 4 5… 10… 20… 22 25 ………30
MaxProfit {}: 0… 0 0 0 0 0 0 ……….0
MaxProfit {i1}: 0… 0 50 50 50 50 50 ……….50
MaxProfit {i2}: 0… 0 5060 140 140 190 ……….190
MaxProfit {i3}: 0… 0 50 60 140 140 190 ……….200
B[3, 20] = max { B[2, 20], B[2, 20-10]+60}
= 140
B[3, 25] = max { B[2, 25], B[2,25-10] + 60}
= 190
B[3,30] = max { B[2,30], B[2, 30-10] + 60}
=200
For a given set of items and a knapsack with weight 30,maximum profit is $200.
2).Set = {3, 4, 5, 6}, sum =13 (Given)
State Space tree:
1
Yes No 17
2
I1: yes No
Yes No 18 25
3 10
I2: Yes No Yes No
Yes No Yes No 22 26 29
4 7 11 14 19
I3: Yes No Y N
Yes No Yes No Yes No Yes No 24 30
5 6 8 9 Yes No
23Yes No 31
20 21
12 13
27 28
15 16
0
0
3
7 3
4
12
0
7
18 12 13 7
8 3
14 8
9 3
9 4
15 9
10 4
5 0
11 5
6 0
The Solution is {3, 4, 6} which sums the total to 13 and marked in 8th
node in
green.
b). Pruned State space tree:
Nodes numbered in call order.
Here we won’t consider the nodes that are not going to give us the total sum we
need, we calculate the total before and won’t proceed further and backtrack from
there to other node.
From the above, we know that nodes 5, 9,10,13,14 are not going to give us 13
totals, so we stop there. We have node 5 which has the probability of giving us
sum 13 so we proceed further and calculate & we get the solution at node 6
marked in grey.
3). We need to arrange the items in the correct order needed by the KWF (largest
profit/weight first)
Calculation for node 1:
Maxprofit = $0 (n=4, c=16)
Node 1: profit = $0, weight =0
Bound = profit + p1 + p2 + (C-7)*p3/w3
= $0 + $40 + $30 + (16-7)*$50/10 = $115
1 is promising because its weight = 0<c=16 and its bound $115>0(maxprofit)
1, maxprofit = $0
2, maxprofit = $40
13
B: Cannot lead to best solution (82<90)
Calculation for Node 2:
Item 3 with profit $40 and weight 2 is included maxprofit = $40
Profit = $40, weight =2
$0, 0,
$115
$0, 0,
$115
$40, 2,
$115 $0, $0,
$82
Bound = profit + p2 +(c-7)*p3/w3
=$40+$30+ (16-7)*$50/10 = $115
2 is promising because its weight = 2 <c =16 and its bound $115 >$40 the value of
max profit.
Calculation for Node 3:
Item2 with profit = $70, weight = 7,
Bound = $70 + $(16 – 7)*50/10
= $115
Max profit = $70.
Node 3 is promising as its weight 7 < C =16 and its bound $115> max profit 40.
Calculation for Node 4:
Item 3 with profit = $120 >bound andweight = 17 > C.
It doesn’t satisfy and hence is not a promising node.
Since node 4 is not a promising node we back track to node 3.
Here we won’t add item 3. That is we will go to the right child node of node 3.
Calculation for Node 5: Exclude item 3
profit = 70
weight = 7
bound = 70 + 10 = $80
Max profit = 70
Node 5 is promising because its Max profit is 70 < upper bound and weight = 7 < C
=16
Calculation for Node 6:
Add item 4 [excluding item 3]
profit = $80
weight = 12
bound = $80
Max profit = $80.
Node 6 is promising since 12 < C=16 but there are no more items left hence we
need to back track.
Visit the right child node of node 5.
Calculation for Node 7:
Excluded items 3 and 4
profit = $70
weight = 7
bound = $70
Max profit = $80.
Upper bound < Max profit and there are no items left. So back track to node 2.
Calculation for Node 8:
Exclude item 2.
profit = $40
weight = 2
bound = 40 + 50 +(16 -12)*10/5
= $98
Maxprofit = $80.
Node 7 is promising since weight < C.
Calculation for Node 9:
Add item 3[excluding item 2]
profit = 40 + 50 = $90
weight = 2+10 = 12
bound = 90+8 =98
Max profit = $90
Node 9 is promising since 12 < C=16.
Calculation for Node 10:
Add item 4[excluding item 2]
profit = 90+10 =$100
weight = 12 + 5 =17 > C
Hence not promising. Back track to node 9 and visit its right child.
Calculation for Node 11:
Exclude item 4 and 2
profit = $90
weight = 12
bound = 90, Max profit = $90.
Node 11 is promising but there are no items left. So back track to node 8
Calculation for Node 12:
Exclude items 2 and 3.
profit = $40
weight = 2
bound = 40 + 10 = 50, Max profit = $90
bound<max profit. Node 12 is not a legal node in the solution.
Back track to node 1
Calculation for Node 13:
Item 3 with profit $40 and weight 2 is not included
At this point, maxprofit = $90 and is not changed
Bound = profit + p2 +p3+(c-7)*p4/w4
=$0+$30+ $50+ (16-15)*$10/5= $82
13 is nonpromising becauseit’s bound $82<$90 the value of maxprofit.
1, maxprofit = $0
2, maxprofit = $40 13 : B (can’t be best sol)
13
3 8
4, F (17>16) 12
5 9 B(50<90)
Maxprofit = 90
6 7 10 11
Not optimal(N), maxprofit = 80 NF(not feasible)(17>16)
OPTIMAL
$40,
2,
$115
$0, $0,
$82
$0, 0,
$115
$70,
7,
$115
120,
17
$40,
2,
$98
$40,
2,
$50$70,
7 $80
$80,
12,
$80
$70,
7,
$70
$90,
12,
$98
$100,
17 $90,
12,
$90
Homework4 b00346910

Homework4 b00346910

  • 1.
    CS575: Design andAnalysis of Algorithms Homework -4B00443447 Venkata Sai Krishna Kishore Kalaga 1) W = 30, S = {(i1, 5, $50), (i2, 20, $140), (i3, 10, $60)} (Given) Step-1: Weight: 0 1 2 3 4 5 ………30 MaxProfit {}: 0 0 0 0 0 0 ……….0 Step-2: Weight: 0 1 2 3 4 5 ………30 MaxProfit {}: 0 0 0 0 0 0 ……….0 MaxProfit {i1}: 0 0 0 0 0 50 ……….50 Step-3: Weight: 0… 4 5…. 20… 22 25 ………30 MaxProfit {}: 0… 0 0 0 0 0 ……….0 MaxProfit {i1}: 0… 0 50 50 50 50 ……….50 MaxProfit {i2}: 0… 0 50 140 140 190 ……….190 B [2, 20] = max {B [1, 20], B [1, 20-20] +b2} = 140 B [2, 25] = max {B [1, 25], B [1, 25-20] + b2} = 190 Step-4: Weight: 0… 4 5… 10… 20… 22 25 ………30 MaxProfit {}: 0… 0 0 0 0 0 0 ……….0 MaxProfit {i1}: 0… 0 50 50 50 50 50 ……….50 MaxProfit {i2}: 0… 0 5060 140 140 190 ……….190
  • 2.
    MaxProfit {i3}: 0…0 50 60 140 140 190 ……….200 B[3, 20] = max { B[2, 20], B[2, 20-10]+60} = 140 B[3, 25] = max { B[2, 25], B[2,25-10] + 60} = 190 B[3,30] = max { B[2,30], B[2, 30-10] + 60} =200 For a given set of items and a knapsack with weight 30,maximum profit is $200. 2).Set = {3, 4, 5, 6}, sum =13 (Given) State Space tree: 1 Yes No 17 2 I1: yes No Yes No 18 25 3 10 I2: Yes No Yes No Yes No Yes No 22 26 29 4 7 11 14 19 I3: Yes No Y N Yes No Yes No Yes No Yes No 24 30 5 6 8 9 Yes No 23Yes No 31 20 21 12 13 27 28 15 16 0 0 3 7 3 4 12 0 7 18 12 13 7 8 3 14 8 9 3 9 4 15 9 10 4 5 0 11 5 6 0
  • 3.
    The Solution is{3, 4, 6} which sums the total to 13 and marked in 8th node in green. b). Pruned State space tree: Nodes numbered in call order. Here we won’t consider the nodes that are not going to give us the total sum we need, we calculate the total before and won’t proceed further and backtrack from there to other node. From the above, we know that nodes 5, 9,10,13,14 are not going to give us 13 totals, so we stop there. We have node 5 which has the probability of giving us sum 13 so we proceed further and calculate & we get the solution at node 6 marked in grey.
  • 4.
    3). We needto arrange the items in the correct order needed by the KWF (largest profit/weight first) Calculation for node 1: Maxprofit = $0 (n=4, c=16) Node 1: profit = $0, weight =0 Bound = profit + p1 + p2 + (C-7)*p3/w3 = $0 + $40 + $30 + (16-7)*$50/10 = $115 1 is promising because its weight = 0<c=16 and its bound $115>0(maxprofit) 1, maxprofit = $0 2, maxprofit = $40 13 B: Cannot lead to best solution (82<90) Calculation for Node 2: Item 3 with profit $40 and weight 2 is included maxprofit = $40 Profit = $40, weight =2 $0, 0, $115 $0, 0, $115 $40, 2, $115 $0, $0, $82
  • 5.
    Bound = profit+ p2 +(c-7)*p3/w3 =$40+$30+ (16-7)*$50/10 = $115 2 is promising because its weight = 2 <c =16 and its bound $115 >$40 the value of max profit. Calculation for Node 3: Item2 with profit = $70, weight = 7, Bound = $70 + $(16 – 7)*50/10 = $115 Max profit = $70. Node 3 is promising as its weight 7 < C =16 and its bound $115> max profit 40. Calculation for Node 4: Item 3 with profit = $120 >bound andweight = 17 > C. It doesn’t satisfy and hence is not a promising node. Since node 4 is not a promising node we back track to node 3. Here we won’t add item 3. That is we will go to the right child node of node 3. Calculation for Node 5: Exclude item 3 profit = 70 weight = 7 bound = 70 + 10 = $80 Max profit = 70 Node 5 is promising because its Max profit is 70 < upper bound and weight = 7 < C =16 Calculation for Node 6: Add item 4 [excluding item 3] profit = $80 weight = 12 bound = $80 Max profit = $80. Node 6 is promising since 12 < C=16 but there are no more items left hence we need to back track.
  • 6.
    Visit the rightchild node of node 5. Calculation for Node 7: Excluded items 3 and 4 profit = $70 weight = 7 bound = $70 Max profit = $80. Upper bound < Max profit and there are no items left. So back track to node 2. Calculation for Node 8: Exclude item 2. profit = $40 weight = 2 bound = 40 + 50 +(16 -12)*10/5 = $98 Maxprofit = $80. Node 7 is promising since weight < C. Calculation for Node 9: Add item 3[excluding item 2] profit = 40 + 50 = $90 weight = 2+10 = 12 bound = 90+8 =98 Max profit = $90 Node 9 is promising since 12 < C=16. Calculation for Node 10: Add item 4[excluding item 2] profit = 90+10 =$100 weight = 12 + 5 =17 > C Hence not promising. Back track to node 9 and visit its right child. Calculation for Node 11: Exclude item 4 and 2 profit = $90 weight = 12
  • 7.
    bound = 90,Max profit = $90. Node 11 is promising but there are no items left. So back track to node 8 Calculation for Node 12: Exclude items 2 and 3. profit = $40 weight = 2 bound = 40 + 10 = 50, Max profit = $90 bound<max profit. Node 12 is not a legal node in the solution. Back track to node 1 Calculation for Node 13: Item 3 with profit $40 and weight 2 is not included At this point, maxprofit = $90 and is not changed Bound = profit + p2 +p3+(c-7)*p4/w4 =$0+$30+ $50+ (16-15)*$10/5= $82 13 is nonpromising becauseit’s bound $82<$90 the value of maxprofit.
  • 8.
    1, maxprofit =$0 2, maxprofit = $40 13 : B (can’t be best sol) 13 3 8 4, F (17>16) 12 5 9 B(50<90) Maxprofit = 90 6 7 10 11 Not optimal(N), maxprofit = 80 NF(not feasible)(17>16) OPTIMAL $40, 2, $115 $0, $0, $82 $0, 0, $115 $70, 7, $115 120, 17 $40, 2, $98 $40, 2, $50$70, 7 $80 $80, 12, $80 $70, 7, $70 $90, 12, $98 $100, 17 $90, 12, $90