I was wondering what the Big-O of a simple brute force backtracking Sudoku solving algorithm was.
Sudoku has 4 constraints:
- cell - one cell can contain one number max
- region - numbers in the region must be all different
- row - numbers on the same row must be all different
- column - numbers on the same column must be all different
Given the 9x9 grid:
3|___|___________
_|_ _|_ _ _ _ _ _
_|___|_ _ _ _ _ _
_|_ _ _ _ _ _ _ _
_|_ _ _ _ _ _ _ _
_|_ _ _ _ _ _ _ _
_|_ _ _ _ _ _ _ _
_|_ _ _ _ _ _ _ _
_|_ _ _ _ _ _ _ _
I think the row, column and region constraints are all O(n!) since (n)(n-1)(n-2)(n-3)(n-4)(n-5)(n-6)(n-7)(n-8) for each row, column and region as they get filled up.
But given that there must be a minimum of 17 given solutions for a unique 9x9 Sudoku solution to exist, I'm not sure now. The number of permutations are O(n^(n^2 - k)) where k = 17 for pure brute force but this does not include constraint satisfaction, which I'm sure is either exponential O(c^n) or factorial O(n!) at least.
So the question again is what is the Big-O of sudoku using brute force backtracking with constraint satisfaction and why? O(log n!)?