An Analysis of the n- Queens problem Saleem Karamali.

Slides:



Advertisements
Similar presentations
COSC2007 Data Structures II
Advertisements

4.4.1 Generalised Row Echelon Form
Polynomial Time Algorithms for the N-Queen Problem Rok sosic and Jun Gu.
§ 3.4 Matrix Solutions to Linear Systems.
Announcements Assignment #4 is due tonight. Last lab program is going to be assigned this Wednesday. ◦ A backtracking problem.
P Chapter 6 introduces the stack data type. p Several example applications of stacks are given in that chapter. p This presentation shows another use called.
The N-Queens Problem lab01.
Eight queens puzzle. The eight queens puzzle is the problem of placing eight chess queens on an 8×8 chessboard such that none of them are able to capture.
Simultaneous Linear Equations
Linear Inequalities and Linear Programming Chapter 5
P1 RJM 07/08/02EG1C2 Engineering Maths: Matrix Algebra 5 Solving Linear Equations Given the equations 3x + 4y = 10 2x + z = 7 y + 2z = 7 Solve by removing.
Backtracking COP Backtracking  Backtracking is a technique used to solve problems with a large search space, by systematically trying and eliminating.
Ch 13 – Backtracking + Branch-and-Bound
Chapter 1 Section 1.2 Echelon Form and Gauss-Jordan Elimination.
Table of Contents Solving Systems of Linear Equations - Gaussian Elimination The method of solving a linear system of equations by Gaussian Elimination.
Do Now Pass out calculators. Solve the following system by graphing: Graph paper is in the back. 5x + 2y = 9 x + y = -3 Solve the following system by using.
Solving Systems of Equations and Inequalities
Math Dept, Faculty of Applied Science, HCM University of Technology
Solving Systems of Equations
Solving Systems of Equations and Inequalities Section 3.1A-B Two variable linear equations Section 3.1C Matrices Resolution of linear systems Section 3.1D.
Notes 7.3 – Multivariate Linear Systems and Row Operations.
 Row and Reduced Row Echelon  Elementary Matrices.
