/
N Queens Problem by N Queens Problem by

N Queens Problem by - PowerPoint Presentation

marina-yarberry
marina-yarberry . @marina-yarberry
Follow
342 views
Uploaded On 2019-11-21

N Queens Problem by - PPT Presentation

N Queens Problem by Max Groover Chris Wehunt Forest Gates Introduction The N Queens problem is finding the placement of N queens on an NN chessboard so that no two queens attack each other ID: 766551

queen queens algorithm column queens queen column algorithm problem hill climbing row solution backtracking values find algorithms time heuristic

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "N Queens Problem by" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

N Queens Problem by Max Groover, Chris Wehunt , Forest Gates

Introduction The N - Queens problem is finding the placement of N queens on an N×N chessboard so that no two queens attack each other. Basically, we have to ensure 4 things: 1. No two queens share a column. 2. No two queens share a row. 3. No two queens share a top-right to bottom-left diagonal. 4. No two queens share a top-left to bottom-right diagonal.

The eight queens problem was first introduced in the Berliner Schachzeitung by German chess composer Max Bezzel in 1841First complete set of solutions published in 1850 by Franz Nauck Max Bezzel http://www.math.armstrong.edu/faculty/brown/InitialNQueens.htm Context

E.W. Dijkstra, a pioneer in the field of computer science, used the eight queens problem to demonstrate the idea of structured programming with an implementation of a backtracking algorithm in 1971 Context (cont.)

Abstract Use three different algorithms and analyze their efficiency at finding a solution to the N-queens problem at different values of N. The size of N starts at 4, as there is no valid solutions at N = 2, 3. Each algorithm is run and timed at N to determine their efficiency in finding a singular valid solution. If an algorithm takes an untenable amount of time to find a solution at a certain value of N, then N will no longer be incremented for testing with that algorithm. Algorithms will be analyzed for both their times at finding a solution and their ability to efficiently find a valid solution at certain values of N in a reasonable amount of time.

Formal problem statement X – chessboard of N x N dimensions X rc – permutation of queen at row r and column cPlace N amount of queens on board X subject to:       

Three algorithms used: -Brute force -Backtracking -Hill climbing

Brute Force Generates a permutation of N queen placements, starting with the first queen at row one/column one The permutation is checked for validity as a solution using the four constraints (no same row, column, or diagonals) -If a solution is not found, permutations are exhausted with the queen at the first position, then the queen is moved to the next position where all possible permutations will be generated and checked This algorithm can produce up to N^N possible number of permutations. However, there is a way to greatly reduce the amount of permutations needed to exhaust all possible combinations of queen placements…

Brute Force (cont.) Only one queen can be in each row or column, and every row or column must have at least one queen. Knowing this and applying it allows us to greatly reduce the maximum number of permutations generated. 1) Assign one queen to each row 2) Generate all possible permutations with queen at the first row and column, with the other queens being moved left and right on their prospective rows 3) Move the queen to the right one column and repeat until the first queen reaches the nth columnThis greatly reduces the time to find a solution, as well as allows the algorithm to handle larger values of N in reasonable amounts of time.

Backtracking A recursive approach to solving the N Queens problem: 1) Places queen in a safe spot in column 0. Saves the now unsafe row, column and diagonals. 2) Goes to next column, tries to find safe spot without collision with already places Queens. a) If spot exists, place (save unsafe row, column, and diagonals) and move to next column. b) If spot doesn’t exist, backtrack to previous column and find new spot. - If new spot doesn’t exist for this queen, backtrack again to the previous and so on.3) Continues until placed Queens = N and no conflicts occur.Worst case time complexity is O(n!)

Backtracking (cont.)

Backtracking (cont.) One line of code sped up the algorithm significantly: - Instead of starting by attempting to place a queen starting in the first two rows each time, we skip these two and only come back to them if no other row works. This algorithm is quick with lower values of n, but rapidly becomes slow with higher values. Times between values can also greatly differ because of the randomness involved. Some Ns will lead to only a couple early backtracking sequences, and others will make it to column N and have to backtrack all the way to column 0.

Hill climbing Hill Climbing = generate and test + heuristics t = neighbor with a better heuristic score 1) Pick initial state s 2) Pick t in neighbors(s) with the largest f(t) 3) If f(t) <= f(s), then STOP and return s 4) If s = t, then go back to step TWO.This algorithm is very fast up until the mid-20s. However, once you get to N = 30 it starts to slow down significantly. This algorithm uses a heuristic which helps you look for an answer but the results are subject to chance. The heuristic tells you only how to look and not what to find. This algorithm may fail to reach global maxima.

Hill climbing (cont.) The Hill Climbing algorithm is a minimum-conflicts algorithm. Hill-climbing searches work by starting off with an initial guess of a solution, then iteratively making local changes to it until either the solution is found or the heuristic gets stuck in a local maximum. The heuristic method provides a score for each problem based on the number of queen collisions. If the score is ten that means there are ten collisions to be fixed before the problem is solved. If the heuristic score is zero the problem is solved.  There are many ways to try to avoid getting stuck in local maxima, such as running many searches in parallel, or probabilistically choosing the successor state, etc. A problem with the Hill Climbing technique is some arrangements of queens preplaced on the board cannot be improved any further. This is called a local minima. The board would be stuck in a local minima if only two of the queens conflict and the rest were fine. To fix this type of situation, one of the conflicting queens is moved to a random row to create conflicts and start the process over again. In many cases, hill-climbing algorithms will rapidly converge on the correct answer. However, none of these approaches are guaranteed to find the optimal solution.

Interpretation (graph) Interpretation of results Brute force inefficiency quickly starts to become pronounced at N = 5 and not practical at around N = 15 Backtracking appears to be the fastest up to a certain value of N, branching off from Hill climbing at around N = 10 Hill climbing, despite running slower than backtracking up to N = 30, is able to handle larger values of N in reasonable amounts of time

Conclusion The best algorithm to use depends on the user’s needs. If you need faster times but aren’t worried about its capabilities as N reaches a certain threshold, use backtracking. If you wish to find solutions at larger values of N, use hill climbing. This applies only to these three algorithms. There is many different algorithms and variations that can be used to solve the N-queens problem such as branch/bound and genetic. Future work would entail evaluating these other algorithms to determine their efficiencies compared to the ones we have already looked into, and to see if they can handle larger values of N. The algorithms we have used could also possibly be refined to squeeze out even greater efficiency.

Questions What type of problem is N-Queens? Constraint satisfaction problem What algorithm is fastest up to N=30?Backtracking What algorithm can handle the largest values of N?Hill climbingAt around which value of N does brute force start to become untenable?N=15At around which value of N does the difference between backtracking and hill climbing become pronounced?N=10