Вы находитесь на странице: 1из 14

Design and Analysis of Algorithms CS 255 Sudoku

By: Priyank Shah Parin Shah

Outline
Introduction Project Description Back Tracking Algorithm Graph Coloring Brute Force Algorithm Demo Results

Sudoku
Sudoku is a logic-based, number-placement puzzle consisting of a n-by-n grid of n2 squares, each of which is similarly divided into smaller squares, some containing numbers.

Rules
Cannot write the same digit in two or more cells of the same row. Cannot write the same digit in two or more cells of the same column. Cannot write the same digit in two or more cells of the same block. For a Sudoku to be solvable to unique solution there should be at least 17 given numbers in puzzle.

Generation of Sudoku
Create fast, short and reliable Sudoku using known algorithms. Using two different algorithms 1) Backtracking algorithm 2) Graph coloring Sudoku generated have unique solution. Contains five levels of difficulty. Validates the value entered by user by solving Sudoku using Backtracking algorithm. Show all possible values that might go in grid.

Continued...

Sudoku Solver
Solves partially filled grid following the rules of puzzle. Brute force algorithm is used to solve the puzzle. Calculating time to solve different levels of puzzle.

Generation by Backtracking algorithm


Overview of backtracking
Backtracking is a general algorithm for finding solutions to some computational problem. It incrementally builds candidates to the solutions. Eliminates each partial candidate as soon as it determines that it cannot possibly be completed to a valid solution

Backtracking
dead end ? dead end start ? ? ? dead end dead end ? success! dead end

Graph Coloring
Graph coloring is a problem in which each vertex or edge is colored in such a way that no two neighboring vertex or edge are of same color.

Application to Sudoku riddle


An integer between one to nine could be assigned to each vertex. Each vertex joined by an edge would not have the identical integer assigned to it.
4 * 4 puzzle

Brute Force Algorithm


Brute Force is problem-solving technique that enumerating all possible candidates for the solution and checking whether each candidate satisfies the problem's statement. Solution is guaranteed. No strong relation between the solving time and the degree of difficulty of the puzzle.

Application in Sudoku
Placing the digit "1" in the first cell. Check for row, column and box constraint. NO violations moves to next cell and places 1. 1 is not allowed so the value is advanced to a "2". If a cell is discovered where none of the 9 digits is allowed, then the algorithm leaves that cell blank and moves back to the previous cell. The value in that cell is then incremented by one. The algorithm is repeated until the allowed value in the 81st cell is discovered.

Calculating difficulty level

First of all it checks from number 1 to 9 and checks for possible values that go in grid. Then if cell has 1 possible value then it is hit and get points added to difficulty. If more than 1 value goes in grid then 3 points are added for each value.
0... 515 = very easy 515... 570 = easy 570... 960 = normal 960... 1200 = hard 1200... above = very hard

Results Time taken to generate Sudoku puzzle


Very Easy ( 0 .. 515) Easy (515...570) Normal (570...960) Hard(960... 1200) 270 315 ms 251 - 281ms 270 - 290 ms 235 - 285ms

Very Hard(1200...above) 230 - 260ms

Each level of puzzle is generated between 230ms 320ms.

Solver using Brute Force Algorithm


Results are based on average of five observations.

Level of Difficulty Very Easy Easy Normal Hard Very Hard

Time Taken 48ms! 46ms! 63ms! 51ms! 60ms!

Thank you

Вам также может понравиться