SlideShare une entreprise Scribd logo
1  sur  11
8-Queens Problem
Overview
• Objective of the Problem
• Constraints
• Solutions
• Conclusion
Objective of the Problem
• 8-Queens Problem
• A Queen can move on 8*8 board in horizontally,Verically and
diagonally.
• We have to ensure no two Queens should attack each other
Constraints
• Each row should contain single Queen
• Each column should contain single Queen
• If R-C=0 , then the Queens are under attack diagonally
• Based on the solutions, we can extract various constraints for
diagonal move of the Queen
• Row + Col = constant
• Row-Col + n-1 = constant
• Let say n = 5, then we have a total of 2n-1 left and right diagonals
Let say we placed a queen at (2,0)
(2,0) have leftDiagonal value = 2. Now we can not place another queen at (1,1) and (0,2) because both of
these have same leftDiagonal value as for (2,0). Similar thing can be noticed for right diagonal as well.
Concept to solve 8-Queens
• Decomposition
-Divide-and-Conquer
• Pattern Matching
- 4 Queens Solution
• Abstraction
- N Queens
4-Queen Solutions
• Based on Positions there are 2 Solutions
8-Queens Problem
• 3 Possible solutions
(1,5,2,6,3,7,4,8) (6,4,7,1,8,2,5,3)
(3,6,4,2,8,5,7,1)
Backtracking Solution - Algorithm
1) Start in the leftmost column
2) If all queens are placed
return true
3) Try all rows in the current column.
Do following for every tried row.
a) If the queen can be placed safely in this row
then mark this [row, column] as part of the
solution and recursively check if placing
queen here leads to a solution.
b) If placing the queen in [row, column] leads to
a solution then return true.
c) If placing queen doesn't lead to a solution then
unmark this [row, column] (Backtrack) and go to
step (a) to try other rows.
4) If all rows have been tried and nothing worked,
return false to trigger backtracking.
Conclusion
• We explain to students with use of Backtracking on 4-Queens
• For optimal Solution (for placement training), Dynamic Programming
mechanism can be utilized.
Suggestions?
Queries?

Contenu connexe

Tendances

Tendances (20)

Merge sort
Merge sortMerge sort
Merge sort
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplication
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
Branch and bound technique
Branch and bound techniqueBranch and bound technique
Branch and bound technique
 
Backtracking-N Queens Problem-Graph Coloring-Hamiltonian cycle
Backtracking-N Queens Problem-Graph Coloring-Hamiltonian cycleBacktracking-N Queens Problem-Graph Coloring-Hamiltonian cycle
Backtracking-N Queens Problem-Graph Coloring-Hamiltonian cycle
 
Backtracking Algorithm.ppt
Backtracking Algorithm.pptBacktracking Algorithm.ppt
Backtracking Algorithm.ppt
 
All pair shortest path
All pair shortest pathAll pair shortest path
All pair shortest path
 
Backtracking
BacktrackingBacktracking
Backtracking
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
Splay tree
Splay treeSplay tree
Splay tree
 
N queen puzzle
N queen puzzleN queen puzzle
N queen puzzle
 
Backtracking
BacktrackingBacktracking
Backtracking
 
Binary Search
Binary SearchBinary Search
Binary Search
 
Prims and kruskal algorithms
Prims and kruskal algorithmsPrims and kruskal algorithms
Prims and kruskal algorithms
 
Knight's Tour
Knight's TourKnight's Tour
Knight's Tour
 
Optimal binary search tree
Optimal binary search treeOptimal binary search tree
Optimal binary search tree
 
Graph coloring problem
Graph coloring problemGraph coloring problem
Graph coloring problem
 
Red Black Tree Insertion & Deletion
Red Black Tree Insertion & DeletionRed Black Tree Insertion & Deletion
Red Black Tree Insertion & Deletion
 
ppt-knight'stour
ppt-knight'stourppt-knight'stour
ppt-knight'stour
 
backtracking algorithms of ada
backtracking algorithms of adabacktracking algorithms of ada
backtracking algorithms of ada
 

Similaire à 8-Queens Problem.pptx

Algebra 2 01-Systems of Linear Equations and Matrices (RW 2022).pptx
Algebra 2 01-Systems of Linear Equations and Matrices (RW 2022).pptxAlgebra 2 01-Systems of Linear Equations and Matrices (RW 2022).pptx
Algebra 2 01-Systems of Linear Equations and Matrices (RW 2022).pptx
BivekRegmi1
 
11 alternative search
11 alternative search11 alternative search
11 alternative search
Tianlu Wang
 
February 17, 2015
February 17, 2015February 17, 2015
February 17, 2015
khyps13
 

Similaire à 8-Queens Problem.pptx (20)

module5_backtrackingnbranchnbound_2022.pdf
module5_backtrackingnbranchnbound_2022.pdfmodule5_backtrackingnbranchnbound_2022.pdf
module5_backtrackingnbranchnbound_2022.pdf
 
