Suppose we place one queen per column, but only consider squares which are not attacked by the queens already on the board.
Each queen can invalidate at most 3 squares in each other column, one in the same row and two in the two diagonals passing through that square. "At most" because some squares may be attacked by multiple queens and also some attacked squares may be off the board. [For example if you put a queen in (0,0), it only attacks 2 squares in each other column.] Hence, there are at least (n - 3x) safe squares in the nXn board in each of the remaining columns after x queens are placed.
Hence, the number of states to be considered by the search sapce in question is at least:
n * (n-3) * (n-6) * .... 1 (or 2 or 3) = n!!!.
(n!!!) ^3 = n^3 * (n-3)^3 * .... * 1^3 (or 2^3 or 3^3).
>= n (n-1) (n-2) (n-3) (n-4) (n-5) ..... 1
= n!
Hence the size of the search space explored (for all solutions)
>= n!!! >= (n!)^{1/3}
Note: I used x^y to denote x to the power of y.
Assuming, like in the book, that 10000 nodes can be expanded in a second, and since there are 86,400 seconds in a day, the time it takes to expand that many states is (n!)^{1/3} / 864,000,000. This gives the following results:
| n | days to compute the answer |
|---|---|
| 20 | 0.0015566624991418378 |
| 21 | 0.0042947138033482746 |
| 22 | 0.012033956990890452 |
| 23 | 0.034222972923347215 |
| 24 | 0.0987161359866793 |
| 25 | 0.2886477326728829 |
| 26 | 0.8551177731981187 |
| 27 | 2.565353319594359 |
| 28 | 7.789923599244858 |
| 29 | 23.933113344767208 |
| 30 | 74.36574775353864 |
| 40 | 1.0815E7 (= 29,631 years!) |
Notice how quickly the function grows between n=26 and n=30. More than n=25 should be considered impractical. Note that space is not an issue here, since we can use depth first search, which only requires space in proportion to O(n^2).
The rest of the solutions are given out in the class.