SlideShare a Scribd company logo
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

More Related Content

What's hot

Math Project Matrix
Math Project MatrixMath Project Matrix
Math Project Matrix
appliedmath40s
 
Math Project Matrix
Math Project MatrixMath Project Matrix
Math Project Matrix
appliedmath40s
 
2s complement arithmetic
2s complement arithmetic2s complement arithmetic
2s complement arithmetic
Sanjay Saluth
 
Binary Arithmetic Operations
Binary Arithmetic OperationsBinary Arithmetic Operations
Binary Arithmetic Operations
Digital System Design
 
Math quiz 1
Math quiz 1Math quiz 1
Math quiz 1
jsorrell2011
 
Math quiz 1
Math quiz 1Math quiz 1
Math quiz 1
jsorrell2011
 
Expresiones algebraicas genesis sira y osniel tobo
Expresiones algebraicas   genesis sira y osniel toboExpresiones algebraicas   genesis sira y osniel tobo
Expresiones algebraicas genesis sira y osniel tobo
osnielmapache
 
Number system
Number systemNumber system
Number system
Mantra VLSI
 
Box multiplication copy
Box multiplication   copyBox multiplication   copy
Box multiplication copy
CLakshmiPriya
 
Linear equations1
Linear equations1Linear equations1
Linear equations1
Monika Schwarze
 
Linear equations1
Linear equations1Linear equations1
Linear equations1
Monika Schwarze
 
Miscellaneous examples of binary , quinary and octonary numbers (2)
Miscellaneous examples of binary , quinary and octonary numbers (2)Miscellaneous examples of binary , quinary and octonary numbers (2)
Miscellaneous examples of binary , quinary and octonary numbers (2)
Nadeem Uddin
 
Digital and Logic Design Chapter 1 binary_systems
Digital and Logic Design Chapter 1 binary_systemsDigital and Logic Design Chapter 1 binary_systems
Digital and Logic Design Chapter 1 binary_systems
Imran Waris
 
Number Systems
Number SystemsNumber Systems
Number Systems
Jubayer Alam Shoikat
 
Alg2 lesson 5-9
Alg2 lesson 5-9Alg2 lesson 5-9
Alg2 lesson 5-9
Carol Defreese
 
Math Project Matrix
Math Project MatrixMath Project Matrix
Math Project Matrix
appliedmath40s
 
I t presentation
I t presentationI t presentation
I t presentation
pimggwalior
 
Chuyen de day cac so viet theo quy luat
Chuyen de day cac so viet theo quy luatChuyen de day cac so viet theo quy luat
Chuyen de day cac so viet theo quy luat
Cảnh
 
Math magic
Math magicMath magic
Math magic
Tathmainul Qulub
 
magic of math
magic of mathmagic of math
magic of math
Tedy Dwi Ariyanto
 

What's hot (20)

Math Project Matrix
Math Project MatrixMath Project Matrix
Math Project Matrix
 
Math Project Matrix
Math Project MatrixMath Project Matrix
Math Project Matrix
 
2s complement arithmetic
2s complement arithmetic2s complement arithmetic
2s complement arithmetic
 
Binary Arithmetic Operations
Binary Arithmetic OperationsBinary Arithmetic Operations
Binary Arithmetic Operations
 
Math quiz 1
Math quiz 1Math quiz 1
Math quiz 1
 
Math quiz 1
Math quiz 1Math quiz 1
Math quiz 1
 
Expresiones algebraicas genesis sira y osniel tobo
Expresiones algebraicas   genesis sira y osniel toboExpresiones algebraicas   genesis sira y osniel tobo
Expresiones algebraicas genesis sira y osniel tobo
 
Number system
Number systemNumber system
Number system
 
Box multiplication copy
Box multiplication   copyBox multiplication   copy
Box multiplication copy
 
Linear equations1
Linear equations1Linear equations1
Linear equations1
 
Linear equations1
Linear equations1Linear equations1
Linear equations1
 
Miscellaneous examples of binary , quinary and octonary numbers (2)
Miscellaneous examples of binary , quinary and octonary numbers (2)Miscellaneous examples of binary , quinary and octonary numbers (2)
Miscellaneous examples of binary , quinary and octonary numbers (2)
 
Digital and Logic Design Chapter 1 binary_systems
Digital and Logic Design Chapter 1 binary_systemsDigital and Logic Design Chapter 1 binary_systems
Digital and Logic Design Chapter 1 binary_systems
 
Number Systems
Number SystemsNumber Systems
Number Systems
 
Alg2 lesson 5-9
Alg2 lesson 5-9Alg2 lesson 5-9
Alg2 lesson 5-9
 
Math Project Matrix
Math Project MatrixMath Project Matrix
Math Project Matrix
 
I t presentation
I t presentationI t presentation
I t presentation
 
Chuyen de day cac so viet theo quy luat
Chuyen de day cac so viet theo quy luatChuyen de day cac so viet theo quy luat
Chuyen de day cac so viet theo quy luat
 
Math magic
Math magicMath magic
Math magic
 
magic of math
magic of mathmagic of math
magic of math
 

Similar to Homework4 b00346910

Data structure notes
Data structure notesData structure notes
Data structure notes
anujab5
 
2.2 add real numbers day 1-2
2.2 add real numbers   day 1-22.2 add real numbers   day 1-2
2.2 add real numbers day 1-2
bweldon
 
Binary Indexed Tree / Fenwick Tree
Binary Indexed Tree / Fenwick TreeBinary Indexed Tree / Fenwick Tree
Binary Indexed Tree / Fenwick Tree
Mohammed Ashiqur Rahman Baig
 
