



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Lab; Professor: Ceberio; Class: Data Structures; Subject: Computer Science; University: University of Texas - El Paso; Term: Fall 2006;
Typology: Lab Reports
1 / 5
This page cannot be seen from the preview
Don't miss anything!




Data Stru tures and Algorithms CS
Lab 1
Help
Algorithm Analysis
Kakuro Puzzle
Please refer to http://www.kakuro. om for a omplete presentation of Kakuro.
Kakuro puzzles resemble rosswords whi h use numb ers instead of words. The aim of the game is to ll all the blank squares in the grid with only the numb ers 1-9 so that the numb ers you enter add up to the orresp onding lues. When the grid is lled, the puzzle is omplete.
Kakuro puzzle grids an b e any size, though usually the squares within them have to b e arranged symmetri ally. As a rule of thumb, the more blank squares a puzzle ontains, the harder it is, however this isn't always true, esp e ially if it is a go o d quality puzzle.
You have to:
Help
To omplete this lab, you have to determine the value of ea h blank ell of the b oard. To ll the blanks, you have a limited hoi e:
A simple approa h
A simple^1 way to pro eed is to:
(a) if there is no more p ossible value to assign to the last ell assigned, then go ba k one more step, and so on, until you nd a formerly assigned ell that an still take another value. (b) if there is no su h formerly assigned ell, it means that there is no solution to your puzzle.
This approa h is alled Generate and Test. This is a very extensive sear h for the state of the b oard that meets the onstraints. Basi ally, what it do es is that it generates all p ossible ombinations of numb ers on the b oard, and he ks the ompletely lled b oard against the onstraints (if it meets them, it is a solution, otherwise, it is to b e redone).
A p ossible improvement^3
Instead of waiting until the b oard is full to he k the values against the onstraints, it is desirable to he k the onstraints as so on as p ossible, so that values an b e dis arded b efore the generation of a more omplete b oard that would never b e a solution anyway.
(^1) Simple do es not mean that it is easy for the omputer (e ien y is an issue). (^2) This is alled ba ktra king. (^3) Not yet the b est version.
Figure 1: An example of a problem and its solution
greater than 5, b e ause we know in advan e that they are going to violate the sum onstraint.
If, in addition, there are already other values instan iated, and involved in the same onstraint, then the p ossible valid values are even more limited.
Taking this feature into a ount redu es even more the time it takes to rea h a solution of the puzzle.
IMPORTANT NOTE: You should implement this last version only when the former one fun tions p erfe tly.
Figure 2: An example of a problem as given as input (i.e., to b e lled