You are on page 1of 2

Problem Set 3

Due: Monday, Oct 04, 2021, 5:10pm


Princeton Ferro (pcf252@nyu.edu)

object A B C D E
value 10 8 7 6 4
weight 8 4 3 3 1

1) Suppose at some iteration of simple hill climbing the current state is {A, E} . What is the
best neighbor of the state {A, E} ? What happens on the next iteration?

At state S = {A, E} :

Error(S) = max(weight(S) − 10, 0) + max(20 − value(S), 0)

Error(S) = max(9 − 10, 0) + max(20 − 14, 0)

Error(S) = max(−1, 0) + max(6, 0) = 6


Now we look at neighboring states:

(adding B → {A, B, E} )

Error(S) = max((8 + 4 + 1) − 10, 0) + max(20 − (10 + 8 + 4), 0) = 3 + 0 = 3

(adding C → {A, C, E} )

Error(S) = max((8 + 3 + 1) − 10, 0) + max(20 − (10 + 7 + 4), 0) = 2 + 0 = 2

(adding D → {A, D, E} )

Error(S) = max((8 + 3 + 1) − 10, 0) + max(20 − (10 + 6 + 4), 0) = 2 + 0 = 2

(removing A → {E} )

Error(S) = max(1 − 10, 0) + max(20 − 4, 0) = 0 + 16 = 16

(removing E → {A} )

Error(S) = max(8 − 10, 0) + max(20 − 10, 0) = 0 + 10 = 10

(replacing A with B → {B, E} )

Error(S) = max((4 + 1) − 10, 0) + max(20 − (8 + 4), 0) = 0 + 8 = 8


(replacing A with C → {C, E} )

Error(S) = max((3 + 1) − 10, 0) + max(20 − (7 + 4), 0) = 0 + 9 = 9

(replacing A with D → {D, E} )

Error(S) = max((3 + 1) − 10, 0) + max(20 − (6 + 4), 0) = 0 + 10 = 10

(replacing E with B → {A, B} )

Error(S) = max((8 + 4) − 10, 0) + max(20 − (10 + 8), 0) = 2 + 2 = 4

(replacing E with C → {A, C} )

Error(S) = max((8 + 3) − 10, 0) + max(20 − (10 + 7), 0) = 1 + 3 = 4

(replacing E with D → {A, D} )

Error(S) = max((8 + 3) − 10, 0) + max(20 − (10 + 6), 0) = 1 + 4 = 5

On the next iteration, we add C to the set, since it (along with adding D ) results in the lowest
error of 2, but gives us a higher value (21 versus 20).

2) Consider now the general case where there are N objects. What is the size of the state
space? What is maximal number of neighbors of any state?

The size of the state space for N objects is 2 N . (For each item, it can either be in the knapsack
or not.)

The maximal number of neighbors for a given state S depends on A, the number of ways to
add an item to the knapsack, R the number of ways to remove an item, and E the number of
ways to exchange an item for another item, such that the answer is A + R + E . If there are K
items in the knapsack and N total items, then:

A=N −K

R=K

E = K(N − K)

Therefore, the maximal number of neighbors is N + KN − K 2

You might also like