[This page is auto-generated; please prefer to read the article’s PDF Form.]
An earlier article titled Generating Permutations with Recursion [1] discusses a permutation generation algorithm by C. T. Fike which can be modified to solve the 8-Queens Problem (refer method fike() in its section “Fike’s Algorithm”). Instead of searching, it systematically locates the next element to place at index s.
The modified method is shown below with all added lines marked using /* 8Q */. Unlike permute(), array a needs to be initialized in this case. For other initializations, the earlier shown init() method should be used.
Notice how, adding a few steps to the two permutation generation methods (permute() and fike()), gave us methods to solve an initially dissimilar 8-Queens Problem.
For both these methods, we could skip the recursive call (for argument (s + 1)) whenever required and could still uphold the correctness of the permutation generation logic with ease. We may be able to use other permutation generation algorithms too (e.g. from article [1]) for the 8-Queens Problem, but introduction of such skipping may demand other changes to ensure their correctness.
■
[1] Nitin Verma. Generating Permutations with Recursion. https://
mathsanew.com/articles/permutations_with_recursion.pdf.
Copyright © 2021 Nitin Verma. All rights reserved.