Knapsack Problem’s Algorithm-Advance Analysis Design-Lecture Slides, Slides of Design and Analysis of Algorithms

This course object is to design and analysis of modern algorithms, different variants, accuracy, efficiency, comparing efficiencies, advance designing techniques. In this course algorithm will be analyse using real world examples. This lecture includes: Knapsack, Problem, Algorithm, Dynamic, Programming, Optimal, Weight, Triangulation, Generalization, Variations, Dynamic

Typology: Slides

2011/2012

Uploaded on 08/06/2012

parnavi
parnavi 🇮🇳

4.2

(15)

119 documents

1 / 38

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Dr Nazir A. Zafar Advanced Algorithms Analysis and Design
Lecture No. 20
0-1 Knapsack Problem’s Algorithm
(using Dynamic Programming)
and
Optimal Weight Triangulation
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26

Partial preview of the text

Download Knapsack Problem’s Algorithm-Advance Analysis Design-Lecture Slides and more Slides Design and Analysis of Algorithms in PDF only on Docsity!

Lecture No. 20

0-1 Knapsack Problem’s Algorithm

(using Dynamic Programming)

and

Optimal Weight Triangulation

  • 0-1 knapsack problem
    • Algorithm– Generalizations and variations of the Problem
      • Optimal Weight Triangulation
        • Definitions– Problem Analysis– Dynamic Solution– Algorithm using Dynamic Programming– Time Complexity
          • Conclusion

Today Covered

-^

V[i, j] = max(V[i-1, j], v

  • V[i-1, j – wi

]);i

-^

i = 4

V[4, 10] = max(70, 50 + 40) = 90;

Keep(4, 10) = 1

-^

i = 3

V[3, 10 - 3] = V[3, 7] = max(40, 30) = 40 Keep(3, 7) = 0

-^

i = 2

V[2, 7] = max(10, 40) = 40

Keep(2, 7) = 1

-^

i = 1

V[1, 7-4] = V[1, 3] = 0

Keep(1, 3) = 0

Constructing Optimal Solution

KnapSack (v, w, n, W)for (i = 1 to n), V[i, 0] = 0;for (j = 0 to W), V[0, j] = 0;for (i = 1 to n)

for (j = 1 to W)

if (w(i)

j) V[i, j] = max(V[i-1, j], v

  • V[i-1, j – wi^

]);i

else

V[i, j] = V[i-1, j];

Return V[n, W]Time Complexity O(n.W)

Algorithm : Dynamic Programming

KnapSack(v, w, n, W)for (w = 0 to W), V[0, w] = 0; for (i = 1 to n), V[i, 0] = 0;for (i = 1 to n)

for (w = 1 to W)

if ((w(i)

w) and (v

  • V[i-1,w – wi^

] > V[i-1,w]))i

V[i, w] = (v

  • V[i-1,w – wi^

];i

keep[i, w] = 1;

else

V[i, w] = V[i-1,w];keep[i, w] = 0;

K = W;

for (i = n down to 1)

if keep[i, K] = = 1

output iK = K – w

i

Return V[n, W]

Complete: Dynamic Programming Algorithm

  1. Generalization of Knapsack Problems -^

Common to all versions are a set of n items, with eachitem 1

j^

≤^

n having an associated profit p

and weight wj^

.j

-^

The objective is to pick some of the items, with maximaltotal profit, obeying that maximum total weight limit W.

-^

Generally, coefficients are scaled to become integers, andthey are almost always assumed to be positive.

-^

The knapsack problem in its most basic form:maximize

subject to

xi

{0, 1},

1

i^

n

n  i

i xi p 1

W

x

w

n i

i i^



1

  1. Generalizations (x

i^

{0, 1})

  1. Generalization of Knapsack Problems -^

If each item can be chosen multiple times, we get thebounded knapsack problem.

-^

Suppose, weight of each item is at least 1 unit, thenwe can never choose an item more than W times.

-^

This is another variation in the basic form

-^

Now the problem will becomemaximize

subject to

x^ i

{0, 1,.. ., W},

1

i^

n

n  i

i xi p 1

W

x

w

n i

i i^



1

  1. Generalizations (more than one objects)
  1. Generalization of Knapsack Problems -^

If the items are subdivided into k classes denoted N

i

-^

And exactly one item must be taken from each class

-^

We get the multiple choice knapsack problem

-^

In this case our optimized mathematical model ismaximize

subject to

1

i^

≤^

k

xij

{0, 1},

1

i^

≤^

k, j

N

i

 

k i

ij ij

N j

x

p

i

1

1

x

ere wh

Ni j

ij

1

 

^

W

x w

n i

ij ij

N j^

i

  1. Generalizations (K Classes)
  1. Generalization of Knapsack Problems -^

If in the multiple knapsack problem, the weightsare not the same in every container

-^

We are allowed to choose each item multipletimes, we get multiple constrained knapsackproblemmaximize

subject to

n  j

j xj p 1

m i 1

1

 



i

n j

j ij^

W

x w

  1. Item’s Different Weight in Different Knapsack)

Z

x

j

j^

0,

x

Optimal Weight Triangulation

•^

Optimal triangulation problem is very similar tomatrix chain multiplication

-^

It is an excellent approach to make one to onecorresponding between two problems and

-^

Then solving one problem based on the approachalready used in the solution of the other problem

-^

This is what we are going to do in solving anoptimal solution of the triangulation problem whichis very popular in computational geometry

-^

Applications of this problem can be observed inmany other areas where division of structures isrequired before performing computation over it.

Similarity: Optimal Polygon Triangulation, other Problem

Polygon

A set of finite piecewise-linear, closed curve in a plane iscalled a polygon Sides

The pieces of the polygon are called its sides Vertex

A point joining two consecutive sides is called a vertex Interior

The set of points in the plane enclosed by a simplepolygon forms interior of the polygon Boundary

The set of point on the polygon forms its boundary Exterior

The set of points surrounding the polygon form its exterior

Basic Concepts

Simple Polygon Convex Polygons

Simple Polygon

Polygon

Polygons

-^

For a convex polygon, it is assumed that its vertices arelabeled in counterclockwise order

-^

We assume that indexing is done modulo

n

, so

and the above polygon P has

n

number of vertices

.

,..., , ,^

1

2 1 0

vn

v v v

P

.

0

vn

v

v

= v

6

v

v

v

v

v

,^

5

2 1 0

v

v

v

v

P

Labeling Convex Polygons