You are on page 1of 33

N QUEEN PROBLEM 1NH18MCA37

CHAPTER 1
INTRODUCTION
1.1 GENERAL INTRODUCTION
Chess composer Max Bezzel published the eight queens puzzle in 1848. Franz Nauck
published the first solutions in 1850.Nauck also extended the puzzle to the n queens problem,
with n queens on a chessboard of n × n squares.

Since then, many mathematicians, including Carl Friedrich Gauss, have worked on both the
eight queens puzzle and its generalized n-queens version. In 1874, S. Gunther proposed a
method using determinants to find solutions.J.W.L. Glaisher refined Gunther's approach.

In 1972, Edsger Dijkstra used this problem to illustrate the power of what he called
structured programming. He published a highly detailed description of a depth-first
backtracking algorithm.

The classic example of the use of backtracking is the eight queens puzzle, that asks for all
arrangements of eight chessqueens on a standard chessboard so that no queen attacks any
other. In the common backtracking approach, the partial candidates are arrangements of k
queens in the first k rows of the board, all in different rows and columns. Any partial solution
that contains two mutually attacking queens can be abandoned.

The problem can be quite computationally expensive, as there are 4,426,165,368 (i.e., 64C8)
possible arrangements of eight queens on an 8×8 board, but only 92 solutions. It is possible
to use shortcuts that reduce computational requirements or rules of thumb that avoids brute-
force computational techniques. For example, by applying a simple rule that constrains each
queen to a single column (or row), though still considered brute force, it is possible to reduce
the number of possibilities to 16,777,216 (that is, 88 ) possible combinations. Generating
permutations further reduces the possibilities to just 40,320 (that is, 8!), which are then
checked for diagonal attacks.

Martin Richards published a program to count solutions to the n- queens problem using
bitwise operations.[3] . However, this solution has already been published by Zongyan Qiu
Department of MCA, NHCE 2018-2019 1
N QUEEN PROBLEM 1NH18MCA37

1.2 PROBLEM STATEMENT


o The N Queen is the problem of placing N chess queens on an N×N chessboard
so that no two queens attack each other.
o That means , no two queens are placed in same row or in same column or
diagonal to each other.
o Higher dimensions
 Find the number of non-attacking queens that can be placed in a d-
dimensional chess space of size n. More than n queens can be placed
in some higher dimensions (the smallest example is four non-attacking
queens in a 3×3×3 chess space), and it is in fact known that for any k,
there are higher dimensions where nk queens do not suffice to attack
all spaces.[5]
o Using pieces other than queens
 On an 8×8 board one can place 32 knights, or 14 bishops, 16 kings or
eight rooks, so that no two pieces attack each other. Fairy chess
pieces have also been substituted for queens. In the case of knights, an
easy solution is to place one on each square of a given color, since
they move only to the opposite color. The solution is also easy for
rooks and kings. Eight rooks can be placed along a long diagonal
(amongst thousands of other solutions), and 16 kings are placed on the
board by dividing it into 2 by 2 squares and placing the kings at
equivalent points on each square.

o Chess variations
 Related problems can be asked for chess variations such as shogi. For
instance, the n+k dragon kings problem asks to place k shogi
paws and n+k mutually nonattacking dragon kings on an n×n shogi
board.[6]
o Permutation matrix
 In mathematics, a permutation matrix can be regarded geometrically as
a set of n points lying on the squares of a n×n chessboard, such that
each row or column contains only one point. Thus, an order-
n permutation matrix is a solution to an n-rooks puzzle.
Department of MCA, NHCE 2018-2019 2
N QUEEN PROBLEM 1NH18MCA37
o Nonstandard boards
 Pólya studied the n queens problem on a toroidal ("donut-shaped")
board and showed that there is a solution on an n×n board if and only
if n is not divisible by 2 or 3.[7] In 2009 Pearson and Pearson
algorithmically populated three-dimensional boards (n×n×n)
with n2 queens, and proposed that multiples of these can yield
solutions for a four-dimensional version of the puzzle.[8][better source needed]
o Domination
 Given an n×n board, the domination number is the minimum number
of queens (or other pieces) needed to attack or occupy every square.
For n = 8 the queen's domination number is 5.
o Queens and other pieces
 Variants include mixing queens with other pieces; for example,
