hobiwan wrote:As you can see the ratio between Wikipedias "nearly worst case" and #46556 is over 1:47 (although 95ms is probably still fast enough for most applications).
the wiki worst case makes some bad assumptions on backtracking algorithm implementatiions
namely that the grid is examined by something like
for r in 1..9 for c in 1..9 for v in 1..9
and always in the same order
the forgot the most basic backtracking optimization: take the branch(es) with the least amount of choices
Draco wrote:#1 and #3 = 15.63Ms, #2 = 234.38Ms. So not instantaneous, but still pretty darned quick. Clearly some of these are much harder for the recursive solver to nail. I doubt a human could match these times though
. Also clear that there are/will be diff's between recursive implementations and what they find faster or slower. For those that care about technical details, at one point I tried unwinding the recursion and turning it into a loop. The amount of state I had to put onto my own "stack" for this meant that there was little speed difference (and the unwound version was a lot harder to read!)
a big part of the efficiency of a backtracking implementation is the amount of state that must be copied for the next ply and/or unwound on error
also, to measure timings in the noise, do the timing on say 1000 copies of the same puzzle
15 vs. 234 may not be much for one puzzle, but its an order of magnitude, and that could make
a big differences on a collection of 100s or 1Ms or puzzles
or e.g. when searching for puzzles with particular properties, like 17 clues or with clues matching a pattern template