3. 3
N-queens Problem
• Define the problem
• If two queens are placed at positions (i, j) and (k, l)
• Then, they are on the same diagonal iff i – j = k – l or i+j = k+l
• Here, first equation implies that j – l = i – k
• The second equation implies that j – l = k - i
• Combining the two, we get |j – l |= |i – k|
6. Subset Sum Problem
• Problem definition: Find a subset of a given set A = {a1, . . . , an} of n
positive integers whose sum is equal to a given positive integer d.
• For example, for A = {1, 2, 5, 6, 8} and d = 9, there are two solutions:
{1, 2, 6} and {1, 8}.
• Of course, some instances of this problem may have no solutions.
• It is convenient to sort the set’s elements in increasing order. So, we
will assume that
a1< a2< . . . < an.
• The state-space tree can be constructed as a binary tree like that in
Figure shown below for the instance A = {3, 5, 6, 7} and d = 15.