SlideShare a Scribd company logo
1 of 22
Download to read offline
0/1 Knapsack Problem
(using BRANCH & BOUND)
Presented by
41.ABHISHEK KUMAR SINGH
0/1 Knapsack Problem
Given two integer arrays val[0..n-1] and wt[0..n-1] that represent values and weights
associated with n items respectively.
Find out the maximum value subset of val[] such that sum of the weights of this
subset is smaller than or equal to Knapsack capacity W.
We have ‘n’ items with value v1 , v2 . . . vn and weight of the corresponding items
is w1 , w2 . . . Wn .
Max capacity is W .
We can either choose or not choose an item. We have x1 , x2 . . . xn.
Here xi = { 1 , 0 }.
xi = 1 , item chosen
xi = 0 , item not chosen
Different approaches of this problem :
 Dynamic programming
 Brute force
 Backtracking
 Branch and bound
Why branch and bound ?
 Greedy approach works only for fractional knapsack problem.
 If weights are not integers , dynamic programming will not work.
 There are 2n possible combinations of item , complexity for brute force
goes exponentially.
What is branch and bound ?
 Branch and bound is an algorithm design paradigm which is
generally used for solving combinatorial optimization
problems.
 These problems typically exponential in terms of time
complexity and may require exploring all possible
permutations in worst case.
 Branch and Bound solve these problems relatively quickly.
 Combinatorial optimization problem is an
optimization problem, where an optimal solution
has to be identified from a finite set of solutions.
 Sort all items in decreasing order of ratio of value per unit
weight so that an upper bound can be computed using Greedy
Approach.
 Initialize maximum profit, maxProfit = 0
 Create an empty queue, Q.
 Create a dummy node of decision tree and enqueue it to Q.
Profit and weight of dummy node are 0.

ALGORITHM
 Do following while Q is not empty.

 Extract an item from Q. Let the extracted item be u.
 Compute profit of next level node. If the profit is more than maxProfit, then update
maxProfit.
 Compute bound of next level node. If bound is more than maxProfit, then add next
level node to Q.
 Consider the case when next level node is not considered as part of solution and
add a node to queue with level as next, but weight and profit without considering
next level nodes.

EXAMPLE :
$90
12
$98
Max weight = 16
maxProfit = 0
$ 0
0
$115
$90
12
$98
$115
2
$40
Max weight = 16
maxProfit = 40
$90
12
$98
Max weight = 16
maxProfit = 40
$ 0
0
$82
$90
12
$98
Max weight = 16
maxProfit = 70
$70
7
$115
$90
12
$98
2
$40
$98
Max weight = 16
maxProfit = 70
$90
12
$98
Max weight = 16
maxProfit = 70
$30
5
$82
$90
12
$98
Max weight = 16
maxProfit = 70
$ 0
0
$60
$90
12
$98
Max weight = 16
maxProfit = 70
$120
17
$0
$90
12
$98
Max weight = 16
maxProfit = 70
$70
7
$80
Max weight = 16
maxProfit = 90
struct Item
{
float weight;
int value;
}
Node structure to store information of decision tree
struct Node
{
int level, profit, bound;
float weight;
// level ---> Level of node in decision tree (or index ) in arr[]
// profit ---> Profit of nodes on path from root to this node (including this node)
// bound ---> Upper bound of maximum profit in subtree of this node
}
Data items used in the Algorithm :
knapsack(int W, Item arr[], int n)
queue<Node> Q
Node u, v //u.level = -1
Q.push(u) //u.profit = u.weight = 0
while ( !Q.empty() ) //int maxProfit = 0
u = Q.front() & Q.pop()
v.level = u.level + 1 // selecting the item
v.weight = u.weight + arr[v.level].weight
v.profit = u.profit + arr[v.level].value
if (v.weight <= W && v.profit > maxProfit)
maxProfit = v.profit
v.bound = bound(v, n, W, arr)
if (v.bound > maxProfit)
Q.push(v)
v.weight = u.weight // not selecting the item
v.profit = u.profit
v.bound = bound(v, n, W, arr)
If (v.bound > maxProfit)
Q.push(v)
return (maxProfit)
Algorithm for maxProfit :
bound(Node u, int n, int W, Item a[])
if (u.weight >= W)
return (0)
int u_bound <- u.profit
int j <- u.level + 1
int totweight <- u.weight
while ((j < n) && (totweight + a[j].weight <= W))
totweight <- totweight + a[j].weight
u_bound <- u_bound + a[j].value
j++
if (j < n)
u_bound <- u_bound + ( W - totweight ) * a[j].value /a[j].weight
return (u_bound)
Procedure to calculate upper bound :
THANK
YOU

