COEN 171
Principles of Programming Languages
Winter 2000
First
Programming Assignment
Problem Statement: The "N Non-attacking Queens"
problem is a classic in the instructional programming area. It exemplifies a common problem solving approach
known as "backtracking."
In
chess, a Queen may attack along the horizontal rows, the vertical columns, or
the diagonals. The N Queens problem is
to place N Queens on an NxN chessboard so that no Queen attacks another.
Your
assignment is to implement two
solutions to the 8 Queens
problem, one solution using an iterative approach (that is, one in which the
main body of the program is a (possibly nested) loop) and the other using a
recursive approach (in which the main body is a recursive procedure). You may use any imperative language
of your choice (C, C++, Ada, Java, others) that supports recursion.
Hand
in complete source listings for your programs, as well as the results of
execution indicating a correct solution to the 8 Queens problem. The output can be a printer listing, a print
of an output file, or a screen capture of an interactive session.
Suggestions: You
may find one solution, or all solutions (I think there are 92!), whichever is
easier.
You may find it easier to debug your
programs using a smaller board (say, 4x4) simply to minimize execution
time. You may also find it easier to
implement a solution that works for any value of N, and then invoke it
with a parameter to solve the 8x8 case.
There is no requirement for graphical (or other two-dimensional) output of your solution. A simple list of (row, column) pairs is sufficient.
These are not difficult problems. You might want to take this opportunity to work in an imperative language with which you aren't completely familiar, just to gain some additional experience.
Due Date: January 18, 2000