Você está na página 1de 8

Lab Session Unit VI: Backtracking

Phase Transitions in Sudoku

Carlos Cotta

Departamento de Lenguajes y Ciencias de la Computación


Universidad de Málaga

http://www.lcc.uma.es/∼ccottap

Comput. Sci., Comput. Eng. & Software Eng. – 2017-2018

C. Cotta Backtracking Lab 1/8


Index

Index

1 Lab Session Unit VI: Phase Transitions in Sudoku


Problem Statement
Backtracking Approach
Goals of the Lab Session

C. Cotta Backtracking Lab 2/8


Problem Statement
Lab Session Unit VI: Phase Transitions in Sudoku Backtracking Approach
Goals of the Lab Session

Sudoku

4
1 6 9 5 8 Sudoku is a Japanese numerical
9 3 puzzle. The most common
3 version uses a 9 × 9 board but
5 8 7
2 1 3 the game can be generalized to
6 2 1 4 other sizes.
4 8
2 1 7

C. Cotta Backtracking Lab 3/8


Problem Statement
Lab Session Unit VI: Phase Transitions in Sudoku Backtracking Approach
Goals of the Lab Session

Sudoku

Order-2
Order-3 Sudoku Order-4 Sudoku
Sudoku

C. Cotta Backtracking Lab 4/8


Problem Statement
Lab Session Unit VI: Phase Transitions in Sudoku Backtracking Approach
Goals of the Lab Session

Sudoku

Sudoku
An order-n sudoku is a numerical puzzle defined over a board:
1 Its size is n2 × n2 squares.
2 The board is divided into n2 contiguous regions of size n × n
each.
3 Each square can contain a number between 1 and n2 .
The goal is filling all squares with numbers in [1, n2 ] such that no
number is repeated in any row, column or region.

C. Cotta Backtracking Lab 5/8


Problem Statement
Lab Session Unit VI: Phase Transitions in Sudoku Backtracking Approach
Goals of the Lab Session

Constructing a Solution

Feasible solutions are constructed by filling a square at a time.


Each square can contain a number in [1, n2 ]. Let S be the
potential candidates that do not violate any constraint with
respect to squares filled before:
1 If S 6= ∅ each value x ∈ S must be recursively explored until a
solution is found or the set exhausted.
2 If S = ∅ we must backtrack.
Each time a decision is taken we advance to the next (in any
suitable order) empty square.
Some squares are initially fixed and cannot be modified throughout
the process. These are skipped.

C. Cotta Backtracking Lab 6/8


Problem Statement
Lab Session Unit VI: Phase Transitions in Sudoku Backtracking Approach
Goals of the Lab Session

Considerations

Given a certain sudoku instance, it may have 0, 1 or many


solutions.
Solving complexity (number of backtracking steps performed)
depends upon the fraction of squares initially fixed:
If there are few or none the instance is lowly constrained and
there are many solutions. The algorithm advances fast.
If there are many the options to be explored are also limited
so the algorithm advances fast as well.
At a certain critical intermediate value the complexity hits a
maximum (there is an easy-hard-easy phase transition).

C. Cotta Backtracking Lab 7/8


Problem Statement
Lab Session Unit VI: Phase Transitions in Sudoku Backtracking Approach
Goals of the Lab Session

Goals

1 Build a backtracking algorithm to solve arbitrarily-large


sudokus.
2 Use this algorithm to find the critical complexity point for
order-3 sudokus. To this end:
1 The backtracking algorithm must count the number of
recursive steps performed.
2 Test cases with a different number of fixed squares will be used
to empirically assess the complexity of the algorithm as a
function of this number.

C. Cotta Backtracking Lab 8/8

Você também pode gostar