Homework 1 (due 10/10/97): The N-Queens Problem

The N-Queens problem is the problem of positioning N Queens on a N x N chess board such that no Queen can "take" another Queen by moving horizontally, vertically, or diagonally (standard chess Queen movement).

Write a program in C, C++, or Java to solve the 8-Queens problem. This problem requires that your program find all solutions to the problem of placing eight queens on a chess board with the constraint that no queen can "take" any other queen. Your program should search using back-track search, with constraints. Your program should print out all solutions.

You may use symmetries and constraints to reduce the amount of searching.

Hand in a fully documented report, listing your program and showing exactly what each part of your program is doing. You should also show the input to your program and all output solutions. You do not have to hand in a listing of all solutions. Instead, you may hand in at least five solutions and state the number of solutions. Feel free to turn in legible pseudo code with your program.


This is an example of a solution to the N-Queens problem. It will not allow you to run it for N = 7, 8 or 9. Try it for small N like 4 or 6 and for large N like 10 or 12. Notice that the 12-Queens problem takes much longer to run than the 6-Queens Problem.

Enter an N value into the Field and click on the Run button. When it finishes running it will tell you how many solutions it found in the Boards Left box. Repeatedly click on Next Board to look at the solutions.

To be able to see this applet, you must have a Java capable browser.