n - Queen's problem�
Amity School of Engineering & Technology
Amity School of Engineering & Technology
Algorithm N Queen (k, n)
// Using backtracking, this procedure prints all possible placements of
// n- queens on the n*n chess board so that they are non-attacking.
{
for i = 1 to n do
{
if (Place (k, i))then
{
X[k] = i;
if (k = =n) then write (x[1: n ]) ;
else N Queens (k+1, n); } } }
Amity School of Engineering & Technology
Algorithm Place(k,i)
{
for(j=1 to k-1 do
if((x[ j]==i) || (ABS(x[ j]-i)==ABS(j-k)))
then return false;
return true;
}
Amity School of Engineering & Technology
4 - Queen's problem�
Amity School of Engineering & Technology
Amity School of Engineering & Technology
Thus, the solution for 8 -queen problem is (4, 6, 8, 2, 7, 1, 3, 5).
Amity School of Engineering & Technology