Linear Systems Two or more unknown quantities that are related to each other can be described by a “system of equations”. If the equations are linear,
Solving Systems of Equations by matrices
Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall.
MATH 250 Linear Equations and Matrices
Row Reduction Method Lesson 6.4.
Vlad Furash & Steven Wine.  Problem surfaced in 1848 by chess player Max Bezzel as 8 queens (regulation board size)  Premise is to place N queens on.
Introduction to Numerical Analysis I MATH/CMPSC 455 PA=LU.
COSC2007 Data Structures II
Matrices Addition & Subtraction Scalar Multiplication & Multiplication Determinants Inverses Solving Systems – 2x2 & 3x3 Cramer’s Rule.
Unit 6 : Matrices.
Unit 3: Matrices.
Back Tracking Project Due August 11, 1999 N-queens: –A classic puzzle for chess buffs is the N- Queens problem. Simply stated: is it possible to place.
HISTORY The problem was originally proposed in 1848 by the chess player Max Bezzel, and over the years, many mathematicians, including Gauss have worked.
Design and Analysis of Algorithms - Chapter 111 How to tackle those difficult problems... There are two principal approaches to tackling NP-hard problems.
Chapter 12 Coping with the Limitations of Algorithm Power Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
1 N -Queens via Relaxation Labeling Ilana Koreh ( ) Luba Rashkovsky ( )
Recursion When to use it and when not to use it. Basics of Recursion Recursion uses a method Recursion uses a method Within that method a call is made.
Data Structures Using C++ 2E1 Recursion and Backtracking: DFS Depth first search (a way to traverse a tree or graph) Backtracking can be regarded as a.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 5: Recursion as a Problem-Solving Technique Data Abstraction.
Class Opener:. Identifying Matrices Student Check:
Section 7-3 Solving 3 x 3 systems of equations. Solving 3 x 3 Systems  substitution (triangular form)  Gaussian elimination  using an augmented matrix.
Pima Elementary School 5th Grade Math Ms. Haas
Slide Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley A set of equations is called a system of equations. The solution.
3.6 Solving Systems Using Matrices You can use a matrix to represent and solve a system of equations without writing the variables. A matrix is a rectangular.
Best-first search Idea: use an evaluation function f(n) for each node –estimate of "desirability"  Expand most desirable unexpanded node Implementation:
§5 Backtracking Algorithms A sure-fire way to find the answer to a problem is to make a list of all candidate answers, examine each, and following the.
Computer Sciences Department1.  Property 1: each node can have up to two successor nodes (children)  The predecessor node of a node is called its.
Copyright ©2015 Pearson Education, Inc. All rights reserved.
© 2006 Pearson Addison-Wesley. All rights reserved 6-1 Chapter 6 Recursion as a Problem- Solving Technique.
Analysis & Design of Algorithms (CSCE 321)
Chapter 13 Backtracking Introduction The 3-coloring problem
CSCE350 Algorithms and Data Structure Lecture 21 Jianjun Hu Department of Computer Science and Engineering University of South Carolina
N-queens problem Original problem: How to place 8 queens on an 8x8 chessboard so that no two queens attack each other N-queen problem: Generalization for.
Satisfiability and SAT Solvers CS 270 Math Foundations of CS Jeremy Johnson.
Unit 3: Matrices. Matrix: A rectangular arrangement of data into rows and columns, identified by capital letters. Matrix Dimensions: Number of rows, m,
CSG3F3/ Desain dan Analisis Algoritma
Solving Systems of Equations Using Matrices
PIVOTING The pivot or pivot element is the element of a matrix, or an array, which is selected first by an algorithm (e.g. Gaussian elimination, simplex.
Intro to Computer Science II
Advanced Design and Analysis Techniques
Chapter 8: Lesson 8.1 Matrices & Systems of Equations
Warm-up a. Solve for k: 13 −5
4-2 Adding & Subtracting Matrices
Math-2 Honors Matrix Gaussian Elimination
MATRICES MATRIX OPERATIONS.
Lial/Hungerford/Holcomb/Mullins: Mathematics with Applications 11e Finite Mathematics with Applications 11e Copyright ©2015 Pearson Education, Inc. All.
Gaussian Elimination.
DETERMINANT MATH 80 - Linear Algebra.
Presentation transcript:

An Analysis of the n- Queens problem Saleem Karamali

Movement of a Queen on a Chessboard

N-Queens Problem

Place n queens on an n x n chessboard such that no two queens attack each other.

Notation/Conventions n x n solution: A valid arrangement of n queens for an n x n board. Q(n): Number of n x n solutions Since no two queens can share a column, we identify solutions by the row of each queen as we move from right to left. Start counting at zero (from the bottom left) An n x n solution is a permutation of {0, …, n-1} But not every permutation gives a solution {1,3,0,2}

Partial Table of Number of Solutions n Q(n) ,200227,514,171,973,73622,317,699,616,364,044

History

Time Complexity

Gunther’s Determinant Method Key point: The determinant of an n x n matrix consists of a sum of n! products of elements. Each product contains exactly one element from each row and column If we represent an n x n board as a generic n x n matrix, then the determinant contains every possible arrangement of queens with no row and column attacks. Eliminating the diagonal attacks gives each n x n solution But how do we identify these attacks?

Constructing the Matrix

Terms along the same diagonal have either the same variable name or the same index We take the determinant, and then eliminate these terms

Eliminating Diagonals in a 4 x 4 Matrix Each term corresponds to a placement of 4 queens at positions given by the factors of the term.

Determinant Method Time Complexity

Dynamic Programming: Finding Q(n) in Stages Place a queen on an n x n board one at a time As we add queens, we want to keep memory of which arrangements of fewer queens work. We don’t need to generate every possible permutation We will see that the time complexity is exponential < factorial

Equivalence Classes of Positions

Theorem

Proof

Algorithm

Dynamic Programming Time Complexity

Conclusion Dynamic Programming likely among the fastest techniques to solve the problem As more optimization techniques are developed, they may be applicable to n-Queens Work being done to calculate Q(27) Behavior of Q(n) still largely unknown

Acknowledgements Professor Knoerr The Oxy Math Department

References

Finding one solution Search method (Sosic & Gu) Algorithm/steps: 1. Generate a solution corresponding to a random permutation of {0, …, n-1} 2. Check every column If the queen in that column is attacked, check whether swapping it with another queen will decrease the number of total attacks. If so, make the swap If not, continue to the next column 3. If swaps were made, go to step 2. If no swaps were made and there are no total attacks, end the algorithm If no swaps were made but there still are attacks, go to step 1

Example Consider the initial position {2,1,0,3,4} Total number of attacks: 4 Column 0 Swap with column 1: 2 attacks

Position: {1,2,0,3,4} Total number of attacks: 2 Swap column 0 and 2: 2 attacks Swap column 0 and 3: 2 attacks Swap column 0 and 4: 0 attacks

Time complexity of the Search Method