Knapsack problem using fixed tuple

Post on 15-Feb-2017

619 views 4 download

transcript

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

Topics Covered

• Introduction• Difference between Backtracking and Branch

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

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

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

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

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.   

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

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

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

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

• Cryptography• Applied Mathematics• Complexity Theory• Computer science

Application of Knapsack ProblemApplication of Knapsack Problem

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. 

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

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.

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

ReferenceReference

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

Basu.

Thank You

MLSU UNIVERSITY