SlideShare a Scribd company logo
NADAR SARASWATHI COLLEGE OF ARTS&SCIENCE,THENI
DEPARTMENT OF COMPUTER
SCIENCE&INFORMATION TECHNOLOGY
V.VANMATHY
I-MSC(CS)
DATA STRUCTURE
ALGORITHMS
0/1 knapsack least cost
branch and bound&FIFO
branch and bound
TOPIC:
0/1 knapsack least cost branch and bound
Given N items with weight W[0…..n-1],values
V[0…..n-1] and a knapsack with capacity C select the
items such that:
1. The sum of weight taken into the knapsack I less
than or equal to c.
2. The sum of values of the items in the knapsack I
maximum among all the possible combinations
0/1 knapsack least cost branch and bound
Input: N=4,C=15,V[]={10,10,12,18},W[]={2,4,6,9}
Output:
Items taken into the knapsack are
1101
Maximum profit is 38
Explanation:
1 in the output indicates that the item is included in
the knapsack while 0 indicates that the item I
excluded.
0/1 knapsack least cost branch and bound
Since the maximum possible cost all owed is 15, the
ways to select items are:
(1101)->cost=2+4+9=15,profit=10+10+18=38
(0011)->cost=6+9=15,profit=12+18=30
(1110)->cost=2+4+6=12,profit=32
Hence,maximum profit possible wit hin a cost of 15
is 38.
0/1 knapsack least cost branch and bound
Input: N=4,C=21,V[]={18,20,14,18},w[]={6,3,5,9}
Output:
Items taken into the knapsack are
1101
Maximum profit is 56
Explanation:
Cost=6+3+9=18
Profit=18+20+18=56
Least cost
Upper= node:1 profit: 10 10 12 18
M=15 weight:2 4 6 9
c=-38u=-32 c=10+10+12+18/9*3
u=10+10+12 2 + 4 + 6
u=-32
upper value find the value remove 12
the value 18/9*3 find the answer 15-12=3
u=-32 c=10+10+12+2*3
c=-38
1
c
Least cost
18/9*5 remove value c=10+10+12+18/9*5
find the value u answer 2+ 4+6
u=-32
x=1 c=-38 10
u=-32 x=0 15-10=5
c=-38 c=-32 u=-22 c=10+12+10
c=-32
u=10+12
node: 2,3 u=-22
1
2 3
Least cost
c=10+10+12+18/9*7
u=-32 2+ 4+6
c=-38
u=-32 x=1 x=0 8
c=-38 c=-32 u=-22 15-8=7
x=0 x=1 c=10+12+14
u=-32 u=-22 c=-36
c=-38 c=-36 u=10+12
u=-22
Node:4,5
1
2 3
4 5
Least cost
c=10+10+12+18
u=-32 2+ 4+6 +9
x=1 c=-38
u=-32 x=0
c=-38 c=-32 u=-22
x=1 x=0 c=10+10+18
u=-32 u=-22 c=-38
c=-38 c=-36 u=10+10+18
x=1 x=0 u=-38
Node:7 u=-38
c=-38
1
2 3
4 5
6
7
k
Least cost
u=-32 lower bound>upper bound
x=1 x=0 c=-38 -20>-38
u=-32 u=-22 kill value node 9
c=-38 c=-32
x=1 x=0
u=-32 u=-22
x=1 x=0c=-38 c=-36 c=10+10
u=-32 u=-38 2+4
c=-38 c=-38 c=20
x=1 x=0
u=-38 node: 9
c=-38 k c=-20
1
3
2
4 5
6 7
8 9
k
X={1,1,0,1}
10+10+0+18=38
2+4+0+9=15
FIFO branch and bound solution
Draw the portion of the state space tree generated by the
FIFO BB technique for the knapsack instance of n=5
m=12
(p1,p2,p3,p4,p5)=(10,1,6,8,4)
(w1,w2,w3,w4,w5)=(4,6,3,4,2)
0/1 knapsack problem is a maximization problem but we
require FIFO BB knapsack problem, I a minimization
problem.
Hence,we convert the +ve profits into –ve profits.
Hence, the problem is converted from maximization
problem to minimization problem.
FIFO EXAMPLE
FIFO
FIFO
FIFO
FIFO
FIFO
FIFO
FIFO
FIFO
FIFO
FIFO
FIFO
FIFO
Data structure and algorithm

More Related Content

PPT
03 algorithm properties
PPTX
Merge sort
PPT
Queue Data Structure
PPTX
NP completeness
PPTX
BACKTRAKING TECHNIQUES IN ANALYTICS OF ALGORITHM
PPTX
Backtracking-N Queens Problem-Graph Coloring-Hamiltonian cycle
PPT
Backtracking Algorithm.ppt
PPTX
stack & queue
03 algorithm properties
Merge sort
Queue Data Structure
NP completeness
BACKTRAKING TECHNIQUES IN ANALYTICS OF ALGORITHM
Backtracking-N Queens Problem-Graph Coloring-Hamiltonian cycle
Backtracking Algorithm.ppt
stack & queue

