In: Computer Science
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
This can be solved using a backtracking algorithm.
Algorithm:
i) Start
ii) Enter the knights position one by one starting from first row and first column
ii)Iterate forward to first row and second column such that they don’t attack each other.
iii)When one row is exhausted ,iterate over to the next row.
iv)Before placing a knight, Insert a checking condition to check if the block is safe i.e. it is not an attacking position of some other knight.
v)If (block == safe),
place the knight and mark it’s attacking position on the board
else
move forward and check for other blocks.
vi)In this process, make a new board every time a new knight is inserted into the board.
vii)continue until all possible solutions are obtained.
viii)Stop the program
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Correctness of this algorithm:
Since this algorithm is based on backtracking i.e, if we get one solution and we need the rest of the solutions, then we can backtrack to our old board with old configuration of knights and that can be used to find the other possible solutions.