17
LOGO 1 0/1 Knapsack Problem 0/1 Knapsack Problem (fixed tuple) using (fixed tuple) using BACKTRACKING BACKTRACKING Submitted to: Submitted to: Submitted by: Submitted by: Mrs. Deepti Shrimali Krati Mrs. Deepti Shrimali Krati Katyal Katyal

Knapsack problem using fixed tuple

Embed Size (px)

Citation preview

Page 1: Knapsack problem using fixed tuple

LOGO11

0/1 Knapsack Problem0/1 Knapsack Problem(fixed tuple) using (fixed tuple) using

BACKTRACKINGBACKTRACKING

Submitted to: Submitted by:Submitted to: Submitted by: Mrs. Deepti Shrimali Krati KatyalMrs. Deepti Shrimali Krati Katyal MCA 3rd SemMCA 3rd Sem

Page 2: Knapsack problem using fixed tuple

Topics Covered

• Introduction• Difference between Backtracking and Branch

& Bound• Advantages & Disadvantages • Application• Knapsack Problem• Application• Advantages & Disadvantages • Problem• Reference

Page 3: Knapsack problem using fixed tuple

IntroductionIntroduction

In this seminar we will learn about an optimization technique which is known as backtracking and solve the 0/1 knapsack problem using fixed tuple.

Backtracking is a recursive method for building up feasible solutions one at a time.

It provides a simple recursive method of generating all possible n-tuples. After each n-tuple is generated, it is checked for feasibility. If feasible, the solution incurred is compared to the current optimal solution

Page 4: Knapsack problem using fixed tuple

Difference Between Backtracking & Difference Between Backtracking & Branch and BoundBranch and Bound

BACKTRACKING BRANCH & BOUNDIt is used to find all possible solutions available to the problem.

It is used to solve optimization problem.

It traverse tree by DFS (Depth First Search).

It may traverse the tree in any manner, DFS or BFS.

It realizes that it has made a bad choice & undoes the last choice by backing up.

It realizes that it already has a better optimal solution that the pre-solution leads to so it abandons that pre-solution.

It search the state space tree until it found a solution.

It completely searches the state space tree to get optimal solution.

It involves feasibility function

It involves bounding function

Page 5: Knapsack problem using fixed tuple

Advantages:

1) Simple to implement.2) State changes are stored in stack, meaning we do not need to concern ourselves about them.3) Intuitive approach of trial and error.4) Code size is usually small.

Advantages & Disadvantages of Backtracking

Page 6: Knapsack problem using fixed tuple

Disadvantages:

1) Multiple function calls are expensive.2) Inefficient when there is lots of branching from one state.3) Requires large amount of space as the each function state needs to be stored on system stack.   

Page 7: Knapsack problem using fixed tuple

ApplicationApplication

This approach is used for a number of problems like:•N Queen Problem •Sorting•Sum Of Subset Problem•0/1 Knapsack Problem•Solving a Maze•Coloring a Map•Solving a Puzzel

Page 8: Knapsack problem using fixed tuple

Knapsack ProblemKnapsack ProblemA knapsack problem consist of profit vector P = (p1,p2,p3,….,pn), a weight vector W = (w1,w2,w3,….wn) a capacity C of the Knapsack. Problem: How to pack the knapsack to achieve maximum total value of packed items?Problem, in other words, is to find 

Ti

iTi

i Wwb subject to max

Page 9: Knapsack problem using fixed tuple

• This problem is called a “0-1” problem, because each item must be entirely accepted or rejected.

• Since there are n items, there are 2n possible combinations of items.

• We go through all combinations and find the one with maximum value and with total weight less or equal to W.

• Running time will be O(2n).• This problem is sove by state space diagram.

Page 10: Knapsack problem using fixed tuple

State space tree:Left child is always xi= 1 in our formulation Right child is always xi= 0.

Page 11: Knapsack problem using fixed tuple

• Cryptography• Applied Mathematics• Complexity Theory• Computer science

Application of Knapsack ProblemApplication of Knapsack Problem

Page 12: Knapsack problem using fixed tuple

Advantage: • Will find an optimal solution if an optimal solution exists.  Disadvantage: • Computationally very demanding: O ( n · 2 n ). • Very memory intensive. Number of nodes and links both grow with 2 n, node label grows with n. 

Page 13: Knapsack problem using fixed tuple

Q1: Q1: In this problem n=4, profit P = (2,1,4,3) , weight of knapsack W = (5,3,7,6) and capacity of knapsack is C=11.SOL: Search tree of fixed length tuple approach is:

ProblemsProblems

The solution state are 17 and 19 representing the solution (1,0,0,1) and (0,1,1,0) respectively with the same profit 5

Page 14: Knapsack problem using fixed tuple

Search tree of variable length tuple approach is:

The solution state are 8 and 9 representing the solution (1,4) and (2,3) respectively with the same profit 5.

Page 15: Knapsack problem using fixed tuple

Q2: Q2: In this problem n=4, profit P = (3,5,6,10) , weight of knapsack W = (2,3,4,5) and capacity of knapsack is C=8. 

Practice QuestionPractice Question

Page 16: Knapsack problem using fixed tuple

ReferenceReference

• www.google.com• www.encyclopedia.com• www.wikipedia.com• Design Method and Analysis of Algorithm By S.K

Basu.

Page 17: Knapsack problem using fixed tuple

Thank You

MLSU UNIVERSITY