More Related Content

What's hot

Sum of subsets problem by backtracking 
Sum of subsets problem by backtracking Sum of subsets problem by backtracking 
Sum of subsets problem by backtracking Hasanain Alshadoodee
 
Binary Heap Tree, Data Structure
Binary Heap Tree, Data Structure Binary Heap Tree, Data Structure
Binary Heap Tree, Data Structure Anand Ingle
 
The Maximum Subarray Problem
The Maximum Subarray ProblemThe Maximum Subarray Problem
The Maximum Subarray ProblemKamran Ashraf
 
04 brute force
04 brute force04 brute force
04 brute forceHira Gul
 
Topological Sorting
Topological SortingTopological Sorting
Topological SortingShahDhruv21
 
Circle algorithm
Circle algorithmCircle algorithm
Circle algorithmPooja Dixit
 
Rules of data mining
Rules of data miningRules of data mining
Rules of data miningSulman Ahmed
 
Polynomial reppresentation using Linkedlist-Application of LL.pptx
Polynomial reppresentation using Linkedlist-Application of LL.pptxPolynomial reppresentation using Linkedlist-Application of LL.pptx
Polynomial reppresentation using Linkedlist-Application of LL.pptxAlbin562191
 
Binomial Heap
Binomial HeapBinomial Heap
Binomial HeapGoa App
 
Red black tree
Red black treeRed black tree
Red black treeRajendran
 
Algorithm Using Divide And Conquer
Algorithm Using Divide And ConquerAlgorithm Using Divide And Conquer
Algorithm Using Divide And ConquerUrviBhalani2
 
Greedy with Task Scheduling Algorithm.ppt
Greedy with Task Scheduling Algorithm.pptGreedy with Task Scheduling Algorithm.ppt
Greedy with Task Scheduling Algorithm.pptRuchika Sinha
 
The n Queen Problem
The n Queen ProblemThe n Queen Problem
The n Queen ProblemSukrit Gupta
 

What's hot (20)

Sum of subsets problem by backtracking 
Sum of subsets problem by backtracking Sum of subsets problem by backtracking 
Sum of subsets problem by backtracking 
 
Binary Heap Tree, Data Structure
Binary Heap Tree, Data Structure Binary Heap Tree, Data Structure
Binary Heap Tree, Data Structure
 
The Maximum Subarray Problem
The Maximum Subarray ProblemThe Maximum Subarray Problem
The Maximum Subarray Problem
 
04 brute force
04 brute force04 brute force
04 brute force
 
Linked List
Linked ListLinked List
Linked List
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
Topological Sorting
Topological SortingTopological Sorting
Topological Sorting
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
Circle algorithm
Circle algorithmCircle algorithm
Circle algorithm
 
Rules of data mining
Rules of data miningRules of data mining
Rules of data mining
 
Polynomial reppresentation using Linkedlist-Application of LL.pptx
Polynomial reppresentation using Linkedlist-Application of LL.pptxPolynomial reppresentation using Linkedlist-Application of LL.pptx
Polynomial reppresentation using Linkedlist-Application of LL.pptx
 
Knapsack problem
Knapsack problemKnapsack problem
Knapsack problem
 
Greedy method
Greedy methodGreedy method
Greedy method
 
Binomial Heap
Binomial HeapBinomial Heap
Binomial Heap
 
Red black tree
Red black treeRed black tree
Red black tree
 
Bin packing
Bin packingBin packing
Bin packing
 
Heap and heapsort
Heap and heapsortHeap and heapsort
Heap and heapsort
 
Algorithm Using Divide And Conquer
Algorithm Using Divide And ConquerAlgorithm Using Divide And Conquer
Algorithm Using Divide And Conquer
 
Greedy with Task Scheduling Algorithm.ppt
Greedy with Task Scheduling Algorithm.pptGreedy with Task Scheduling Algorithm.ppt
Greedy with Task Scheduling Algorithm.ppt
 
The n Queen Problem
The n Queen ProblemThe n Queen Problem
The n Queen Problem
 

Similar to knapsackusingbranchandbound

0 1 knapsack using naive recursive approach and top-down dynamic programming ...
0 1 knapsack using naive recursive approach and top-down dynamic programming ...0 1 knapsack using naive recursive approach and top-down dynamic programming ...
0 1 knapsack using naive recursive approach and top-down dynamic programming ...Abhishek Singh
 
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.pptParallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.pptdakccse
 
Unit 3- Greedy Method.pptx
Unit 3- Greedy Method.pptxUnit 3- Greedy Method.pptx
Unit 3- Greedy Method.pptxMaryJacob24
 