What's hot (20)

PPT
Minimum spanning tree
PPTX
Merge Sort
PPTX
Huffman's algorithm in Data Structure
PDF
Machine Learning and Data Mining: 10 Introduction to Classification
PPTX
Abstract Data Types
PPTX
Back tracking and branch and bound class 20
PPTX
Java abstract class & abstract methods
PPTX
Introduction to stack
PPT
Graph algorithms
PPTX
Project on stack Data structure
PPTX
Divide and conquer 1
PPT
Lecture 8 dynamic programming
PPTX
Webinar : P, NP, NP-Hard , NP - Complete problems
PPTX
Exception handling in c++
PPTX
Data Structure and Algorithms Merge Sort
PPTX
single linked list
PPTX
Lecture optimal binary search tree
PPTX
Prim's algorithm
PPT
Backtracking
Minimum spanning tree
Merge Sort
Huffman's algorithm in Data Structure
Machine Learning and Data Mining: 10 Introduction to Classification
Abstract Data Types
Back tracking and branch and bound class 20
Java abstract class & abstract methods
Introduction to stack
Graph algorithms
Project on stack Data structure
Divide and conquer 1
Lecture 8 dynamic programming
Webinar : P, NP, NP-Hard , NP - Complete problems
Exception handling in c++
Data Structure and Algorithms Merge Sort
single linked list
Lecture optimal binary search tree
Prim's algorithm
Backtracking
Ad

Similar to Data structure and algorithm (20)

PPTX
MODI_SteppingStone.pptx
PPTX
PPT
Non linear function
PPTX
5b.Greedy Technique - Fractional Knapsack+Coin change Problem.pptx
DOCX
Homework4 b00346910
PPTX
Modified Distribution Method (MODI)
DOC
programming in C++ report
PPTX
Chapter 12 Dynamic programming.pptx
PDF
OR_Presentation on muli item deterministic inventory model
PDF
Pembahasan soal un matematika smp tahun 2014 paket 1-www.olimattohir.blogspot...
PPT
Unit-2 Branch & Bound Design of Algorithms.ppt
PDF
Ch 03
PDF
A NEW APPROACH FOR SOLVING TRANSPORTATION PROBLEM
PDF
Quantitative techniques for MBA (QDM)
DOCX
Question 1 1. Evaluate using integration by parts. l.docx
PPT
Transportation problem
PDF
Solucionário Fundamentos Circuitos Elétricos 5ª Ed.pdf
PDF
Fundamentals_of_Electric_Circuits_Instructor_Solutions_Manual_by.pdf
MODI_SteppingStone.pptx
Non linear function
5b.Greedy Technique - Fractional Knapsack+Coin change Problem.pptx
Homework4 b00346910
Modified Distribution Method (MODI)
programming in C++ report
Chapter 12 Dynamic programming.pptx
OR_Presentation on muli item deterministic inventory model
Pembahasan soal un matematika smp tahun 2014 paket 1-www.olimattohir.blogspot...
Unit-2 Branch & Bound Design of Algorithms.ppt
Ch 03
A NEW APPROACH FOR SOLVING TRANSPORTATION PROBLEM
Quantitative techniques for MBA (QDM)
Question 1 1. Evaluate using integration by parts. l.docx
Transportation problem
Solucionário Fundamentos Circuitos Elétricos 5ª Ed.pdf
Fundamentals_of_Electric_Circuits_Instructor_Solutions_Manual_by.pdf
Ad

More from vanmathy1 (6)

PPTX
VANMATHY V cloud computing
PPTX
VANMATHY V
PPTX
VANMATHY V.pptx
PPTX
vanmathy v DIP.pptx
PPTX
Compiler design
PPTX
Advanced Java programming
VANMATHY V cloud computing
VANMATHY V
VANMATHY V.pptx
vanmathy v DIP.pptx
Compiler design
Advanced Java programming

Recently uploaded (20)

PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
master seminar digital applications in india
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
GDM (1) (1).pptx small presentation for students
PDF
Classroom Observation Tools for Teachers
PPTX
Pharma ospi slides which help in ospi learning
PPTX
Cell Types and Its function , kingdom of life
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Anesthesia in Laparoscopic Surgery in India
Chinmaya Tiranga quiz Grand Finale.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
master seminar digital applications in india
Abdominal Access Techniques with Prof. Dr. R K Mishra
GDM (1) (1).pptx small presentation for students
Classroom Observation Tools for Teachers
Pharma ospi slides which help in ospi learning
Cell Types and Its function , kingdom of life
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Supply Chain Operations Speaking Notes -ICLT Program
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
A systematic review of self-coping strategies used by university students to ...
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
102 student loan defaulters named and shamed – Is someone you know on the list?
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...