Backtracking Algorithm.pptx
Backtracking Algorithm.pptxBacktracking Algorithm.pptx
Backtracking Algorithm.pptx
 
Backtracking Basics.pptx
Backtracking Basics.pptxBacktracking Basics.pptx
Backtracking Basics.pptx
 
8 QUEENS PROBLEM.pptx
8 QUEENS PROBLEM.pptx8 QUEENS PROBLEM.pptx
8 QUEENS PROBLEM.pptx
 
The N-Queens problemdskksnjfnskjdfnsjnddjsdnjs
The N-Queens problemdskksnjfnskjdfnsjnddjsdnjsThe N-Queens problemdskksnjfnskjdfnsjnddjsdnjs
The N-Queens problemdskksnjfnskjdfnsjnddjsdnjs
 
Branch and bound
Branch and boundBranch and bound
Branch and bound
 
Algebra 2 01-Systems of Linear Equations and Matrices (RW 2022).pptx
Algebra 2 01-Systems of Linear Equations and Matrices (RW 2022).pptxAlgebra 2 01-Systems of Linear Equations and Matrices (RW 2022).pptx
Algebra 2 01-Systems of Linear Equations and Matrices (RW 2022).pptx
 
AIMA_ch3_L2-complement.ppt kjekfkjekjfkjefkjefkjek
AIMA_ch3_L2-complement.ppt kjekfkjekjfkjefkjefkjekAIMA_ch3_L2-complement.ppt kjekfkjekjfkjefkjefkjek
AIMA_ch3_L2-complement.ppt kjekfkjekjfkjefkjefkjek
 
backtracking 8 Queen.pptx
backtracking 8 Queen.pptxbacktracking 8 Queen.pptx
backtracking 8 Queen.pptx
 
8 queens problem using ga
8 queens problem using ga8 queens problem using ga
8 queens problem using ga
 
11 alternative search
11 alternative search11 alternative search
11 alternative search
 
N Queens problem
N Queens problemN Queens problem
N Queens problem
 
N queens problem
N queens problemN queens problem
N queens problem
 
matrices_and_loops.pptx
matrices_and_loops.pptxmatrices_and_loops.pptx
matrices_and_loops.pptx
 
linear equation and gaussian elimination
linear equation and gaussian eliminationlinear equation and gaussian elimination
linear equation and gaussian elimination
 
Ht3313461349
Ht3313461349Ht3313461349
Ht3313461349
 
February 17, 2015
February 17, 2015February 17, 2015
February 17, 2015
 
Solving radical equations
Solving radical equationsSolving radical equations
Solving radical equations
 
Lec2 state space
Lec2 state spaceLec2 state space
Lec2 state space
 
Linear Algebra and Matlab tutorial
Linear Algebra and Matlab tutorialLinear Algebra and Matlab tutorial
Linear Algebra and Matlab tutorial
 

Dernier

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ankushspencer015
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
MsecMca
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Christo Ananth
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Christo Ananth
 

Dernier (20)

Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 

8-Queens Problem.pptx

  • 2. Overview • Objective of the Problem • Constraints • Solutions • Conclusion
  • 3. Objective of the Problem • 8-Queens Problem • A Queen can move on 8*8 board in horizontally,Verically and diagonally. • We have to ensure no two Queens should attack each other
  • 4. Constraints • Each row should contain single Queen • Each column should contain single Queen • If R-C=0 , then the Queens are under attack diagonally • Based on the solutions, we can extract various constraints for diagonal move of the Queen • Row + Col = constant • Row-Col + n-1 = constant
  • 5. • Let say n = 5, then we have a total of 2n-1 left and right diagonals Let say we placed a queen at (2,0) (2,0) have leftDiagonal value = 2. Now we can not place another queen at (1,1) and (0,2) because both of these have same leftDiagonal value as for (2,0). Similar thing can be noticed for right diagonal as well.
  • 6. Concept to solve 8-Queens • Decomposition -Divide-and-Conquer • Pattern Matching - 4 Queens Solution • Abstraction - N Queens
  • 7. 4-Queen Solutions • Based on Positions there are 2 Solutions
  • 8. 8-Queens Problem • 3 Possible solutions (1,5,2,6,3,7,4,8) (6,4,7,1,8,2,5,3) (3,6,4,2,8,5,7,1)
  • 9. Backtracking Solution - Algorithm 1) Start in the leftmost column 2) If all queens are placed return true 3) Try all rows in the current column. Do following for every tried row. a) If the queen can be placed safely in this row then mark this [row, column] as part of the solution and recursively check if placing queen here leads to a solution. b) If placing the queen in [row, column] leads to a solution then return true. c) If placing queen doesn't lead to a solution then unmark this [row, column] (Backtrack) and go to step (a) to try other rows. 4) If all rows have been tried and nothing worked, return false to trigger backtracking.
  • 10. Conclusion • We explain to students with use of Backtracking on 4-Queens • For optimal Solution (for placement training), Dynamic Programming mechanism can be utilized.