1

Suppose, I got a hypothetical fixed list of all possible general Sudoku puzzles. I then create the pseudo-code to demonstrate the algorithm.

  • The algorithm does a search to compare the indexes of elements in the puzzle that are not listed as zero.

  • In other words, all the possible listed Sudoku
    grids are compared until a solution is found matching solution sharing the elements with the
    same index.

--

tuple=[.......]

tuple=[.......]

all possible Sudoku grids.

Here's our solver.

solver = input('enter the puzzle like this 10000030004000...)

if Element with Same Index solver == tuple1, tuple2,...

print (solution containing exact elements that share the indexes in
       both the solution and puzzle)

Will this algorithm solve all Sudoku Puzzles in O log n time?

The T
  • 321
  • 2
  • 11

1 Answers1

4

Such an algorithm can solve Sudoku, but it will be very slow in practice.

By definition, Sudoku is on a 9x9 grid, so there are only a fixed (finite) number of possible puzzles. Your algorithm encodes all of them. Therefore, your algorithm takes constant time, i.e., $O(1)$ time.

What this is telling you is that asymptotic analysis is not a useful tool for analyzing the running time of a Sudoku solver, as asymptotic running time focuses on how the running time grows as you increase the size of the input. With Sudoku, you can't increase the size of the input; the size of the input is fixed. Thus it doesn't even make sense to talk about asymptotic running time for solving Sudoku puzzles.

Some people do analyze a generalization of Sudoku, where instead of a 9x9 grid, we have a $k^2 \times k^2$ grid, where $k$ can be any integer. Then one can consider asymptotic running time. However, your algorithm can't be applied to this generalization of Sudoku, as there are infinitely many puzzles for this generalization, so you can't hardcode them all in the code of your algorithm -- every algorithm must be of finite length. Thus, in that setting, while asymptotic analysis does apply, your algorithmic approach no longer works.

D.W.
  • 167,959
  • 22
  • 232
  • 500