Data structure and algorithm

  • 1. NADAR SARASWATHI COLLEGE OF ARTS&SCIENCE,THENI DEPARTMENT OF COMPUTER SCIENCE&INFORMATION TECHNOLOGY V.VANMATHY I-MSC(CS)
  • 2. DATA STRUCTURE ALGORITHMS 0/1 knapsack least cost branch and bound&FIFO branch and bound TOPIC:
  • 3. 0/1 knapsack least cost branch and bound Given N items with weight W[0…..n-1],values V[0…..n-1] and a knapsack with capacity C select the items such that: 1. The sum of weight taken into the knapsack I less than or equal to c. 2. The sum of values of the items in the knapsack I maximum among all the possible combinations
  • 4. 0/1 knapsack least cost branch and bound Input: N=4,C=15,V[]={10,10,12,18},W[]={2,4,6,9} Output: Items taken into the knapsack are 1101 Maximum profit is 38 Explanation: 1 in the output indicates that the item is included in the knapsack while 0 indicates that the item I excluded.
  • 5. 0/1 knapsack least cost branch and bound Since the maximum possible cost all owed is 15, the ways to select items are: (1101)->cost=2+4+9=15,profit=10+10+18=38 (0011)->cost=6+9=15,profit=12+18=30 (1110)->cost=2+4+6=12,profit=32 Hence,maximum profit possible wit hin a cost of 15 is 38.
  • 6. 0/1 knapsack least cost branch and bound Input: N=4,C=21,V[]={18,20,14,18},w[]={6,3,5,9} Output: Items taken into the knapsack are 1101 Maximum profit is 56 Explanation: Cost=6+3+9=18 Profit=18+20+18=56
  • 7. Least cost Upper= node:1 profit: 10 10 12 18 M=15 weight:2 4 6 9 c=-38u=-32 c=10+10+12+18/9*3 u=10+10+12 2 + 4 + 6 u=-32 upper value find the value remove 12 the value 18/9*3 find the answer 15-12=3 u=-32 c=10+10+12+2*3 c=-38 1 c
  • 8. Least cost 18/9*5 remove value c=10+10+12+18/9*5 find the value u answer 2+ 4+6 u=-32 x=1 c=-38 10 u=-32 x=0 15-10=5 c=-38 c=-32 u=-22 c=10+12+10 c=-32 u=10+12 node: 2,3 u=-22 1 2 3
  • 9. Least cost c=10+10+12+18/9*7 u=-32 2+ 4+6 c=-38 u=-32 x=1 x=0 8 c=-38 c=-32 u=-22 15-8=7 x=0 x=1 c=10+12+14 u=-32 u=-22 c=-36 c=-38 c=-36 u=10+12 u=-22 Node:4,5 1 2 3 4 5
  • 10. Least cost c=10+10+12+18 u=-32 2+ 4+6 +9 x=1 c=-38 u=-32 x=0 c=-38 c=-32 u=-22 x=1 x=0 c=10+10+18 u=-32 u=-22 c=-38 c=-38 c=-36 u=10+10+18 x=1 x=0 u=-38 Node:7 u=-38 c=-38 1 2 3 4 5 6 7 k
  • 11. Least cost u=-32 lower bound>upper bound x=1 x=0 c=-38 -20>-38 u=-32 u=-22 kill value node 9 c=-38 c=-32 x=1 x=0 u=-32 u=-22 x=1 x=0c=-38 c=-36 c=10+10 u=-32 u=-38 2+4 c=-38 c=-38 c=20 x=1 x=0 u=-38 node: 9 c=-38 k c=-20 1 3 2 4 5 6 7 8 9 k X={1,1,0,1} 10+10+0+18=38 2+4+0+9=15
  • 12. FIFO branch and bound solution Draw the portion of the state space tree generated by the FIFO BB technique for the knapsack instance of n=5 m=12 (p1,p2,p3,p4,p5)=(10,1,6,8,4) (w1,w2,w3,w4,w5)=(4,6,3,4,2) 0/1 knapsack problem is a maximization problem but we require FIFO BB knapsack problem, I a minimization problem. Hence,we convert the +ve profits into –ve profits. Hence, the problem is converted from maximization problem to minimization problem.
  • 14. FIFO
  • 15. FIFO
  • 16. FIFO
  • 17. FIFO
  • 18. FIFO
  • 19. FIFO
  • 20. FIFO
  • 21. FIFO
  • 22. FIFO
  • 23. FIFO
  • 24. FIFO
  • 25. FIFO