placing m queens and m knights on an n×n board so that no piece
attacks another[9] or placing queens and pawns so that no two queens
attack each other.[10][better source needed]
o Magic squares
 In 1992, Demirörs, Rafraf, and Tanik published a method for
converting some magic squares into n-queens solutions, and vice
versa.[11]
o Latin squares
 In an n×n matrix, place each digit 1 through n in n locations in the
matrix so that no two instances of the same digit are in the same row
or column.
o Exact cover
 Consider a matrix with one primary column for each of the n ranks of
the board, one primary column for each of the n files, and one
secondary column for each of the 4n − 6 nontrivial diagonals of the
board. The matrix has n2 rows: one for each possible queen placement,
and each row has a 1 in the columns corresponding to that square's
rank, file, and diagonals and a 0 in all the other columns. Then
the n queens problem is equivalent to choosing a subset of the rows of

Department of MCA, NHCE 2018-2019 3


N QUEEN PROBLEM 1NH18MCA37
this matrix such that every primary column has a 1 in precisely one of
the chosen rows and every secondary column has a 1 in at most one of
the chosen rows; this is an example of a generalized exact
cover problem, of which sudoku is another example.
o n-Queens Completion
 A 2017 paper[12] investigated the problem "Given an n×n chessboard
on which some queens are already placed, can you place a queen in
every remaining row so that no two queens attack each other?" and
several related problems. The authors asserted that these problems
are NP-complete[13], and #P-complete.

1.3 EXISTING SYSTEM

 A new approach to solve n-queens problem based on series

The n-queens problem is proposed for the first time in 1850 by Carl Gauss. It is to
determine a placement of n queens on an n × n chessboard, such that no two queens can
attack each other [3]. This problem falls in a special class of problems well
known as NP hard, whose solution cannot be found

out in polynomial time. Let’s consider the 8-queen problem, which is computationally
very expensive since the total number of possible arrangements queen is 64! / (56! x 8!)
~ 4.4 x 1 and the total number of possible solutions are 92 [1]. But there exists only 12
unique solutions. There are some solutions that are to be the same and can be obtained one
from the other by taking rotations or symmetry. The n-queen problem follows the same rules
as in 8-queen problem with N queens and an n x n chessboard. Current knowledge of
total number of solutions of n-queens problem can be viewed from the Table 1.

Department of MCA, NHCE 2018-2019 4


N QUEEN PROBLEM 1NH18MCA37

 A Novel Quantum N-Queens Solver Algorithm and its Simulation and Application to
Satellite Communication Using IBM Quantum Experience

NP complete problems encompass all decision problems in class NP that can be


verified in polynomial time [1, 2]. However, the time taken to obtain a solution for an NP
complete problem is not polynomial. Some common examples of NP complete problems
include the traveling salesman problem [3], the subset sum problem [4], the Hamiltonian
cycle problem [5], the knapsack problem [6] and satisfiability problem [8, 9] to name a few.
The N -Queens Problem is an NP complete problem [10, 11]. It states that N queens
must be placed on an N × N chessboard such that no two queens can attack each other
[10, 12]. The queens follow the moves that a classical chess queen follows, i.e. horizontal,
vertical and diagonal jumps across any number of squares as long as the queen is
unobstructed by the presence of another queen. The generalized N -Queens Problem

Department of MCA, NHCE 2018-2019 5


N QUEEN PROBLEM 1NH18MCA37
[12] has already been attempted over the years [13]. It has been approached using multiple
classical computational methods [14]. Some of these include the brute force algorithm [15],
different variants of the backtracking algorithm [16, 17] and the greedy technique [18].
The brute force algorithm has the highest growth rate (with N ) of the order O(N ). The
backtracking algorithm isslightly better than the former with a time complexity of the order
O(N !). Other variants of the backtracking method such as the optimized backtracking and
novice backtracking algorithms have an exponential time com- plexity [10, 19]. The
systematic and greedy search methods have a time complexity of the order O(N ) to O(N ).
These algorithms, although solvable in polynomial time

1.4 OBJECTIVE OF THE WORK


