Analysis of Sudoku Solving Algorithms

— The idea of this paper is to analyse the performance of various Sudoku solving algorithms. A well laid out groundwork has been done to find out the efficient and fast approach to making the computer solve a Sudoku. After considering multiple options like Backtracking and Brute Force Algorithm, the research ended up with DANCING LINKS algorithm that was proposed to the world by DONALD KNUTH, which he claimed was the best approach to solving a Sudoku from a computational perspective. Also, a comparative analysis of the chosen algorithm with the more traditional approaches was performed to know the competence of our algorithm.

The previous research [6] holds that Brute Force using backtracking for iterative processing uses backtracking and hence proved to be faster than the Backtracking algorithm.
III. PROPOSED IDEA Sudoku, in the past, has proven to be a complex problem in both the field of mathematics and computer science. We are trying to accomplish a Sudoku solving application that makes use of the ALGORITHM X. Since any application demands both speed and accuracy the chosen algorithm must be able to meet both the requirements. Our options included the basic BRUTE FORCE, BACKTRACKING, DANCING LINKS (ALGORITHM X). As the chosen algorithm was a derivative of the Backtracking problem the analytical comparison included only Brute Force and Algorithm X. The chosen algorithm makes use of the Backtracking process including a concept called Dancing Links introduced by DONALD KNUTH.
IV. CONSTRAINT PROGRAMMING Sudoku is a constraint problem. In his paper Sudoku as a Constraint Problem, Helmut Simonis [7] describes many reasoning algorithms available in the form of constraints which can be applied to model and solve the problem. Some constraint solvers include an example how to the model and solve Sudoku problems. Once the constraint program modelling is used for sudoku solving it takes less than 100 lines of code in most solvers.
An exact cover problem is a problem where there are a given set of choices, and constraints and the user's challenge are to select the set of choices that will fill every constraint only once.
For example, consider the case of a magician who creates his show timeline. He holds a lot of tricks of disguise but always plans as such that no tricks get repeated again. Even though having a lot of tricks in his magic hat he chooses the ideal selection to cover all the tricks only once. In this example, the constraints are that he must perform every trick. The trick choices are the possible show timeline he could incorporate into his timeline.
A better way to represent such type of problems is to draw out a table where the constraints are columns and the choice are rows, and we have a big X in cells where a particular choice fulfils that constraint. As it turns out, on the given right constraints and choices, Sudoku can be described as an Exact Cover Problem.
We drew our inspiration from the solution that Donald Knuth suggested was the best approach to an exact cover problem. There have been many approaches when it comes to solving the Sudoku. It is one of the Intriguing problems and involves multiple complex operations.

A. Sudoku as a constraint problem
Sudoku can be transformed into an exact cover problem [8] using a technique called "Dancing Links" which was put forth by Donald Knuth. This allows both for an elegant description of the problem and an efficient solution using a backtracking algorithm. The usage of algorithms for exact cover, such as Dancing Links, typically solves a 9X9 sudoku problem with the computation time of the order of seconds. While exact cover does not guarantee efficient solution time for large grids.
In technical aspect, Algorithm X is a recursive [9], non-deterministic, depth-first [10] and backtracking algorithm. For solving such exact cover problem, Donald Knuth [11] used "Algorithm X" as the reference name for this trial and error approach in his paper called "Dancing Links".

A. Methodology
The implementation was done in C# with our initial approach of including unity to package for android and iOS. But due to the technical difficulties, the approach has been changed to having a server in visual studio and creating a client in either of the devices.

B. How it works
As explained before the Algorithm X uses the technique Dancing Links to solve an exact cover problem or a Sudoku statement. The Dancing Links works in the following way. 1) Let us have a square matrix filled with 0's and 1's. 2) Either a column or a row with the least number of 1's is taken and corresponding columns or rows are selected which have the 1's and the rest are omitted. 3) After repeating this process for several times based on the size of the matrix. We get a matrix that has a 1 in all rows and columns. 4) This means that the dancing links gives the final result where there is a one in that row or a column, which is essential to solving a Sudoku problem. Though the dancing links is an amazing technique to solve an exact cover problem it cannot by itself give a solution in real time. Hence Donald Knuth came up with the Algorithm X to reduce the number of processing statements and hence reduce the time complexity of the algorithm.

VI. ALGORITHM X
The below mentioned is the pseudo code of the Algorithm X: if matrix a has no columns then the current partial solution is a valid solution; terminate successfully; else otherwise choose column c (deterministically); choose a row r such that ar, c=1 (non-deterministically); include row r in the partial solution; for column j such that aj=1 do for row i such that ai, j=1 do delete row i from matrix a; delete column j from matrix a; end end end Repeat this algorithm recursively on the reduced matrix a; VII. This is a simple iterative approach to the same rather than using the traditional recursive approach. Theoretically, the computation time of brute force algorithm is O(M *N^3) while Algorithm X has O(N^3).

RESULTS AND DISCUSSIONS A. BRUTE FORCE ALGORITHM
where M are the number of zeroes present in the grid and N equals to 9.

T(Algorithm X solution) <= T(K*brute force solution)
Where K= 1/M while they both were clearly distinctive on paper, practical efficiency was key for the successful working of the application. In order to properly measure the potential and analyse the algorithm x, many complex and hard level Sudoku problems were taken and both were run in two different algorithms.
One was the Brute Force algorithm and the other was the employed Algorithm X, the brute force runs every probable option for all the grids until an acceptable answer is reached and the Algorithm X eliminates possibilities to increase efficiency and accuracy.
There were 12 different samples that were run to make a comparative analysis of the algorithms. After they were executed the difference between the runtimes was phenomenal, the Algorithm X was faster than the Brute Force algorithm by a lot, by a whole second in few cases. This kind of combination of accuracy and speed was essential for the efficiency of the application which made the employed algorithm the best choice without question.
VIII. CONCLUSION After a complete analysis of the potential bore by the algorithm X and the efficiency it offers the application through the concept of dancing links, we can infer that the algorithm X is far advanced and superior compared to traditional algorithms in an approach to solve a Sudoku. The statistical analysis clearly states that higher the difficulty level of sudoku problem, the higher is the calculation time difference between the Algorithm X and Brute Force.
IX. FUTURE SCOPE The speed of Algorithm X execution against Brute Force Algorithm has done all the talking. But experiencing the speed with naked eyes gives more satisfaction. To get it to that level we can use Augmented Reality, a new boom in the technical world. The fetching of physical Sudoku on the computer screen though the camera and then providing the solution using the Algorithm X within milliseconds back on the screen will make anyone feel the speed against existing slow algorithm.