Professional Documents
Culture Documents
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} :
(adding B → {A, B, E} )
(adding C → {A, C, E} )
(adding D → {A, D, E} )
(removing A → {E} )
(removing E → {A} )
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)