Backtracking is a prime algorithmic technique that uses depth first search to explore
the solution space which is most naturally formulated in terms of recursive programs.
Suppose that we are given an n × n chessboard, where n is a positive integer. A queen can
attack in Y.Abhigna Reddy et al, Int. J. Comp. Tech. Appl., Vol 2 (6), 1737-1741 IJCTA |
NOV-DEC 2011 Available online@www.ijcta.com 1737 ISSN:2229-6093 horizontal,
vertical, and the two diagonal directions. The nqueens problem asks to find a configuration of
n queens on an n × n chessboard such that no two attack one another. There are no solutions
to this problem for n = 2 or 3, but it can be shown that a solution exists for each n 4. The
main idea is to proceed row by row. Suppose that the values of row[k] for all 0 k < I, are
selected then the value for row[i] that is consistent with the requirements is selected that have
outlined above. If that is not possible, then backtracking is done and different value for
row[i-1] is choosen.

1.5 SOLUTION INVENTOR


 The first solution for 8 queens were provided by Franz Nauck in 1850. Nauck also
extended the puzzle to n-queens problem (on an n n board—a chessboard of arbitrary
size).
 In 1874, S. Günther proposed a method of finding solutions by using determinants,
and J.W.L. Glaisher refined this approach.
 Edsger Dijkstra used this problem in 1972 to illustrate the power of what he called
structured programming.

Department of MCA, NHCE 2018-2019 6


N QUEEN PROBLEM 1NH18MCA37
 He published a highly detailed description of the development of a depth-first
backtracking algorithm

1.6 PROPOSED SYSTEM WITH METHODOLOGY


Backtracking is a general algorithm for finding all (or some) solutions to some computational
problems, notably constraint satisfaction problems, that incrementally builds candidates to
the solutions, and abandons each partial candidate ("backtracks") as soon as it determines
that the candidate cannot possibly be completed to a valid solution.

The backtracking algorithm enumerates a set of partial candidates that, in principle, could be
completed in various ways to give all the possible solutions to the given problem. The
completion is done incrementally, by a sequence of candidate extension steps.

Conceptually, the partial candidates are represented as the nodes of a tree structure, the
potential search tree. Each partial candidate is the parent of the candidates that differ from it
by a single extension step; the leaves of the tree are the partial candidates that cannot be
extended any further.

The backtracking algorithm traverses this search tree recursively, from the root down, in
depth-first order. At each node c, the algorithm checks whether c can be completed to a valid
solution. If it cannot, the whole sub-tree rooted at c is skipped (pruned). Otherwise, the
algorithm (1) checks whether c itself is a valid solution, and if so reports it to the user; and
(2) recursively enumerates all sub-trees of c. The two tests and the children of each node are
defined by user-given procedures.

Therefore, the actual search tree that is traversed by the algorithm is only a part of the
potential tree. The total cost of the algorithm is the number of nodes of the actual tree times
the cost of obtaining and processing each node. This fact should be considered when
choosing the potential search tree and implementing the pruning test.

Department of MCA, NHCE 2018-2019 7


N QUEEN PROBLEM 1NH18MCA37

1.7 FEASIBILITY STUDY


The N Queen is the problem of placing N chess queens on an N×N chessboard so that no two
queens attack each other. For example, following is a solution for 4 Queen problem.

The N Queen is the problem of placing N chess queens on an N×N chessboard so that no two
queens attack each other. For example, following are two solutions for 4 Queen problem.

Department of MCA, NHCE 2018-2019 8


N QUEEN PROBLEM 1NH18MCA37

CHAPTER 2
REVIEW OF LITERATURE

2.1 REVIEW SUMMARY


Algorithm strategies are the approach to solve computational problems. It may
combine many approaches together to solve a problem. We follow different strategies based
on the problem. Algorithm can be implemented either iteration or recursive in structure.
Dynamic Programming, Branch-and-Bound, Bruit Force, Backtracking, Greedy, Recursive,
Heuristic, etc. are some the important algorithm strategies.

Backtracking Strategy
 Backtracking algorithms are applicable for NP-Complete problems. Priestley and
Ward [1] presented the details about the backtracking and its applications. They have
clearly explained the preliminaries of the algorithm and gave a clear picture of the 8-
queen puzzle. The solution for the problem could be achieved through tree structure
representation of the choices. The proposed procedure could reduce the number of
test cases to a sum of 15,720. The time complexity was reduced by reducing test
cases. Pre –analysis was used to reduce the test cases. They used bush pruning
technique for further improvement. Finally hybrid approach of pre-analysis and bust
pruning gave better result.
 Ginsberg [2] introduced dynamic backtracking algorithm but that does not solve
