Skip to main content

Eight queens puzzle

Eight queens puzzle



Eight Queens Puzzle The eight queens puzzle is the problem of placing eight chess queens on an 8×8 chessboard so that no two queens threaten each other. Thus, a solution requires that no two queens share the same row, column, or diagonal. The eight queens puzzle is an example of the more general n queens problem of placing n non-attacking queens on an n×n chessboard, for which solutions exist for all natural numbers n with the exception of n=2 and n=3. The eight queens puzzle has 92 distinct solutions. If solutions that differ only by the symmetry operations of rotation and reflection of the board are counted as one, the puzzle has 12 solutions. These are called fundamental solutions; representatives of each are shown below.
A fundamental solution usually has eight variants (including its original form) obtained by rotating 90, 180, or 270° and then reflecting each of the four rotational variants in a mirror in a fixed position. However, should a solution be equivalent to its own 90° rotation (as happens to one solution with five queens on a 5×5 board), that fundamental solution will have only two variants (itself and its reflection). Should a solution be equivalent to its own 180° rotation (but not to its 90° rotation), it will have four variants (itself and its reflection, its 90° rotation and the reflection of that). If n > 1, it is not possible for a solution to be equivalent to its own reflection because that would require two queens to be facing each other. Of the 12 fundamental solutions to the problem with eight queens on an 8×8 board, exactly one (solution 12 below) is equal to its own 180° rotation, and none is equal to its 90° rotation; thus, the number of distinct solutions is 11×8 + 1×4 = 92 (where the 8 is derived from four 90° rotational positions and their reflections, and the 4 is derived from two 180° rotational positions and their reflections). 




The initial state is given by the empty chess board. Placing a queen on the board represents an action in the search problem. A goal state is a configuration where none of the queens attacks any of the others. Note that every goal state is reached after exactly 8 actions. 


This formulation as a search problem can be improved when we realize that, in any solution, there must be exactly one queen in each of the columns. Thus, the possible actions can be restricted to placing a queen in the next column that does not yet contain a queen. This reduces the branching factor from (initially) 64 to 8.
Furthermore, we need only consider those rows in the next column that are not already attacked by a queen that was previously on the board. This is because the placing of further queens on the board can never remove the mutual attack and turn the configuration into a solution.

Comments

Popular posts from this blog

Knapsack problem

The  knapsack problem  or  rucksack problem  is a problem in  combinatorial optimization : Given a set of items, each with a weight and a value, determine the number of each item to include in a collection so that the total weight is less than or equal to a given limit and the total value is as large as possible. It derives its name from the problem faced by someone who is constrained by a fixed-size  knapsack and must fill it with the most valuable items. 0/1 Knapsack Problem: Dynamic Programming Approach: Knapsack Problem: Knapsack is basically means bag. A bag of given capacity. We want to pack n items in your luggage. The ith item is worth v i  dollars and weight w i  pounds. Take as valuable a load as possible, but cannot exceed W pounds. v i  w i  W are integers. 0/1 Knapsack Problem: Dynamic Programming Approach: Knapsack Problem: Knapsack is basically means bag. A bag of given capacity. We want to pack n items in your luggage. The ith item is worth v

Sorting Operations in Design Analysis and Algorithm

/* Implementing  sorting in a C Program  * Written by: Riddhi Lalakiya.   */ Sorting Algorithms in C 1.BubbleSort : 1. Algorithm : begin BubbleSort(list)    for all elements of list       if list[i] > list[i+1]          swap(list[i], list[i+1])       end if    end for        return list     end BubbleSort 2. Pseudocode : procedure bubbleSort( list : array of items )    loop = list.count;        for i = 0 to loop-1 do:       swapped = false       for j = 0 to loop-1 do:                 /* compare the adjacent elements */             if list[j] > list[j+1] then             /* swap them */             swap( list[j], list[j+1] )               swapped = true          end if                 end for              /*if no number was swapped that means        array is sorted now, break the loop.*/              if(not swapped) then          break       end if           end for