Experiment No. 8- Implement a Program for 8 Queens Problem (N- Queens Problem) Using Backtracking.docx
Experiment No. 8- Implement a Program for 8 Queens Problem (N- Queens Problem) Using Backtracking.docx
: 8
Outcomes: Students will be able to compute the best-case, worst-case complexity of 8 Queens
Problem (N- Queens Problem) using Backtracking.
Hardware / Software Required: Turbo C/ Notepad/ Eclipse/ IDEs/ code editors, and online
compilers.
Problem Definition:
In this problem N queens are to be placed on N x N chessboard
- No two queens must be in same Row,
- No two queens must be in same Column
- No two queens must be in same Diagonal
All the solutions to the n-queens problem can be represented as n tuples(x1,x2,….,xn) where xi
is the column on which queen i is placed. Solution space consists of n! Permutations of n
tuple (1,2,-----,n).
Theory:
Backtracking is the refinement of the brute force approach, which systematically searches for
a solution to a problem among all available options. It does so by assuming that the solutions
are represented by vectors (v1,v2,…..,vm) of values and by traversing the domains of vectors
until the solutions are found.
Algorithm:
Algorithm n_queen (row,n)
//Problem Description: Implementation of n queen Problem
//Input: no.of queens
for col←1 to n do