constraint satisfaction problem dynamically. Gerald and Thomas [3] proposed some
alteration to support a dynamic constraint satisfaction. But this method suffers due to
heavy time complexities.

 Lijo V. P. et al, / (IJCSIT) International Journal of Computer Science and Information


Technologies, Vol. 6 (4) , 2015, 3844-3848 www.ijcsit.com 3844 M M Noori and B
T Razaie [4] expose and implemented an improved backtracking algorithm for
identifying t-designs which is proposed by J. Combin. Des. According to Noori, the
algorithm uses a systematic method to derive new useful equations from the initial
equations which are useful in speeding up the classical backtracking algorithm. The

Department of MCA, NHCE 2018-2019 9


N QUEEN PROBLEM 1NH18MCA37
reader can refer [5] to get brief description of backtracking algorithms and their
applications.
 Bessière et al. [6] proposed a asynchronous backtracking algorithm for distributed
constraint satisfaction problems. This is based on distributed backtracking with
storage of the previous results to reduce the total number of trials. M.A. Gutierrez-
Naranjo et al. presented the N-queen problem in conjunctive normal form. They
described the queen problem as a SAT problem by assuming the each Psystems send
truth values as Yes or No. Pioneer solution have presented to the N-queens puzzle
based on Membrane Computing [7]. Algorithm 1 gives an insight on back tracking
algorithm which is based on depth-first recursive search.
 Algorithm 1: Backtracking general algorithm [8]
Checks whether solution has been found
If found solution,
return it
else
for each choice that can be made
take that choice
Recurrence
If recursion
gives a positive result,
return it
If no
choices remain,
return failure
Computational Complexities
 Vipin Kumar [9] gives a detailed survey on constraint satisfaction problem
algorithms. Some of them solve the problems by constraint propagation and rest of
them are solving problem by direct approach though backtracking. A survey on
complexity analysis of space-bounded algorithms for constraint satisfaction problems
is proposed by J Roberto et al.[10]. They cover unrestricted, size-bounded, relevance-
bounded learning and their complexities.

Department of MCA, NHCE 2018-2019 10


N QUEEN PROBLEM 1NH18MCA37
 J. H Patterson [11] presented the computational results of the minimized and
maximized problems in a general way. They have considered both mainframe and
personal computer experiences. Optimal solution for small problems is very easily
attained in PCs but for large problems quite difficult to achieve result in PCs.

 John Gaschnig [12] proposed a fast backtracking algorithm which is reduced its
computational complexities by eliminating redundant tests. He tried to exploit space-
time trade off maximum in his algorithm. According to John, it is hard to eliminate all
redundant tests in computationally efficient manner. But it is possible to eliminate all
redundant test cases with heuristic approach. In [13], Jordan Bell and Brett Stevens
discussed the computational approaches of n queen’s problem. In this survey paper
they have given concentration for different approaches and results for the same
problem.

 Erbak and Tanik given a detailed study of algorithms used for n-queens problem in
[14]. They grouped the total algorithms in different categories based on the outcome
of the algorithms. As per their view they are three types of algorithms based on their
outcomes. Some of them generate all solutions and others are produce fundamental or
subset of total number of solutions. Brute-force trial and error and backtracking are
examples of algorithms which generate complete solutions. The algorithms based on
group properties of results, symmetric elimination and test-based produce only basic
solutions.

Department of MCA, NHCE 2018-2019 11


N QUEEN PROBLEM 1NH18MCA37

CHAPTER 3

SYSTEM CONFIGURATION
It does not need any additional hardware and software to operate the program, the following
requirements should strongly maintained

3.1 SOFTWARE CONFIGURATION


1. Operating system: Windows 98 and higher.

2. Front end: Turbo c ++ needs to be installed.

3. Language: procedural c language.

3.2 HARDWARE CONFIGURATION


1. Pentium II and Higher

2. 512 and Higher Ram

3. 800Mhz processor and higher

4. 20 MB of memory space

CHAPTER 4
MODULE DESCRIPTION
4.1 MODULE 1
N QUEEN
Input:
NxN Matrix
Process:
Using Backtracking Algorithm searching the location of queen
Output:
Displaying the possibility queen in the matrix

Department of MCA, NHCE 2018-2019 12


N QUEEN PROBLEM 1NH18MCA37

CHAPTER 5
SYSTEM DESIGN
5.1 DFD / UML Diagrams

Context Flow Diagram:

NxN Matrix

N QUEEN

Display possible Way of