Optimization problems
Optimization problemsOptimization problems
Optimization problemsRuchika Sinha
 
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.pptParallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.pptBinayakMukherjee4
 
Unit 3 - Greedy Method
Unit 3  - Greedy MethodUnit 3  - Greedy Method
Unit 3 - Greedy MethodMaryJacob24
 
Unit 3 greedy method
Unit 3  greedy methodUnit 3  greedy method
Unit 3 greedy methodMaryJacob24
 
Knapsack problem using greedy approach
Knapsack problem using greedy approachKnapsack problem using greedy approach
Knapsack problem using greedy approachpadmeshagrekar
 
Knapsack Dynamic
Knapsack DynamicKnapsack Dynamic
Knapsack DynamicParas Patel
 
final-ppts-daa-unit-iii-greedy-method.pdf
final-ppts-daa-unit-iii-greedy-method.pdffinal-ppts-daa-unit-iii-greedy-method.pdf
final-ppts-daa-unit-iii-greedy-method.pdfJasmineSayyed3
 
fdocuments.in_branch-and-bound-design-and-analysis-of-alogorithm.ppt
fdocuments.in_branch-and-bound-design-and-analysis-of-alogorithm.pptfdocuments.in_branch-and-bound-design-and-analysis-of-alogorithm.ppt
fdocuments.in_branch-and-bound-design-and-analysis-of-alogorithm.pptKartikGupta711
 
Knapsack problem and Memory Function
Knapsack problem and Memory FunctionKnapsack problem and Memory Function
Knapsack problem and Memory FunctionBarani Tharan
 
lecture14-SVMs (1).ppt
lecture14-SVMs (1).pptlecture14-SVMs (1).ppt
lecture14-SVMs (1).pptmuqadsatareen
 
test pre
test pretest pre
test prefarazch
 
5.3 dynamic programming 03
5.3 dynamic programming 035.3 dynamic programming 03
5.3 dynamic programming 03Krish_ver2
 

Similar to knapsackusingbranchandbound (20)

0 1 knapsack using naive recursive approach and top-down dynamic programming ...
0 1 knapsack using naive recursive approach and top-down dynamic programming ...0 1 knapsack using naive recursive approach and top-down dynamic programming ...
0 1 knapsack using naive recursive approach and top-down dynamic programming ...
 
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.pptParallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
 
Unit 3- Greedy Method.pptx
Unit 3- Greedy Method.pptxUnit 3- Greedy Method.pptx
Unit 3- Greedy Method.pptx
 
Optimization problems
Optimization problemsOptimization problems
Optimization problems
 
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.pptParallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
 
Knapsack dp
Knapsack dpKnapsack dp
Knapsack dp
 
Unit 3 - Greedy Method
Unit 3  - Greedy MethodUnit 3  - Greedy Method
Unit 3 - Greedy Method
 
Unit 3 greedy method
Unit 3  greedy methodUnit 3  greedy method
Unit 3 greedy method
 
Module 3_DAA (2).pptx
Module 3_DAA (2).pptxModule 3_DAA (2).pptx
Module 3_DAA (2).pptx
 
Knapsack problem using greedy approach
Knapsack problem using greedy approachKnapsack problem using greedy approach
Knapsack problem using greedy approach
 
Unit 3-Greedy Method
Unit 3-Greedy MethodUnit 3-Greedy Method
Unit 3-Greedy Method
 
Knapsack Dynamic
Knapsack DynamicKnapsack Dynamic
Knapsack Dynamic
 
final-ppts-daa-unit-iii-greedy-method.pdf
final-ppts-daa-unit-iii-greedy-method.pdffinal-ppts-daa-unit-iii-greedy-method.pdf
final-ppts-daa-unit-iii-greedy-method.pdf
 
fdocuments.in_branch-and-bound-design-and-analysis-of-alogorithm.ppt
fdocuments.in_branch-and-bound-design-and-analysis-of-alogorithm.pptfdocuments.in_branch-and-bound-design-and-analysis-of-alogorithm.ppt
fdocuments.in_branch-and-bound-design-and-analysis-of-alogorithm.ppt
 
Knapsack problem and Memory Function
Knapsack problem and Memory FunctionKnapsack problem and Memory Function
Knapsack problem and Memory Function
 
lecture14-SVMs (1).ppt
lecture14-SVMs (1).pptlecture14-SVMs (1).ppt
lecture14-SVMs (1).ppt
 
test pre
test pretest pre
test pre
 
5.3 dynamic programming 03
5.3 dynamic programming 035.3 dynamic programming 03
5.3 dynamic programming 03
 
Backtracking
BacktrackingBacktracking
Backtracking
 
