Skip to main content
added 359 characters in body; added 3 characters in body
Source Link

The Position class is (although probably good design) quite redundant: you construct an array of Position objects, of which the row (first argument of the constructor) is always the same as the index in the array. In effect the int array queens at that point already contains all information for the solution. The conversion to Positions doesn't add any information, is redundant and the performance would increase (marginally) by removing it.

EDIT: The candidates array is static for each problem size: no need to pass it to the search method, if you would create a SolutionFinder class that is specialized for a particular problem size. Now the candidates can be final state in an instance of this class, the solve and search methods become simpler. Not sure if this would impact performance.

The Position class is (although probably good design) quite redundant: you construct an array of Position objects, of which the row (first argument of the constructor) is always the same as the index in the array. In effect the int array queens at that point already contains all information for the solution. The conversion to Positions doesn't add any information, is redundant and the performance would increase (marginally) by removing it.

The Position class is (although probably good design) quite redundant: you construct an array of Position objects, of which the row (first argument of the constructor) is always the same as the index in the array. In effect the int array queens at that point already contains all information for the solution. The conversion to Positions doesn't add any information, is redundant and the performance would increase (marginally) by removing it.

EDIT: The candidates array is static for each problem size: no need to pass it to the search method, if you would create a SolutionFinder class that is specialized for a particular problem size. Now the candidates can be final state in an instance of this class, the solve and search methods become simpler. Not sure if this would impact performance.

Source Link

The Position class is (although probably good design) quite redundant: you construct an array of Position objects, of which the row (first argument of the constructor) is always the same as the index in the array. In effect the int array queens at that point already contains all information for the solution. The conversion to Positions doesn't add any information, is redundant and the performance would increase (marginally) by removing it.