queen
USER

DFD
The Data Flow Diagram shows the flow of data through a system. It views the system
as a function that transform the input to the desired output, it contains the number of
symbols that is use to represent the system. DFD describes about the modules and
their attributes in such a manner that each and every one can understand it easily.

Department of MCA, NHCE 2018-2019 13


N QUEEN PROBLEM 1NH18MCA37

DFD FOR NQUEEN PROBLEM:

Dot_Table

Retrive
RetriveNodes
Nodes

EnterNodes
Enter Nodes Update
UpdateNodes
Nodes

USER N QUEEN Dot_Table

Retrive Nodes
Display Display
User

DISPLAY

Update Nodes
Department of MCA, NHCE 2018-2019 14
N QUEEN PROBLEM 1NH18MCA37

CHAPTER 6
SYSTEM IMPLEMENTATION

6.1 IMPLEMENTATION
N Queen problem implementation generally consists of placing queens in a particular
row and column and continuing to place the next queen in next row and column without
violating the same row, same column and same diagonal constraint. The initial permutation
consists of placing a queen in first row. There are n columns in the first row offering a
possible of n combinations in first row. For every column in the first row there are n columns
that are available for placing a queen in the second row raising the number of combinations
in the second row to n*n combinations. At nth row there are nn combinations. This can be
reduced to a minimum by using the following constraints No two queens can be placed in the
same row No two queens can be placed in the same column No two queens can be placed in
the same diagonal The general algorithm is to place the queen and move till the nth row and
backtrack. This can be optimized by checking for the constraints when a column is assigned
for every row. So while traversing the recursion tree the constraints are applied at that level
before proceeding to the children. When the constraints are put we can decide whether the
current node from root accepts or violates all the constraints. If the node is accepted the
control shifts to finding a suitable column for the next row. When there is violation in
constraints the node at that level can never lead to any valid solutions and so the tree is
pruned at that node by returning to the parent to consider the next column assignment. This
leads to reduction in the computing needed.

6.2ALGORITHM
Algorithm:
1. Place the queens column wise, start from the left most column
2. If all queens are placed.
1. return true and print the solution matrix.
3. Else
1. Try all the rows in the current column.

Department of MCA, NHCE 2018-2019 15


N QUEEN PROBLEM 1NH18MCA37
2. Check if queen can be placed here safely if yes mark the current cell in solution
matrix as 1 and try to solve the rest of the prob- lem recursively.
3. If placing the queen in above step leads to the solution return true.
4. If placing the queen in above step does not lead to the solution , BACKTRACK,
mark the current cell in solution matrix as 0 and return false.
4. If all the rows are tried and nothing worked, return false and print NO SOLUTION.

6.3 CODING

#include<stdio.h>
#include<conio.h>
#include<math.h>

