N queen problem

RidhimaChowdhury 9,904 views 12 slides Apr 10, 2018
Slide 1
Slide 1 of 12
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12

About This Presentation

This is the presentation on N queen problem


Slide Content

WELCOME TO THE PRESENTATION

TOPIC : N-QUEEN problem using backtracking

THE QUEEN OF A CHESSBOARD

PROBLEM INVENTOR : MAX BEZZEL The puzzle was originally proposed in 1848 by the chess player Max Bezzel and over the years many mathematicians, including Gauss, have worked on this puzzle and its generalized n-queens problem.

SOLUTION INVENTOR : FRANZ NAUCK The first solution for 8 queens were provided by Franz Nauck in 1850 . Nauck also extended the puzzle to n-queens problem (on an n by n – a chessboard of arbitrary size ).

The N-Queen Problem: The N-Queens problem originates from a question relating to Chess , The n-Queens problem. Chess is played on an n × n grid, with each piece taking up one cell. A queen is a piece in chess that, in any given move, can move any distance vertically, horizontally, or diagonally. However, the queen cannot move more than one direction per turn. It can only move one direction per turn.

EXAMPLE WITH EXPLANATION USING BACKTRACKING (MATRIX FORM) : Q X X X Q X X X X 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 X X There exists no solution if we place the 1 st queen in the 1 st position Q

1 2 3 4 1 2 3 4 Q 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 If we place the 1 st queen in the 2 nd position then the solution is 2 4 1 3 By using the same process for 4 queen we get another solution that is 3 1 4 2 Q Q Q Q Q Q Q Q Q X X X X X X X X X X X X X X X X X X X X

EXAMPLE WITH EXPLANATION USING BACKTRACKING (STATE SPACE TREE) : 1 1 2 4 Q 1 3 2 4 3 1 4 2 2 3 Q 2 X X X X X X 3 4 1 TO BE CONTINUED

3 1 2 Q 2 3 4 1 3 2 3 2 3 2 Q 3 3 Q 4 X X X X X X X X X X 4 1 1 3 4 2 4 2 The solution for 4 queen problem are : 2 4 1 3 3 1 4 2 &

 T(N) = O(N 2 ) + N*T(N-1) If we add all this up and define the run time as T(N). Then T(N) = O(N 2 ) + N*T(N-1). If you draw a recursion tree using this recurrence, the final term will be something like n 3 + n!O (1). By the definition of Big O, this can be reduced to O(n!) running time. 1 1 2 4 3 2 4 3 1 4 2 2 3 3 4 1 3 4 1 3 2 3 2 3 2 3 1 3 4 2 2 Q 3 Q 2 Q 1 Q 4 X X X X X X X X X X X X X X Q Time complexity of N_Queen : X 2 X

THANK YOU ANY QUESTIONS ??
Tags