Long division and synthetic division
Long division and synthetic divisionLong division and synthetic division
Long division and synthetic division
Xylene Methyll Colorado
 
Vedic maths 2
Vedic maths 2Vedic maths 2
Vedic maths 2
indu thakur
 
ch3a-binary-numbers.ppt
ch3a-binary-numbers.pptch3a-binary-numbers.ppt
ch3a-binary-numbers.ppt
MUNAZARAZZAQELEA
 
Lenier Equation
Lenier EquationLenier Equation
Lenier Equation
Khadiza Begum
 
X ch 1 real numbers
X  ch 1  real numbersX  ch 1  real numbers
X ch 1 real numbers
AmruthaKB2
 
tutorial5.ppt
tutorial5.ppttutorial5.ppt
tutorial5.ppt
jvjfvvoa
 
123a ppt-all-2
123a ppt-all-2123a ppt-all-2
123a ppt-all-2
math123a
 
INTEGERS
INTEGERSINTEGERS
INTEGERS
sourabhrana21
 
ch3a-binary-numbers.ppt
ch3a-binary-numbers.pptch3a-binary-numbers.ppt
ch3a-binary-numbers.ppt
RabiaAsif31
 
Prep velvet – Speed Maths
Prep velvet – Speed MathsPrep velvet – Speed Maths
Prep velvet – Speed Maths
Prep Velvet
 
Pre-Calculus Quarter 4 ExamName _________________________ S.docx
Pre-Calculus Quarter 4 ExamName _________________________ S.docxPre-Calculus Quarter 4 ExamName _________________________ S.docx
Pre-Calculus Quarter 4 ExamName _________________________ S.docx
ChantellPantoja184
 
Mock cat solutions paper no 1
Mock cat solutions paper no 1Mock cat solutions paper no 1
Mock cat solutions paper no 1
Vandan Kashyap
 
Binary decimal conversion
Binary decimal conversionBinary decimal conversion
Binary decimal conversion
Martin Jacob
 
W1-L1 Negative-numbers-ppt..pptx
W1-L1 Negative-numbers-ppt..pptxW1-L1 Negative-numbers-ppt..pptx
W1-L1 Negative-numbers-ppt..pptx
Ghassan44
 
Operation and Production Mgt Assignment.pdf
Operation and Production Mgt Assignment.pdfOperation and Production Mgt Assignment.pdf
Operation and Production Mgt Assignment.pdf
Seetal Daas
 
Algebra 1 week 6 learn it 2
Algebra 1 week 6 learn it 2Algebra 1 week 6 learn it 2
Algebra 1 week 6 learn it 2
JessicaBiemiller
 
Minimization model by simplex method
Minimization model by simplex methodMinimization model by simplex method
Minimization model by simplex method
San Antonio de Padua - Center for Alternative Mathematics
 

Similar to Homework4 b00346910 (20)

Data structure notes
Data structure notesData structure notes
Data structure notes
 
2.2 add real numbers day 1-2
2.2 add real numbers   day 1-22.2 add real numbers   day 1-2
2.2 add real numbers day 1-2
 
Binary Indexed Tree / Fenwick Tree
Binary Indexed Tree / Fenwick TreeBinary Indexed Tree / Fenwick Tree
Binary Indexed Tree / Fenwick Tree
 
Long division and synthetic division
Long division and synthetic divisionLong division and synthetic division
Long division and synthetic division
 
Vedic maths 2
Vedic maths 2Vedic maths 2
Vedic maths 2
 
ch3a-binary-numbers.ppt
ch3a-binary-numbers.pptch3a-binary-numbers.ppt
ch3a-binary-numbers.ppt
 
Lenier Equation
Lenier EquationLenier Equation
Lenier Equation
 
X ch 1 real numbers
X  ch 1  real numbersX  ch 1  real numbers
X ch 1 real numbers
 
tutorial5.ppt
tutorial5.ppttutorial5.ppt
tutorial5.ppt
 
123a ppt-all-2
123a ppt-all-2123a ppt-all-2
123a ppt-all-2
 
INTEGERS
INTEGERSINTEGERS
INTEGERS
 
ch3a-binary-numbers.ppt
ch3a-binary-numbers.pptch3a-binary-numbers.ppt
ch3a-binary-numbers.ppt
 
Prep velvet – Speed Maths
Prep velvet – Speed MathsPrep velvet – Speed Maths
Prep velvet – Speed Maths
 
Pre-Calculus Quarter 4 ExamName _________________________ S.docx
Pre-Calculus Quarter 4 ExamName _________________________ S.docxPre-Calculus Quarter 4 ExamName _________________________ S.docx
Pre-Calculus Quarter 4 ExamName _________________________ S.docx
 
Mock cat solutions paper no 1
Mock cat solutions paper no 1Mock cat solutions paper no 1
Mock cat solutions paper no 1
 
Binary decimal conversion
Binary decimal conversionBinary decimal conversion
Binary decimal conversion
 
W1-L1 Negative-numbers-ppt..pptx
W1-L1 Negative-numbers-ppt..pptxW1-L1 Negative-numbers-ppt..pptx
W1-L1 Negative-numbers-ppt..pptx
 
Operation and Production Mgt Assignment.pdf
Operation and Production Mgt Assignment.pdfOperation and Production Mgt Assignment.pdf
Operation and Production Mgt Assignment.pdf
 
Algebra 1 week 6 learn it 2
Algebra 1 week 6 learn it 2Algebra 1 week 6 learn it 2
Algebra 1 week 6 learn it 2
 
Minimization model by simplex method
Minimization model by simplex methodMinimization model by simplex method
Minimization model by simplex method
 

Homework4 b00346910

  • 1. 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
  • 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 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
  • 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 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
  • 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