neural networksNnf
neural networksNnfneural networksNnf
neural networksNnf
 

Recently uploaded

the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...ranjana rawat
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 

Recently uploaded (20)

the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 

knapsackusingbranchandbound

  • 1. 0/1 Knapsack Problem (using BRANCH & BOUND) Presented by 41.ABHISHEK KUMAR SINGH
  • 2. 0/1 Knapsack Problem Given two integer arrays val[0..n-1] and wt[0..n-1] that represent values and weights associated with n items respectively. Find out the maximum value subset of val[] such that sum of the weights of this subset is smaller than or equal to Knapsack capacity W. We have ‘n’ items with value v1 , v2 . . . vn and weight of the corresponding items is w1 , w2 . . . Wn . Max capacity is W . We can either choose or not choose an item. We have x1 , x2 . . . xn. Here xi = { 1 , 0 }. xi = 1 , item chosen xi = 0 , item not chosen
  • 3. Different approaches of this problem :  Dynamic programming  Brute force  Backtracking  Branch and bound
  • 4. Why branch and bound ?  Greedy approach works only for fractional knapsack problem.  If weights are not integers , dynamic programming will not work.  There are 2n possible combinations of item , complexity for brute force goes exponentially.
  • 5. What is branch and bound ?  Branch and bound is an algorithm design paradigm which is generally used for solving combinatorial optimization problems.  These problems typically exponential in terms of time complexity and may require exploring all possible permutations in worst case.  Branch and Bound solve these problems relatively quickly.
  • 6.  Combinatorial optimization problem is an optimization problem, where an optimal solution has to be identified from a finite set of solutions.
  • 7.  Sort all items in decreasing order of ratio of value per unit weight so that an upper bound can be computed using Greedy Approach.  Initialize maximum profit, maxProfit = 0  Create an empty queue, Q.  Create a dummy node of decision tree and enqueue it to Q. Profit and weight of dummy node are 0.  ALGORITHM
  • 8.  Do following while Q is not empty.   Extract an item from Q. Let the extracted item be u.  Compute profit of next level node. If the profit is more than maxProfit, then update maxProfit.  Compute bound of next level node. If bound is more than maxProfit, then add next level node to Q.  Consider the case when next level node is not considered as part of solution and add a node to queue with level as next, but weight and profit without considering next level nodes.  EXAMPLE :
  • 9. $90 12 $98 Max weight = 16 maxProfit = 0 $ 0 0 $115
  • 11. $90 12 $98 Max weight = 16 maxProfit = 40 $ 0 0 $82
  • 12. $90 12 $98 Max weight = 16 maxProfit = 70 $70 7 $115
  • 14. $90 12 $98 Max weight = 16 maxProfit = 70 $30 5 $82
  • 15. $90 12 $98 Max weight = 16 maxProfit = 70 $ 0 0 $60
  • 16. $90 12 $98 Max weight = 16 maxProfit = 70 $120 17 $0
  • 17. $90 12 $98 Max weight = 16 maxProfit = 70 $70 7 $80
  • 18. Max weight = 16 maxProfit = 90
  • 19. struct Item { float weight; int value; } Node structure to store information of decision tree struct Node { int level, profit, bound; float weight; // level ---> Level of node in decision tree (or index ) in arr[] // profit ---> Profit of nodes on path from root to this node (including this node) // bound ---> Upper bound of maximum profit in subtree of this node } Data items used in the Algorithm :
  • 20. knapsack(int W, Item arr[], int n) queue<Node> Q Node u, v //u.level = -1 Q.push(u) //u.profit = u.weight = 0 while ( !Q.empty() ) //int maxProfit = 0 u = Q.front() & Q.pop() v.level = u.level + 1 // selecting the item v.weight = u.weight + arr[v.level].weight v.profit = u.profit + arr[v.level].value if (v.weight <= W && v.profit > maxProfit) maxProfit = v.profit v.bound = bound(v, n, W, arr) if (v.bound > maxProfit) Q.push(v) v.weight = u.weight // not selecting the item v.profit = u.profit v.bound = bound(v, n, W, arr) If (v.bound > maxProfit) Q.push(v) return (maxProfit) Algorithm for maxProfit :
  • 21. bound(Node u, int n, int W, Item a[]) if (u.weight >= W) return (0) int u_bound <- u.profit int j <- u.level + 1 int totweight <- u.weight while ((j < n) && (totweight + a[j].weight <= W)) totweight <- totweight + a[j].weight u_bound <- u_bound + a[j].value j++ if (j < n) u_bound <- u_bound + ( W - totweight ) * a[j].value /a[j].weight return (u_bound) Procedure to calculate upper bound :