Professional Documents
Culture Documents
INTRODUCTION
In real life we come across Sudoku puzzles of varying difficulty levels in newspapers and other text and
digital media. It is a common leisure activity for a lot of people. However, it is observed that the solution
is not always immediately available for the users verication. In most cases, people have to wait till the
next day to check the solutions of the Sudoku they just solved. Hence our motivation for this project was
to develop an application for it. In this method the user has to enter the values from the given Sudoku
problem and the algorithm returns the complete solution of the same. Sudoku is a logic based puzzle with
the goal to complete a 9x9 grid so that every row, every column and all of the nine 3x3 boxes contain the
numbers 1 through 9, given a partial filing to a unique solution. The problem itself is a popular
brainteaser but can easily be used as an algorithmic problem. The latest version of Sudoku was first
introduced in Japan in the eighties and has since then attracted a lot of programmers and therefore there
are a great deal of different Sudoku solving algorithms available on the Internet, both implementations
and construction methods. Sudoku solvers are interesting because they are practical applications of
theoretical problems, and most people are familiar with it.
Different algorithms have been used to solve this logical problem. We are using two different approaches
to solve the puzzle and will compare them. We will implement the Recursive Backtracking and Constraint
Propagation algorithms. Our task is to find the efficient algorithm between the two. The rest of the paper
is Section 2 the review of Literature, Section 3 Algorithms, Section 4 Result, Section 5 Conclusion and
Section 6 the References.
II. LITERATURE REVIEW
A. OVERVIEW
Approach used here is that the users are required to manually enter the Sudoku puzzle [1] and this
numbers are used in Backtracking algorithm [1] to generate the solution. The algorithm will randomly
1 | 2015, IJAFRC All Rights Reserved
www.ijafrc.org
www.ijafrc.org
End
C. Constraint Propagation
Constraint propagation is an algorithm that solves Sudoku problems by using possibility array and
multiple iterations. For this algorithm we will initially fill all the space with the values given in the
question, after that we will put zeroes in the blank locations. In this we will find all the possible numbers
for a particular blank location and we will have an array for each blank location, if for a particular blank
location there is only one possibility then we will directly insert the value in that location, otherwise we
will have multiple iterations following to complete the Sudoku problem. In some cases where the Sudoku
problem is of hard or extreme level we won't have a possible value after multiple iterations. For most of
the cases constraint propagation will be enough to fill the grid completely and without any conflict.
Limitations:
When single possible value is not available for some grids then the constraint propagation algorithm
enters infinite loop and consequently is unable to solve the Sudoku problem.
Modified Constraint Propagation:
The modified version that we are developing will be able to solve such Sudoku problems efficiently.
1. Pseudo code
Procedure init (grid[][])
Begin
for i=0 to 8 for j= 0 to 8
Cell[i][j] =grid[i][j]
Cell[i][j].domain.clear()
for i=0 to 8
for j= 0 to 8
if grid [i][j] is NOT 0
for k= 0 to 8
Cell[i][k].domain.remove(grid[i][j])
assignIfOnlyOne(i,k)
for k= 0 to 8
Cell[k][j].domain.remove(grid[i][j])
assignIfOnlyOne(k,j)
for k = 0 to 3
for kk = 0 to 3
Cell[floor(i/3)*3+k ][ floor(j/3)*3+kk]
.d
omain.remove(grid[i][j])
assignIfOnlyOne(k, kk)
End
Procedure assignIfOnlyOne (row, col)
Begin
3 | 2015, IJAFRC All Rights Reserved
www.ijafrc.org
if(Cell[row][col].domain.size() ==1
Cell[row][col] = Cell[row][col].domain.get(0)
Cell[row][col].domain.clear()
for k= 0 to 8
Cell[i][k].domain.remove(values[i][j])
assignIfOnlyOne(i,k)
for k= 0 to 8
Cell[k][j].domain.remove(values[i][j])
assignIfOnlyOne(k,j)
for k = 0 to 3
for kk = 0 to 3
Cell[floor(i/3)*3+k ][ floor(j/3)*3+kk]
.domain.remove(values[i][j])
assignIfOnlyOne(k, kk)
End
III. RESULT
Comparing the time and number of iterations of Backtracking and Constraint Propagation.
Name of the
Time and Iterations
Time and Iterations
Time and Iterations
Algorithm
for Easy level sudoku
for Medium level
for Hard level
sudoku
sudoku
Backtracking
327 iterations
1501 iterations
12058 iterations
65 milliseconds
187 milliseconds
1040 milliseconds
Constraint
Propagation
1630 iterations
272 milliseconds
7386 iterations
580 milliseconds
60464 iterations
6052 milliseconds
Improved Constraint
Propagation
455 iterations
77 milliseconds
2823 iterations
250 milliseconds
23083 iterations
631 milliseconds
IV. CONCLUSION
The simulation result shows us that Backtracking algorithm give better solution for the 9x9 grid Sudoku
puzzle with no violation of constraints and it requires less time, number of iterations and has better
performance. On the other hand Constraint Propagation algorithm is more time consuming. We have
found certain limitations while executing constraint propagation i.e. When single possible value is not
available for some grids then the constraint propagation algorithm enters infinite loop and consequently
is unable to solve the Sudoku problem, so we have developed an improved version of constraint
propagation that solves the Sudoku problem more effectively.
V. ACKNOWLEDGMENT
We would like to thank K.J. Somaiya College of Engineering for the platform that they have provided us
and knowledge base, and most importantly we would like to acknowledge the help and efforts of Prof.
AvaniSakhapara.
4 | 2015, IJAFRC All Rights Reserved
www.ijafrc.org
Arnab Kumar Maji and Rajat Kumar Pal, Sudoku Solving using Minigrid based Backtracking,
University
of
Kolkata
and
north
eastern
hill
university,
INDIA,
2014
[2]
Arnab Kumar Maji and Rajat Kumar Pal, Sudoku Solving using Minigrid based Backtracking,
University of Kolkata and north eastern hill university, INDIA, 2014
[3]
Ali Fatih Gunduz, Larasmoyo Nugroho, Afar Saranli," Sudoku Problem Solving using
Backtracking, Constraint Propagation, Stochastic Hill Climbing and Artificial Bee Colony
Algorithms",
[4]
http://en.wikipedia.org/wiki/Backtracking(accessed on 12/10/2014)
[5]
www.ijafrc.org