ALGORITHM

Here represent the positions of the queens using an array Q[1 .. n], where Q[i] indicates which square in row i contains a queen. When backtrack is called, the input parameter r is the index of the first empty row, and the prefix Q[1 .. r 1] contains the positions of the first r-1 queens. In particular, to compute all n-queens solutions with no restrictions, we would call backtrack (Q[1 .. n], 1). The outer for-loop considers all possible placements of a queen on row r; the inner for-loop checks whether a candidate placement of row r is consistent with the queens that are already on the first r 1 rows

PYTHON IMPLEMENTATION

Just download python script through below github link & run it





check below Demo





The problem is to place n queens on an n * n chessboard, so that no two queens are attacking each other.this means that no two queens are in the same row, the same column, or the same diagonal.This is the algorithm for n queens backtracking :