The recursive algorithm for the Many Queens problem can be modified to list not just one, but also all the possible solutions. When each solution is found, it is added to a list. The function then...


The recursive algorithm for the Many Queens problem can be modified to list not just one, but also all the possible solutions. When each solution is found, it is added to a list. The function then removes the queen from the last column to force a failure and a search for another solution.


Here is the pseudocode for the modified algorithm, named solve:


function solve(col, board, listOfSolutions)


For each row in the board


if board[row][col] is not under attack


place queen in board[row][col]


if col is the rightmost one then


add board to listOfSolutions


else


solve(col + 1, board, listOfSolutions)


remove queen from board[row][col]


Modify the Many Queens program so that it displays all the solutions.



May 19, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here