Las Vegas Algorithms - The Eight Queen Problem

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Las Vegas Algorithms: The Eight Queen problem

23MCA004 & 23MCA016


Overview: -
- The n-queens problem is a classical combinatorial problem that has been tackled by various
problem-solving strategies.
- There are well known probabilistic local search algorithms that are based on a conflict
minimization heuristic and do not use any kind of backtracking.
- These algorithms run in polynomial time and are capable of solving even a very large n-
queens problem.
- Regardless this fact, there are many researchers worldwide attempting to solve the problem
by means of utilization of genetic algorithms.

8-QUEENS PROBLEM

- The eight queens’ problem is a classical combinatorial problem. To access to right solution of this
problem, we must put all the queens on the 8x8 board so that no queen is attacked with the other
queens (No Queen conflicting with other queens).

- So, the solution


must be nonattack (the queen is attacked if it
shares the same row, column, or diagonal with
another queen) as shown in "Figure 1" [1,2,3]. In
the other words, a solution of the eight queens’
problem must be ensured that each queen can
move to the eight neighboring directions (two
vertical, two horizontal and four diagonal
directions) without attacking with other queens as
shown in "Figure 2 “
Introduction to Backtracking: -
- Backtracking is like solving a maze where you
try different paths until you find the right one.
In the Eight Queens Problem, we start by
placing a queen on the chessboard and then try
to place the next one, making sure it doesn't
attack the first queen.
- If we reach a point where we can't place the
next queen without breaking the rules, we
backtrack and try a different path.
- Imagine you're exploring a maze. You walk
down a path until you hit a dead end. Instead
of giving up, you backtrack to the last point
where you had a choice and try a different
path. Backtracking in the Eight Queens Problem
works similarly. We explore different
combinations of queen placements, and if we
hit a dead end, we backtrack to a previous state
and try a different approach.

Solving the Eight Queens Problem


through Backtracking
- Imagine we have an empty chessboard, and
we want to place eight queens on it.
- We start by placing a queen in the first row
and the first column (1st square).
- Then, we move to the second row and try
to place another queen in a safe spot,
meaning it won't be threatened by the first
queen.
- If we find a safe spot, great! We place the
queen there and move to the next row to
do the same thing.
- But if we can't find a safe spot in the
current row, we backtrack. Backtracking
means we go back to the previous row and
try a different spot for the queen we placed there.
- We keep trying different spots in each row, backtracking when needed, until we either place
all eight queens (which means we found a solution) or realize that we can't place them all
without threatening each other (which means there's no solution for the current
arrangement).

Optimizations and Performance Enhancements


Constraint Propagation: Think of constraint propagation like using clues to solve a puzzle. By
considering the rules of the game early on, we can eliminate certain possibilities and narrow
down our search. For example, if we know two queens can't be in the same row, we don't need
to waste time checking those positions.

Symmetry Breaking: Symmetry breaking is like finding shortcuts in a maze. Instead of


exploring every single path, we can recognize patterns and avoid repeating similar searches. For
the Eight Queens Problem, we can exploit symmetrical solutions to cut down on redundant
searches. If we find a solution on one half of the chessboard, we can mirror it to find solutions
on the other half without redoing the work.

Bitwise Operations: Bitwise operations might sound complicated, but they're like using a
different language to communicate more efficiently. In the context of the Eight Queens Problem,
we represent the chessboard using binary numbers. Each bit in the number corresponds to a
square on the board. By using bitwise operations, we can quickly check if a position is safe for
placing a queen without having to examine the entire board each time.

Conclusion and Q&A:


Today, we've explored the Eight Queens Problem as a vehicle for understanding and mastering
backtracking. Remember, backtracking is a versatile tool in the algorithmic toolbox, and with
practice, you can apply it to solve a wide range of problems.
Now, I'm happy to take any questions you may have.

You might also like