# N-queens problem objective function

I have read about the N-queens problem and I don't understand the following objective function:

$O(board)=N^2/2-L$

$N$ ... number of queens $L$ ... number of pairs of queens that attack each other

Why they use $N^2/2$? They wrote that it is the number of pairs of queens but I don't understand that can someone maybe explain it to me maybe with visualization

One can think of many other functions satisfying these two properties, for example $\binom{N}{2} - L + C$ for every $C \geq 0$. The exact choice is not so important – indeed, they chose $N^2/2$ whereas they could have chosen $\binom{N}{2} = N(N-1)/2$.
• So it would also be possible to use $O(board)=L$ and minimize the function? and what is the advantage of using such objective functions $O(board)=(N2)−L+C$, $O(board)=N2/2−L$ instead of my example? - maybe it is a stupid question Aug 29, 2016 at 14:48
• I have no idea on what algorithm you are using, but generally speaking, you could minimize $L$, or $L^2$, or $e^L$, or maximize $1/L$; these objectives are all equivalent. A given algorithm might make use of the actual value of the objective function, and then which function you use could make a difference. Aug 29, 2016 at 14:49