Generation of Combinatorial Objects · Backtracking

Lesson 3

Nikolai Chukhin · Alexander S. Kulikov

To check whether a permutation gives a correct queen arrangement, we need to determine whether any two queens lie on the same diagonal. It is easy to see that two queens lie on the same diagonal if the horizontal distance between them equals the vertical distance. More formally, the cells \([i_{1},j_{1}]\) and \([i_{2},j_{2}]\) lie on the same diagonal if and only if \(|i_{1}-i_{2}|=|j_{1}-j_{2}|\).