1

I am currently following an algorithms class and we have to solve a sudoku.

I have already a working solution with naive backtracking but I'm much more interest in solving this puzzle problem with a tree data structure.

My problem is that I don't quite understand how it works. Is anyone can explain to me the basic of puzzle solving with tree?

I don't seek optimization. I looking for explanation on algorithms like the Genetic algorithm or something similar. My purpose only to learn at this point. I have hard time to take what I read in scientific articles and translate it on real implementation.

I Hope, I've made my question more clear.

Thank you very much!

EDIT: I edit the post to be more precise.

  • 2
    what do you mean "with tree"? sudoku is [NP-Hard](http://en.wikipedia.org/wiki/NP-hard) problem, so backtracking is not such a bad idea – amit Feb 02 '12 at 15:51
  • @amit - I know backtracking do the job. But, I think (maybe I'm completely wrong) there is a way to find the next best move to do using a tree representation which every branch represent a move you could do. So, to find the solution, you don't have to follow every possible move but only few move. – Jean-Christophe Fortin Feb 02 '12 at 16:13
  • 2
    The sudoku problem is [NP-Hard](http://en.wikipedia.org/wiki/NP-hard). There is not known polynomial solution that solves it. I am not sure what exactly are you after... – amit Feb 02 '12 at 16:16
  • 2
    You can certainly prioritize the order you search moves in. Sudoku is used to illustrate constraint-based programming for this reason (not only are the constraints fairly easy to specify, but the most constrained move is generally the most promising). I'm not sure about the benefit of a tree data-structure over your current implementation because your call graph seems to be identical to the tree you propose. What operations do you plan on performing on the tree that you can't do with your backtracking technique (hint: the operation should be non-local)? – ccoakley Feb 02 '12 at 17:44

2 Answers2

0

I don't know how to solve Sudoku "with a tree", but you're trying to mark as many cells as possible before trying to guess and using backtrace. Therefore check out this question.

Community
  • 1
  • 1
Dialecticus
  • 16,400
  • 7
  • 43
  • 103
  • Could be a decision tree. In fact it would be a DAG, caused by the transpositions of *moves* – wildplasser Feb 03 '12 at 12:11
  • OP stated that he wants to solve Sudoku with a tree, so that he does not have to backtrack. That makes little sense. Maybe he is asking about heuristic so that when the algorithm tries to guess that guess is the most optimal. But, I'm just guessing here, since that is not written in the question. If that was what OP was really asking then I don't have the answer. But, if OP just wants algorithm that solves as much of the board without resorting to guessing then the link provides some hints about it. – Dialecticus Feb 03 '12 at 13:28
  • @Dialecticus - I edit my question. I already have a solution like the one you propose. The best solution I found it's to make an hybrids between guess and some of the tactics you gave in your link. – Jean-Christophe Fortin Feb 03 '12 at 14:16
0

Like in most search problems, also in Sudoku you may associate a tree with the problem. In this case nodes are partial assignments to the variables and branches correspond to extensions of the assignment in the parent node. However it is not practical (or even feasible) to store these trees in memory, you can think of them as a conceptual tool. Backtracking actually navigates such a tree using variable ordering to avoid exploring hopeless branches. A better (faster) solution can be obtained by constraint propagation techniques since you know that all rows, columns, and 3x3 cells must contain different values. A simple algorithm for that is AC3 and it is covered in most introductory AI books including Russell & Norvig 2010.

sumx
  • 587
  • 5
  • 6