

We try to place every number between 1 to 9 in the unfilled cell. If all the cells are filled then a valid sudoku is obtained. We start by finding an unfilled cell(i,j). " This algorithm visits all the empty cells in some order,filling the digits incrementally, backtracks when a number is not found to be valid.The program starts by filling '1' in the first cell if there are no violations, then advances to the second cell and places '1' incase violation occurs then increments and places '2'.It checks incrementally in this way and when none of the '1' to '9' numbers fit in this cell then the algorithm leaves the cell blank and goes back to the previous cell.The value in that cell is incremented and this process continues until all the cells are filled." STEPS: The difference between brute-force and backtracking is that in backtracking, we do not explore all the possible options instead we explore only worthy options and build the solution incrementally. Sudoku can be solved in the way mentioned above. 3)Backtrackingīacktracking is a kind of brute-force approach which comes into picture when solving a problem requires considering multiple choices as we don't know which choice is correct and we try to solve the problem using trail and error method considering one choice at a time until required answer is obtained. A slight optimization to this would be the backtracking approach. This can be much time consuming and highly inefficient. In naive approach,the algorithm fills in the empty cells without any logic and later checks whether it was a valid placement. Given a partially filled sudoku(Fig 1.a) and a solution to it(Fig 1.b)Ī sudoku is valid if it satisfies all the following properties:ġ.Each row contains unique values ranging from 1 to 9.Ģ.Each column contains unique values ranging from 1 to 9.ģ.Each of 9 sub-squares ,of size 3×3, contains unique values from 1 to 9. Given a 9×9 grid, with some initial values filled.The objective is to fill all the empty cells of the grid with numbers such that it becomes valid. Sudoku is a logic based number placement puzzle. Probably you might know what sudoku is or might have heard somewhere about it.Let's begin with a brief note on it.

We have presented the Time and Space Complexity for various cases. Sometimes there are no steps at all, just try to understand the game, focus on the goal and enjoy the challenge.In this article, we have covered the Backtracking Algorithm for Sudoku and compared with the Brute Force approach. Is the most difficult technique because it is more difficult to spot it. This method can work when you look at cells comprising a rectangle, such as the cells marked in red. Step 3Īnalysis (almost, I Think) this one is almost like the candidate elimination and it is also called deriving certainty from uncertainty. The candidate elimination method happens when a pair of numbers are the only possible answer to two cells. Analysis consists of two methods namely candidate elimination and the what if. If there is just one number missing then that’s what should be in the cell. In counting you simply count all the different numbers that's in a row, column and region that connects to one cell. You scan rows and columns to eliminate where a specific number can be in a given region. Solving the Sudoku Puzzle sometimes can get really hard and challenging, but here are some steps to follow that can help you become faster and more efficient while playing this game.