char a[10][10];
int n;
//print the new position of queen
void printqueen()
{
int i, j;
printf("\n");

for (i = 0; i < n; i++)


{
for (j = 0; j < n; j++)
printf("%c\t", a[i][j]);
printf("\n\n");
}
}
//This function is to get previous queen
int getprequeen(int row)
{
int i;

Department of MCA, NHCE 2018-2019 16


N QUEEN PROBLEM 1NH18MCA37
for (i = 0; i < n; i++)
if (a[row][i] == 'Q')
{
return (i);

}
/*checking the posiblity of the queen
can be placeing at the current position*/
int posiblity(int row, int col)
{
int i, tc;
for (i = 0; i < n; i++) {
tc = getprequeen(i);
//check in the all direction and in diagnal
if (col == tc || abs(row - i) == abs(col - tc))
return 0;
//if equal then no queen can place at this position
}
return 1;
}

void nqueen(int row)


{
int i, j;

if (row < n)
{
for (i = 0; i < n; i++)
{
if (posiblity(row, i))
{
Department of MCA, NHCE 2018-2019 17
N QUEEN PROBLEM 1NH18MCA37
a[row][i] = 'Q';
//check next posiable queen otherwise backtraking
nqueen(row + 1);

a[row][i] = '.';
}
}
}
else
{

//printing the all queen in matrix


printf("\nThe solution is:- ");
printqueen();
getch();
}
}
//this is the main function
int main() {
int i, j,m;
// clrscr();
printf("\nEnter the no. of queens:- ");
scanf("%d%d", &n,&m);

for (i = 0; i < n; i++)


for (j = 0; j < n; j++)
a[i][j] = '.';

//checking for suuare matrix

if(n==m)
{
nqueen(0);
Department of MCA, NHCE 2018-2019 18
N QUEEN PROBLEM 1NH18MCA37
}
else
{
printf("there should be square matrix");
}

getch();
return (0);

6.4 APPLICATION

Constraint Satisfaction Problems - CSP


• The state is defined by n variables Vi (i=1,…,n)
• The possible values for each variable are from a domain Di
• There are a set of constraints between the variable values
• The goal test checks that all variables have been assigned and no constraints are violated.
• We will restrict ourselves to examples with discrete, finite sets of values for each variable.
• Place 4 queens on a 4 by 4 chess board such that no queen can take another
• Assume one queen in each column. Which row does each one go in?
• Variables: Qi(i is the column)
• Domains: Di = {1, 2, 3, 4} (the row)
• Constraints – Qi ≠Qj (cannot be in same row) – |Qi - Qj | ≠ |i - j| (or same diagonal)
• Translate each constraint into set of allowable values for its variables E.g., values for (Q1,
Q2) are (1,3) (1,4) (2,4) (3,1) (4,1) (4,2)
• Problem: place n queens in a board n × n so that no queens attack each other in the rows,
columns or diagonals
• 2 ways of solving the problem: incremental and complete
• Possible states (a) and moves (b):

Department of MCA, NHCE 2018-2019 19


N QUEEN PROBLEM 1NH18MCA37

Department of MCA, NHCE 2018-2019 20


N QUEEN PROBLEM 1NH18MCA37

6.4 SCREEN SHOTS

Matrix Not Equal

Matrix Equal

Department of MCA, NHCE 2018-2019 21


N QUEEN PROBLEM 1NH18MCA37

Possible Output 1:

Possible Output 2:

Department of MCA, NHCE 2018-2019 22


N QUEEN PROBLEM 1NH18MCA37

Possible Output 3:

Possible Output 4:

Department of MCA, NHCE 2018-2019 23


N QUEEN PROBLEM 1NH18MCA37

CHAPTER 7
SYSTEM TESTING

Testing is the activity where the errors remaining from all the previous phases must
be detected. Hence, testing performs a very critical role for ensuring quality.
During testing, the software to be tested is executed with a set of test cases, and the
behavior of the system for the test cases is evaluated to determine if the system is performing
as expected. Clearly, the success of testing in revealing errors depends critically on the test
cases.
Testing is the major quality control measure used during the software development its
basic function is to detect errors in the software.
Thus a goal of testing is to uncover requirement, design, and coding errors in the
programs.
Level of testing:
Testing is done different level which includes the following:
1. Unit testing
2. Integration testing
3. System testing
4. Acceptance testing
Unit testing:
It is a starting point of testing; in this module is testing separately and
is performed by the coder himself simultaneously along with the coding of
the module.
Integration testing:
The modules are gradually integrated into subsystem, which are then
integrated to eventually from the entire system. During integration of module
integration testing is performed to detect design errors by focusing on testing
the interconnection between the modules.
System testing:
After the system put together, system testing is performed here the
system is testing against the system requirements.

Department of MCA, NHCE 2018-2019 24


N QUEEN PROBLEM 1NH18MCA37
Acceptance testing:
This testing is performed to demonstrate to the client on the real life
data of the client, the operation of the system

7.2 Test Case


It is input that tests the genuine of the program and successful execution of the test
cases are generated.
Test case ID NQ01
Title NxN MATRIX
Purpose To test whether given input is square matrix
Test data 1. Valid Input.
2. Invalid Input.
Steps 1. Enter NxN matrix
2.Click Enter
Expected output: Invalid

Department of MCA, NHCE 2018-2019 25


N QUEEN PROBLEM 1NH18MCA37
Valid

Department of MCA, NHCE 2018-2019 26


N QUEEN PROBLEM 1NH18MCA37

CHAPTER 8
RESULTS & DISCUSSION
The eight queens puzzle has 92 distinct solutions. If solutions that differ only by the
symmetry operations of rotation and reflection of the board are counted as one, the puzzle
has 12 solutions. These are called fundamental solutions; representatives of each are
shown…below.

Department of MCA, NHCE 2018-2019 27


N QUEEN PROBLEM 1NH18MCA37

A fundamental solution usually has eight variants (including its original form) obtained by
rotating 90, 180, or 270° and then reflecting each of the four rotational variants in a mirror in
a fixed position. However, should a solution be equivalent to its own 90° rotation (as happens
to one solution with five queens on a 5×5 board), that fundamental solution will have only
two variants (itself and its reflection). Should a solution be equivalent to its own 180°
rotation (but not to its 90° rotation), it will have four variants (itself and its reflection, its 90°
rotation and the reflection of that). If n > 1, it is not possible for a solution to be equivalent to
its own reflection because that would require two queens to be facing each other. Of the 12
fundamental solutions to the problem with eight queens on an 8×8 board, exactly one
(solution 12 below) is 10 equal to its own 180° rotation, and none is equal to its 90° rotation;
thus, the number of distinct solutions is 11×8 + 1×4 = 92 (where the 8 is derived from four
90° rotational positions and their reflections, and the 4 is derived from two 180° rotational
positions and their reflections)

8.1 CONCLUSION
Finding all solutions to the eight queens puzzle is a good example of a simple
but nontrivial problem. For this reason, it is often used as an example problem for various
programming techniques, including nontraditional approaches such as constraint
programming, logic programming or genetic algorithms. Most often, it is used as an example
of a problem that can be solved with a recursive algorithm, by phrasing the n queens problem
inductively in terms of adding a single queen to any solution to the problem of placing n−1
queens on an n-by-n chessboard.
Department of MCA, NHCE 2018-2019 28
N QUEEN PROBLEM 1NH18MCA37

In N-Queen, as N value increases the time of processing also takes more time
.This happens when we try to display all the possible solutions.

Of course, we could make it much faster if we wanted to only find one solution
instead of all of them: not more than a few milliseconds for board sizes up to 50

Various techniques like brute force, permutations, greedy methods which can be used
to solve n queens problem but among all backtracking with recursion is very efficient. Since
backtracking with recursion is useful to solve the problem where the iteration is more
prominent in finding the solutions, it is used to solve n queens problem

Graphical simulation of n-queens problem using backtracking with recursion is


successful to the extent of finding and displaying all the distinct solutions to the single digit
values of n,while a constraint(whether to read single digit or double digit from the solution
list to place queen) occurs for double digit values.

The graphical simulation assists learners in understanding the solutions possible for n
queens problem using backtracking. The graphical interface is very efficient and enables the
users to visualize every solution of n queens problem.

8.2 LIMITATIONS
The major advantage of the backtracking algorithm is the abillity to find and count all
the possible solutions rather than just one while offering decent speed. In fact this is
the reason it is so widely used. Also one can easily produce a parallel version of the
backtracking algorithm increasing speed several times just by starting multiple threads
with different starting positions of the first queens.

Department of MCA, NHCE 2018-2019 29


N QUEEN PROBLEM 1NH18MCA37

8.3 FUTURE ENHANCEMENTS


This paper work can be extended by adding a few algorithms like Dynamic Programming,
Greedy, Hill Climbing, Tabu Search, Ant Colony Optimization, Swarm Optimization etc. to
solve N Queens Problem and make a comparative study of these algorithms and thus, making
the whole task more efficient and effective. Also, the Proposed Genetic Algorithm can be
well modified, so that, it can provide solution to higher values of N. Besides these, in the
Proposed Genetic Algorithm, some other selection/crossover/mutation methods can also be
applied and comparative analysis can be made among those methods to check, which method
is better and this also will be an efficient and effective work. Finally, although several
modifications will have to be made, yet this approach can be tried to be applied to solve 3D
Queens Problem also.
Future Enhancements we demonstrate that the efficiency of the traditional backtracking
algorithm may be improved by the use of a hybrid approach taking advantage of sets to
reduce the number of trials and error attempts. Time taken to solve the n-queen problem in
the backtracking is more than that of the Tuned hybrid technique. Space taken to solve the n-
queen problem in the backtracking is more than that of the Tuned hybrid technique.
Complexity Analysis can be improved using different algorithms and that approach will be
applied on the one of the applications of the N-Queen Problem to obtain the fast and better
solution. Complexity Analysis can be based in the time, space, convergence-rate and
conflict-minimization.
The N-queens problem is a classic puzzle problem where n queens are to be placed on nxn
“chessboard” such that no queen can attack any other queen. AT max 4 queen attack on cell,
and minimum 1 (here 1 mean, where queen place) queen in solution, if violet this condition
so that is not solution. For one unique solution we find a pattern, which give us one unique
solution for any “n” value. For future research work related to find another pattern and also
new rule. Suppose our starting solution is different, so our series of natural number is also
different, like is our starting solution is 5x5 chess board is given below

Department of MCA, NHCE 2018-2019 30


N QUEEN PROBLEM 1NH18MCA37

CHAPTER 9

REFERENCES
9.1 TEXT REFERENCE

 E. J. Hoffman et al., "Construction for the Solutions of the m Queens


Problem". Mathematics Magazine, Vol. XX (1969), pp. 66–72. [1]
 Jump up to:a b W. W. Rouse Ball (1960) "The Eight Queens Problem",
in Mathematical Recreations and Essays, Macmillan, New York, pp. 165–
171.
 Explicit Solutions to the N-Queens Problem for all N, Bo Bernhardsson
(1991), Department of Automatic Control, Lund Institute of Technology,
Sweden.
 The Q27 Project
 J. Barr and S. Rao (2006), The n-Queens Problem in Higher Dimensions,
Elemente der Mathematik, vol 61 (4), pp. 133–137.
 Chatham, Doug (1 December 2018). "Reflections on the n +k dragon kings
problem". Recreational Mathematics Magazine. 5 (10): 39–
55. doi:10.2478/rmm-2018-0007.
 G. Pólya, Uber die "doppelt-periodischen" Losungen des n-Damen-
Problems, George Pólya: Collected papers Vol. IV, G-C. Rota, ed., MIT
Press, Cambridge, London, 1984, pp. 237–247
 Queens and knights problem
 Nine queens problem
 Bitner, J.R. and E.M. Reingold (1975), "Backtracking programming techniques,"
Communications of the ACM, Vol. 18, No. 11, pp. 651-56.
 Gauss and the Eight Queens Problem: A Study in Miniature of the Propagation of
Historical Error, Campbell, Nov. 1977, Historia Mathematica, Vol. 4 No. 4.
 .Purdom, P.W. and C.A. Brown (1983), "An analysis of backtracking with search
rearrangement," SIAM Journal of Computing, Vol. 12, No. 4, pp. 717-33.
 Bernhardsson, B. (1991), "Explicit solutions to the nqueens problems for all n,"
ACM SIGART Bulletin, Vol. 2, No. 7.
 Ellis Horowitz, Sartaj Sahni, Sanguthevar Rajasekaran “Fundamentals of
Computer Algorithms,2nd edition”, Universities Press, 2008.
 An Introduction To Programming And OO Design Using Java , J.Nino And
F.A.Hosch, John Wiley & Sons [7]. Herbert Schildt “The Complete Reference
Java, J2SE 5th edition”, Tata McGraw Hill Edition,2007.
 Barry J.Holmes, Daniel T.Joyce “Object Oriented Programming with Java,2nd
edition”, Jones and Bartlett Publishers,2001.
 Y.Daniel Liang “Introduction to Java Programming, 7th edition”,Prentice
Hall,2008.

Department of MCA, NHCE 2018-2019 31


N QUEEN PROBLEM 1NH18MCA37
 Big Java ,2nd edition, Cay Horstman, Wiley Student Edition , Wiely India Private
Limited.

9.2 WEB REFERENCE


 https://en.wikipedia.org/wiki/Eight_queens_puzzle
 https://developers.google.com/optimization/cp/queens
 https://www.geeksforgeeks.org/n-queen-problem-backtracking-3/
 https://www.tutorialspoint.com/N-Queen-Problem
 https://www.codesdope.com/blog/article/backtracking-explanation-and-n-queens-
problem/
 https://algorithms.tutorialhorizon.com/backtracking-n-queens-problem/
 https://www.includehelp.com/algorithms/n-queens-problem-and-solution-using-
backtracking-algorithm.aspx
 https://www.slideshare.net/smartsukrit/the-n-queen-problem
 https://www.thecrazyprogrammer.com/2015/03/c-program-for-n-queens-problem-
using-backtracking.html
 http://scanftree.com/programs/c/c-program-to-solve-n-queens-problem/
 https://rosettacode.org/wiki/N-queens_problem

Department of MCA, NHCE 2018-2019 32


N QUEEN PROBLEM 1NH18MCA37

Department of MCA, NHCE 2018-2019 33

You might also like