Algorithm Analysis - Data Structures - Lab 1 | CS 2402, Lab Reports of Data Structures and Algorithms

Material Type: Lab; Professor: Ceberio; Class: Data Structures; Subject: Computer Science; University: University of Texas - El Paso; Term: Fall 2006;

Typology: Lab Reports

Pre 2010

Uploaded on 08/18/2009

koofers-user-xcm-1
koofers-user-xcm-1 🇺🇸

10 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Data Strutures and Algorithms CS2402
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 numbers instead of words. The aim of
the game is to ll all the blank squares in the grid with only the numbers 1-9 so that
the numbers you enter add up to the orresponding lues. When the grid is lled, the
puzzle is omplete.
Kakuro puzzle grids an be any size, though usually the squares within them have to be
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, espeially if it is a good quality puzzle.
You have to:
1. Implement the following algorithm:
input: a
n
by
p
board, whose ells are either to be lled or are ells that are
not to be lled and ontain sums or nothing
(f. some examples below)
;
output: the b oard where all ells to be lled are lled and the numbers in
those ells orrespond to the sums;
as a rst attempt, you an implement it for a xed size of the board.
2. Run your algorithm for dierent sizes of Kakuro.
3. Determine the omplexity of your algorithm:
by proving it on the paper;
by running experiments, reporting the results and analyzing them.
1
pf3
pf4
pf5

Partial preview of the text

Download Algorithm Analysis - Data Structures - Lab 1 | CS 2402 and more Lab Reports Data Structures and Algorithms in PDF only on Docsity!

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:

  1. Implement the following algorithm:
    • input: a n by p b oard, whose ells are either to b e lled or are ells that are not to b e lled and ontain sums or nothing ( f. some examples below);
    • output: the b oard where all ells to b e lled are lled and the numb ers in those ells orresp ond to the sums;
    • as a rst attempt, you an implement it for a xed size of the b oard.
  2. Run your algorithm for dierent sizes of Kakuro.
  3. Determine the omplexity of your algorithm:
    • by proving it on the pap er;
    • by running exp eriments, rep orting the results and analyzing them.

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:

  • blanks an only take values from 1 to 9;
  • the values in the blank have to meet the sum onstraints, shown in darker ells.

A simple approa h

A simple^1 way to pro eed is to:

  1. onsider ea h blank ell and assign a value to it (among 1 to 9);
  2. do the same for all blank ells until the b oard is full;
  3. he k if the urrent b oard (with lled ells) meets the sum onstraints;
  4. if the onstraints are not met, then go ba k^2 to the last assignment and hange the value; go ba k to 3;

(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.

  1. if the onstraints are met, you are done: you have found a solution of the 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